pointer to class as arguement in a function
-
What is the proper way to define a function that contains a class pointer as an arguement (because I am having very bad compile errors all over the place) Is this the correct way: void MyFunction(char*, char*, CClass*); or void MyFunction(char*, char*, class CClass*); The former gives me a syntax error eg. identifyer CClass The later gives me compile error when writing a differnt function such as void MyFunction2(char*, char*, CClass::CSubClass*); void MyFunction2(char*, char*, class CClass::cSubClass*); Every time I change one way of doing it, I screw the code up somewhere else. Can I get some help on this one? Thanks
-
What is the proper way to define a function that contains a class pointer as an arguement (because I am having very bad compile errors all over the place) Is this the correct way: void MyFunction(char*, char*, CClass*); or void MyFunction(char*, char*, class CClass*); The former gives me a syntax error eg. identifyer CClass The later gives me compile error when writing a differnt function such as void MyFunction2(char*, char*, CClass::CSubClass*); void MyFunction2(char*, char*, class CClass::cSubClass*); Every time I change one way of doing it, I screw the code up somewhere else. Can I get some help on this one? Thanks
void MyFunction(char* c1, char* c2, CClass* theObject);
void MyFunction2(char* c1, char* c2, CSubClass* theObject);Note that if CSubClass extends CClass then you can pass a CSubClass* as the argument to
CClass*
"No matter where you go, there your are." - Buckaroo Banzai
-pete
-
What is the proper way to define a function that contains a class pointer as an arguement (because I am having very bad compile errors all over the place) Is this the correct way: void MyFunction(char*, char*, CClass*); or void MyFunction(char*, char*, class CClass*); The former gives me a syntax error eg. identifyer CClass The later gives me compile error when writing a differnt function such as void MyFunction2(char*, char*, CClass::CSubClass*); void MyFunction2(char*, char*, class CClass::cSubClass*); Every time I change one way of doing it, I screw the code up somewhere else. Can I get some help on this one? Thanks
-
Ok, thanks for the reply...I must omit "class" before the class. NOw on to the compile errors, I don't understand them because I am including the header file that contains the class definition. Isn't this enough?
-
Ok, thanks for the reply...I must omit "class" before the class. NOw on to the compile errors, I don't understand them because I am including the header file that contains the class definition. Isn't this enough?
-
Ok, thanks for the reply...I must omit "class" before the class. NOw on to the compile errors, I don't understand them because I am including the header file that contains the class definition. Isn't this enough?
that is right. Do not use the word class before variable declarations, only before the class declaration. class B1 int i; B1 b; // B1 is a type like int is a type Your compile errors should be discernable. Take a break and then look at them again. To make it more fun, Java has a "Class" type and this can be used in declaring a variable such as Class somvarthatwillrefertoaclasslater; // :-)
-
that is right. Do not use the word class before variable declarations, only before the class declaration. class B1 int i; B1 b; // B1 is a type like int is a type Your compile errors should be discernable. Take a break and then look at them again. To make it more fun, Java has a "Class" type and this can be used in declaring a variable such as Class somvarthatwillrefertoaclasslater; // :-)
Anonymous wrote: Java has a "Class" type and this can be used in declaring a variable such as Class somvarthatwillrefertoaclasslater; are you sure it is not a declaration before a definition instead of a type ?! (in C++, it is like that...)
TOXCCT >>> GEII power
-
Anonymous wrote: Java has a "Class" type and this can be used in declaring a variable such as Class somvarthatwillrefertoaclasslater; are you sure it is not a declaration before a definition instead of a type ?! (in C++, it is like that...)
TOXCCT >>> GEII power
Thanks for the replies guys. The error line reads: error C2061: syntax error : identifier 'cDataFile' Where cDataFile is a class defined in another header file which I have included in this header file The function definition (part of another class) void Save(cDataFile*); So I'm stumped :confused:
-
Thanks for the replies guys. The error line reads: error C2061: syntax error : identifier 'cDataFile' Where cDataFile is a class defined in another header file which I have included in this header file The function definition (part of another class) void Save(cDataFile*); So I'm stumped :confused:
First, make sure that cDataFile is spelled correctly (including capitalization, I am suspicious of your lowercase 'c'). Second, when your function uses a pointer to a class, as you did, you only need to forward include the class in the header file. Then put the #include in the .cpp file (not the .h file) i.e. class cDataFile; class CYourClass { void Save(cDataFile*); };
-
First, make sure that cDataFile is spelled correctly (including capitalization, I am suspicious of your lowercase 'c'). Second, when your function uses a pointer to a class, as you did, you only need to forward include the class in the header file. Then put the #include in the .cpp file (not the .h file) i.e. class cDataFile; class CYourClass { void Save(cDataFile*); };
Thanks for the continued help...I seem to be a bit confused though...the spelling is correct (I always use a lowercase c for classes) Here is my file structure/layout: Header1.h --------- class cDataFile { ... }; ---------- Header2.h --------- #include "Header1.h" class cSomeClass { public: void SaveSomeFile(cDataFile*); <---- This is were I get the error }; ---------- Could you please explain what you said before in this semi-diagramatical way? Thanks.