<函数列表>的多重定义
Multiple definition of <List of functions>
我敢肯定答案正直勾勾地盯着我,但我因此无法取得任何进展......首先是一些代码:
objects/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
objects/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 以便所有重要的是类结构。
- 谷歌搜索(没有任何运气...
谢谢你的帮助!
我使用 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() {}
相关文章:
- 标准是否使用多余的大括号(例如 T{{{10}}})定义列表初始化?
- 跟随整数索引列表的自定义类迭代器
- 使用模板类的自定义列表类型中的内存泄漏
- 列表参数的类型定义
- 如何使用Q_PROPERTY公开自定义对象列表
- Qt - QVector 和模型视图 - 从列表视图获取自定义类的最佳方法是什么?
- 打印/修改类对象的特定成员变量,其类定义列表 (STL) 包含的元素类型
- 如何在C++中循环浏览自定义列表
- 使用可变参数模板在 c++ 中定义列表类
- QML自定义列表数据类型
- 如何对此自定义C 列表类实现删除函数
- 如何将重新绑定与自定义分配器和自定义列表一起使用
- 遍历自定义列表
- 自定义列表实现迭代器无法访问最后一个元素 (c++)
- MFC C++:如何自定义列表
- 自定义列表类的初始值设定项列表构造函数
- C++和typetraits:定义可能定义列表的最简单方法
- 实现push_back和pop_front的C++自定义列表
- c++自定义列表模板
- 在c++中如何像Java那样定义列表的列表或堆栈的列表