tags:

views:

74

answers:

2

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;
}
+6  A: 
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.

Johannes Schaub - litb
+1  A: 

SomeClass isn't in a namespace.

    SomeClass someObject(1); 
Mark Ransom
Classes don't have an implicit namespace?
@drenami - actually, everything does and SomeClass IS in a namespace - the global namespace. What Mark meant to say I think is that SomeClass is not in a namespace named SomeClass nor is SomeClass a namespace at all.
Noah Roberts