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 /* SOMECLASS_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;
}
First of all that’s not valid, because
SomeClass::SomeClassnames the constructor, and not the class type. Just saySomeClass. Then you probably forget to link againstSomeClass.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.