I receive a g++ error (undefined reference to 'SomeClass::SomeClass(int)' and 'SomeClass::~SomeClass') with the following:
/*
* SomeClass.h
*
*/
#ifndef SOMECLASS_H_
#define SOMECLASS_H_
class SomeClass
{
public:
SomeClass();
SomeClass(int someInt);
~SomeClass();
};
#endif /* SOME开发者_开发百科CLASS_H_ */
/*
* SomeClass.cpp
*
*/
#include "SomeClass.h"
SomeClass::SomeClass()
{
}
SomeClass::SomeClass(int someInt)
{
}
SomeClass::~SomeClass()
{
}
/*
* main.cpp
*
*/
#include "SomeClass.h"
int main()
{
SomeClass::SomeClass someObject(1);
return 0;
}
SomeClass::SomeClass someObject(1);
First of all that's not valid, because SomeClass::SomeClass
names the constructor, and not the class type. Just say SomeClass
. Then you probably forget to link against SomeClass.cpp
's object file. Be sure to include it in the compiler command line when you compile the executable, or add it to the project config by whatever IDE you are using.
SomeClass
isn't in a namespace.
SomeClass someObject(1);
精彩评论