<list of =“”functions =“”> </list>的多重定义

时间:2014-02-11 01:27:23

标签: c++

我确信答案是直截了当地盯着我,但由于这个原因我无法取得任何进展......首先是一些代码:

对象/ testObject.h:

#include <irrlicht.h>
#include "../maths.h"

using namespace irr;

#ifndef testObject_H
#define testObject_H

class testObject : public scene::SAnimatedMesh
{
    public:
        testObject(IrrlichtDevice* device);
        virtual ~testObject();
    protected:
        const char* meshInfoLocation;
        int totAnims;
    private:

};

#endif

对象/ testObject.cpp:

#include "testObject.h"

testObject::testObject(IrrlichtDevice* device) : scene::SAnimatedMesh()
{
    io::IrrXMLReader* modelInformation = io::createIrrXMLReader(meshInfoLocation);

    while(modelInformation->read())
    {
        if(modelInformation->getNodeName() == "totAnims") totAnims = stringToInt(modelInformation->getAttributeValue("totAnims"));
    }
}

testObject::~testObject() { } //Incomplete, but should still compile...

编译此代码时,出现以下错误:

/home/david/workspace/spaceSim/objects/testObject.cpp||In constructor ‘testObject::testObject(irr::IrrlichtDevice*)’:|
/home/david/workspace/spaceSim/objects/testObject.cpp|20|warning: comparison with string literal results in unspecified behaviour [-Waddress]|
/home/david/workspace/spaceSim/main.cpp||In function ‘int main(int, char**)’:|
/home/david/workspace/spaceSim/main.cpp|24|warning: ‘virtual bool irr::io::IFileSystem::addZipFileArchive(const c8*, bool, bool)’ is deprecated (declared at /home/david/irrlicht-1.8.1/include/IFileSystem.h:228) [-Wdeprecated-declarations]|
/home/david/workspace/spaceSim/objects/testObject.cpp||In constructor ‘testObject::testObject(irr::IrrlichtDevice*)’:|
/home/david/workspace/spaceSim/objects/testObject.cpp|20|warning: comparison with string literal results in unspecified behaviour [-Waddress]|
obj/Debug/objects/testObject.o||In function `testObject::testObject(irr::IrrlichtDevice*)':|
/home/david/workspace/spaceSim/objects/testObject.cpp|3|multiple definition of `testObject::testObject(irr::IrrlichtDevice*)'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|3|first defined here|
obj/Debug/objects/testObject.o||In function `testObject::testObject(irr::IrrlichtDevice*)':|
/home/david/workspace/spaceSim/objects/testObject.cpp|3|multiple definition of `testObject::testObject(irr::IrrlichtDevice*)'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|3|first defined here|
obj/Debug/objects/testObject.o||In function `testObject::~testObject()':|
/home/david/workspace/spaceSim/objects/testObject.cpp|27|multiple definition of `testObject::~testObject()'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|27|first defined here|
obj/Debug/objects/testObject.o||In function `testObject::~testObject()':|
/home/david/workspace/spaceSim/objects/testObject.cpp|27|multiple definition of `testObject::~testObject()'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|27|first defined here|
obj/Debug/objects/testObject.o||In function `virtual thunk to testObject::~testObject()':|
/home/david/workspace/spaceSim/objects/testObject.cpp|29|multiple definition of `virtual thunk to testObject::~testObject()'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|29|first defined here|
obj/Debug/objects/testObject.o||In function `testObject::~testObject()':|
/home/david/workspace/spaceSim/objects/testObject.cpp|27|multiple definition of `testObject::~testObject()'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|27|first defined here|
obj/Debug/objects/testObject.o||In function `virtual thunk to testObject::~testObject()':|
/home/david/workspace/spaceSim/objects/testObject.cpp|29|multiple definition of `virtual thunk to testObject::~testObject()'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|29|first defined here|
||=== Build finished: 14 errors, 3 warnings ===|

我在解决时尝试了以下方法:

  • 合并标头和cpp文件。
  • 清空所有方法体并删除#includes,以便重要的是类结构。
  • 谷歌搜索(没有任何运气......)

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我使用mingw32(www.mingw.org)中的gcc4.8.1编译代码(将它们放入文件中,并替换丢失的类型)。编译似乎没问题。我想问题可能是

#include <irrlicht.h>
#include "../maths.h"

代码:

//#include <irrlicht.h>
//#include "../maths.h"

//using namespace irr;

#ifndef testObject_H
#define testObject_H
#include <tuple>
namespace scene {
  typedef  std::tuple<int,int> SAnimatedMesh;
};
typedef int IrrlichtDevice;

class testObject : public scene::SAnimatedMesh
{
    public:
        testObject(IrrlichtDevice* device);
        virtual ~testObject();
    protected:
        const char* meshInfoLocation;
        int totAnims;
    private:

};

#endif

//#include "testObject.h"

testObject::testObject(IrrlichtDevice* device) : scene::SAnimatedMesh()
{
  /*
    io::IrrXMLReader* modelInformation = io::createIrrXMLReader(meshInfoLocation);

    while(modelInformation->read())
    {
        if(modelInformation->getNodeName() == "totAnims") totAnims = stringToInt(modelInformation->getAttributeValue("totAnims"));
    }
  */
}

testObject::~testObject() { } //Incomplete, but should still compile...

int main() {}