C++ c++;类变量作为类成员
我收到一条消息:C++ c++;类变量作为类成员,c++,class,gcc,C++,Class,Gcc,我收到一条消息:在以下代码中的字符串class AInv{上未定义对AVector::AVector()的引用。: #ifndef AINV_HPP_ #define AINV_HPP_ #include "AVector.hpp" class AInv { public: double w; double g; AVector vector; }; #endif /* AINV_HPP_ */ AVector的定义: #ifndef A
在以下代码中的字符串class AInv{
上未定义对AVector::AVector()的引用。
:
#ifndef AINV_HPP_
#define AINV_HPP_
#include "AVector.hpp"
class AInv {
public:
double w;
double g;
AVector vector;
};
#endif /* AINV_HPP_ */
AVector的定义:
#ifndef AVECTOR_HPP_
#define AVECTOR_HPP_
class AVector {
public:
double x;
double y;
double z;
AVector();
AVector(const AVector &v);
};
#endif /* AVECTOR_HPP_ */
是否可以使用类变量(而不是地址)作为类成员?我希望避免变量向量的显式构造函数/析构函数
是否可以使用类变量(而不是地址)作为类成员
是的
我希望避免变量向量的显式构造函数/析构函数
不需要显式析构函数;类类型的每个成员的析构函数都将由AInv
析构函数自动调用,无论您是自己编写还是让编译器生成隐式析构函数
为了避免显式构造函数调用的需要,成员类型必须有一个可访问的默认构造函数。您已经声明了一个,这样就可以了
但是,错误消息表示您忘记定义默认构造函数,或者没有链接到包含该定义的文件。错误
未定义引用是一个链接错误。您可能没有为AVector
的默认构造函数定义,或者它没有在Hanks中链接到Niall!I在makefile中跳过AVector.o。问题解决了!