calling member within a class within a class

Aug 29, 2013 at 4:53am
I tried to google this before, but I got anything but what I was looking for. Here is a stripped down version of my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class color {
public:
    float red;
    float green;
    float blue;
    float alpha;
};

class house {
public:
    color banner;
};

class tenant {
public:
    house faction;

    float render () {
        return tenant::faction::banner::red;    //here is my issue
    }
};


I get an error: 'tenant::faction' is not a class or namespace

I'm sure it's just a beginner's issue, but I'm not able to word it right in google. Thanks in advance.
Aug 29, 2013 at 4:58am
There are multiple issues here. You don't seem to understand the difference between instance members, static members, and enums. What is render supposed to return?
Aug 29, 2013 at 1:35pm
are you trying to achieve something like this:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
enum color {

	red,
	green,
	blue,
	alpha,
};

class house {
public:
	color banner;
};

class tenant {
public:
	house faction;

	void render () 
	{
		faction.banner = red;
	}
};

?
Aug 29, 2013 at 1:46pm
I think what he really want to achieve is:
1
2
3
    float render () {
        return faction.banner.red;
    }
Aug 29, 2013 at 1:51pm
oh right.
Either way, OP, read up on all topics L B mentioned.
Aug 29, 2013 at 2:35pm
render () is actually supposed to render the tenant, but it took up lots of code.

@L B: they are all supposed to be instance members, render isn't supposed to
return anything, hence the void return type

@mutexe: I did, and I now feel very enlightened.

@coder777: thanks, this was what I was looking for. Guess I should learn more on classes.
Aug 29, 2013 at 4:50pm
Twist177 wrote:
render isn't supposed to
return anything, hence the void return type
Read your post? You marked it as returning a float and you even used the return statement.
Topic archived. No new replies allowed.