473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Typedefs inside classes

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
2 1226
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: emerth | last post by:
Suppose I have these 4 typedefs, where each of the 2nd parameter in each is a simple class that just contains a different number of strings: typedef map < char*, cctrlrec_data, ltstr >...
5
by: Simon Elliott | last post by:
For some time I've been using typedefs for STL containers for reasons outlined in: http://www.gotw.ca/gotw/046.htm However a major downside to this is that you can't forward declare a typedef...
2
by: Levent | last post by:
Please consider the following Parent and Child template classes: template <class T> class Parent { public: typedef T type; typedef T& ref; /* pack of typedefs */ };
6
by: Erica | last post by:
Hi, I am currently working on a Pascal-to-C translation, and I am getting an error that I can't seem to debug. I have a globals.h file, and here is a snippet from it: -- typedef char...
1
by: Oleg Subachev | last post by:
How to translate the following C++ typedefs into C# ? typedef struct { BYTE *data; size_t length; } VizBlob; typedef struct VizUserInfoActions { HANDLE (IMPORTED *createFullInfo) ( HANDLE...
5
by: eiji | last post by:
Hi folks, I hope this is not "off topic"! :-) Consider the next code: /* Declarations of types that could become platform-dependent */ #define MyChar char #define MyInt int
1
by: Michal Wróbel | last post by:
Hello, I've got few questions concerning typedefs inside class definition. Firstly, I'll give an example code: template< class T > class Function { public: typedef boost::shared_ptr<...
3
by: aiooua | last post by:
Any idea why the following code does not compile? ---- #include<iostream> #include<list> using namespace std; class Base { public: int val;
2
by: Chris Fairles | last post by:
I'm wondering if theres any rationale behind using _t vs _type in typedefs. I took a look in the standard and it doesn't say much besides things like "size_type must be size_t", "difference_type...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.