C++ 多重定义

C++ 多重定义,c++,C++,我的代码有一个错误,没有定义操作符。看起来您在头文件中定义了一个函数,所以它在包含它的每个源文件中都被定义。要么将其声明为inline(这允许多个定义),要么将实现移动到源文件中(因此只定义一次)编辑:或将定义移动到类定义中,这也使其成为内联的。(谢谢David。)请在定义函数的地方发布一些源代码。+1另一个选项实际上是在类定义内定义方法,其效果与在类定义外将内联添加到方法定义中相同。 int Vector3D::operator < (const Vector 3D &vecto

我的代码有一个错误,没有定义
操作符。看起来您在头文件中定义了一个函数,所以它在包含它的每个源文件中都被定义。要么将其声明为
inline
(这允许多个定义),要么将实现移动到源文件中(因此只定义一次)编辑:或将定义移动到类定义中,这也使其成为内联的。(谢谢David。)

请在定义函数的地方发布一些源代码。+1另一个选项实际上是在类定义内定义方法,其效果与在类定义外将
内联
添加到方法定义中相同。
int Vector3D::operator < (const Vector 3D &vector) const
{
 if(x<vector.x)
   return 1;
 else
   return 0;
}
debug/src/common/propagation-delay-model_1.o: In function `empty':
/usr/include/c++/4.1.2/limits:1044: multiple definition of `ns3::Vector3D::operator<(ns3::Vector3D const&) const'
debug/src/core/vector_1.o:/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/build/../src/core/vector.h:118: first defined here
debug/src/common/propagation-loss-model_1.o: In function `empty':
/usr/include/c++/4.1.2/new:94: multiple definition of `ns3::Vector3D::operator<(ns3::Vector3D const&) const'
debug/src/core/vector_1.o:/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/build/../src/core/vector.h:118: first defined here
debug/src/common/jakes-propagation-loss-model_1.o: In function `empty':
/usr/include/c++/4.1.2/new:94: multiple definition of `ns3::Vector3D::operator<(ns3::Vector3D const&) const'
debug/src/core/vector_1.o:/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/build/../src/core/vector.h:118: first defined here
debug/src/common/cost231-propagation-loss-model_1.o: In function `empty':
/usr/include/c++/4.1.2/limits:1044: multiple definition of `ns3::Vector3D::operator<(ns3::Vector3D const&) const'
debug/src/core/vector_1.o:/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/build/../src/core/vector.h:118: first defined here
debug/src/common/spectrum-propagation-loss-model_1.o: In function `~BandInfo':
/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/build/debug/ns3/type-id.h:392: multiple definition of `ns3::Vector3D::operator<(ns3::Vector3D const&) const'
debug/src/core/vector_1.o:/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/build/../src/core/vector.h:118: first defined here
debug/src/common/friis-spectrum-propagation-loss_1.o: In function `~BandInfo':
/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/build/debug/ns3/vector.h:118: multiple definition of `ns3::Vector3D::operator<(ns3::Vector3D const&) const'
debug/src/core/vector_1.o:/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/build/../src/core/vector.h:118: first defined here
debug/src/node/spectrum-phy_1.o: In function `~TypeId':
/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/build/debug/ns3/type-id.h:392: multiple definition of `ns3::Vector3D::operator<(ns3::Vector3D const&) const'
debug/src/core/vector_1.o:/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/build/../src/core/vector.h:118: first defined here
debug/src/internet-stack/ipv6-l3-protocol_1.o: In function `new_allocator':
/usr/include/c++/4.1.2/new:94: multiple definition of `ns3::Vector3D::operator<(ns3::Vector3D const&) const'
debug/src/core/vector_1.o:/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/build/../src/core/vector.h:118: first defined here
debug/src/routing/olsr/olsr-routing-protocol_1.o: In function `~Association':
/usr/include/c++/4.1.2/new:94: multiple definition of `ns3::Vector3D::operator<(ns3::Vector3D const&) const'
debug/src/core/vector_1.o:/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/build/../src/core/vector.h:118: first defined here
debug/src/routing/olsr/test/bug780-test_1.o: In function `new_allocator':
/usr/include/c++/4.1.2/new:94: multiple definition of `ns3::Vector3D::operator<(ns3::Vector3D const&) const'