By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

Typedefs inside classes

P: n/a
Hi,

Reading X. Meng's post on embedded classes I came to
think of a similar problem I found myself having.

void GamestateToString(class GameApp::TGamestate);

class GameApp {
typedef enum {
STATE_1,
STATE_2
} TGamestate;

[...]
};

This won't compile since I'm not allowed to
define GamestateToString()'s arguments like
that. Why?

In fact, it seems like I can't access GameApp::TGamestate at all,
not even for simple variables, ie.

GameApp::TGamestate state;
state = STATE_1;

-- Pelle
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Pelle Beckman" <he******@chello.se> wrote in message
news:20s6e.681$184.180@amstwist00
Hi,

Reading X. Meng's post on embedded classes I came to
think of a similar problem I found myself having.

void GamestateToString(class GameApp::TGamestate);

class GameApp {
typedef enum {
STATE_1,
STATE_2
} TGamestate;

[...]
};
This typedef is unnecessary --- a hangover from C. You can make it:

class GameApp {
enum TGamestate{
STATE_1,
STATE_2
};

[...]
};
This won't compile since I'm not allowed to
define GamestateToString()'s arguments like
that. Why?


You are doing three things wrong:

1. You should be declaring GamestateToString after, not before, the GameApp
class.

2. Anything in a class is private by default. You need to specify public:
before TGamestate.

3. You are using the wrong syntax for function parameters. Rather than

void GamestateToString(class GameApp::TGamestate);

try

void GamestateToString(GameApp::TGamestate state);
--
John Carson

Jul 23 '05 #2

P: n/a
Pelle Beckman wrote:
Hi,

Reading X. Meng's post on embedded classes I came to
think of a similar problem I found myself having.

void GamestateToString(class GameApp::TGamestate);

class GameApp {
typedef enum {
STATE_1,
STATE_2
} TGamestate;

[...]
};

This won't compile since I'm not allowed to
define GamestateToString()'s arguments like
that. Why?
Because TGamestate is private in class GameApp, and because the class is
defined after the declaration of GamesateToString, so the compiler doesn't
know anything about GameApp::TGamestate yet.
In fact, it seems like I can't access GameApp::TGamestate at all,
not even for simple variables, ie.

GameApp::TGamestate state;
state = STATE_1;


What does "can't access" mean? What happens if you try?

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.