开发者

What is the error in the following g++ class construction?

开发者 https://www.devze.com 2023-01-07 05:38 出处:网络
I receive a g++ error (undefined reference to \'SomeClass::SomeClass(int)\' and \'SomeClass::~SomeClass\') with the following:

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); 
0

精彩评论

暂无评论...
验证码 换一张
取 消