Problem declaring data type
-
Hi, I'm working with a C++ project and have created a new .h file that contains typedef of new types. How do I use the new types in another class?
#ifndef COMMONSETTINGS_H_
#define COMMONSETTINGS_H_typedef enum { XX = 0, YY, ZZ } ProductType;
#endif /* COMMONSETTINGS_H_ */
And the class that uses the type ProductType
class TestClass
{
public:
//! Constructor
TestClass();//! Desctructor virtual ~TestClass();
private:
ProductType product;
};How do I do to use ProductTyp in TestClass? Now I get compile erro since TestClass can not find ProductType. What is the best way to solve this? I want to declare new types in a file and use the types in several other classes. /Olof
-
Hi, I'm working with a C++ project and have created a new .h file that contains typedef of new types. How do I use the new types in another class?
#ifndef COMMONSETTINGS_H_
#define COMMONSETTINGS_H_typedef enum { XX = 0, YY, ZZ } ProductType;
#endif /* COMMONSETTINGS_H_ */
And the class that uses the type ProductType
class TestClass
{
public:
//! Constructor
TestClass();//! Desctructor virtual ~TestClass();
private:
ProductType product;
};How do I do to use ProductTyp in TestClass? Now I get compile erro since TestClass can not find ProductType. What is the best way to solve this? I want to declare new types in a file and use the types in several other classes. /Olof
Stupid question, but did you
#include
the header file in your compilation unit?Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Hi, I'm working with a C++ project and have created a new .h file that contains typedef of new types. How do I use the new types in another class?
#ifndef COMMONSETTINGS_H_
#define COMMONSETTINGS_H_typedef enum { XX = 0, YY, ZZ } ProductType;
#endif /* COMMONSETTINGS_H_ */
And the class that uses the type ProductType
class TestClass
{
public:
//! Constructor
TestClass();//! Desctructor virtual ~TestClass();
private:
ProductType product;
};How do I do to use ProductTyp in TestClass? Now I get compile erro since TestClass can not find ProductType. What is the best way to solve this? I want to declare new types in a file and use the types in several other classes. /Olof
Enumerations did not need the
typedef
keyword. Useenum ProductType
{
XX,
YY,
ZZ
};You should also think about moving your common settings into those classes they are belonging to (e.g. the class that acts according to the
ProductType
enumeration). This is better C++ style and makes your code modules better portable to other projects. To use such class specific enumerations from other classes, prefix them with the class name (e.g.MyClass::ProductType
). Joe -
Hi, I'm working with a C++ project and have created a new .h file that contains typedef of new types. How do I use the new types in another class?
#ifndef COMMONSETTINGS_H_
#define COMMONSETTINGS_H_typedef enum { XX = 0, YY, ZZ } ProductType;
#endif /* COMMONSETTINGS_H_ */
And the class that uses the type ProductType
class TestClass
{
public:
//! Constructor
TestClass();//! Desctructor virtual ~TestClass();
private:
ProductType product;
};How do I do to use ProductTyp in TestClass? Now I get compile erro since TestClass can not find ProductType. What is the best way to solve this? I want to declare new types in a file and use the types in several other classes. /Olof
-
Stupid question, but did you
#include
the header file in your compilation unit?Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Enumerations did not need the
typedef
keyword. Useenum ProductType
{
XX,
YY,
ZZ
};You should also think about moving your common settings into those classes they are belonging to (e.g. the class that acts according to the
ProductType
enumeration). This is better C++ style and makes your code modules better portable to other projects. To use such class specific enumerations from other classes, prefix them with the class name (e.g.MyClass::ProductType
). Joe