2014-02-11 35 views
1

我敢肯定,答案是直视我的脸,但由于这个原因,我还没有能够取得任何进展......首先一些代码:<功能列表>多重定义

对象/ 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... 

当我编译THI S码,我得到以下错误:

/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以便所有重要的是类结构。
  • 谷歌搜索(没有任何运气...)

感谢您的帮助!

回答

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() {}