aludra.usc.edu(25): g++ -o final.out final.cpp Undefined first referenced symbol in file data::Get_Networth() /var/tmp//ccUz9c59.o data::Set_Networth(double) /var/tmp//ccUz9c59.o data::Get_Heightfeet() /var/tmp//ccUz9c59.o data::Get_Lettergpa() /var/tmp//ccUz9c59.o data::Set_Weight(int) /var/tmp//ccUz9c59.o data::Get_Weight() /var/tmp//ccUz9c59.o data::Get_Major() /var/tmp//ccUz9c59.o data::Set_Gpa(double) /var/tmp//ccUz9c59.o data::Get_GPA() /var/tmp//ccUz9c59.o data::Set_Age(int) /var/tmp//ccUz9c59.o data::Get_Age() /var/tmp//ccUz9c59.o data::Set_Major(std::basic_string, std::allocator >)/var/tmp//ccUz9c59.o data::Set_Data(std::basic_string, std::allocator >, int, int, int, double, std::basic_string, std::allocator >, double)/var/tmp//ccUz9c59.o data::Get_Heightfeetremainder() /var/tmp//ccUz9c59.o data::Set_Heightinches(int) /var/tmp//ccUz9c59.o data::data() /var/tmp//ccUz9c59.o data::Get_Name() /var/tmp//ccUz9c59.o data::Get_Heightinches() /var/tmp//ccUz9c59.o ld: fatal: Symbol referencing errors. No output written to final.out collect2: ld returned 1 exit status
这是我在Solaris中编译时不断使用g ++的内容.该代码在VS2010中完美编译.所以我无法弄清楚出了什么问题.
这是我的类文件的代码data.h:
#include <string>
using namespace …
Run Code Online (Sandbox Code Playgroud) 我觉得这应该是简单的事情,但我花了很多时间试图找出为什么我不能创建一个从同一个抽象类继承的不同类的链表
我推送到链表前面的每个类(即BadCruisingShootingAgent)都是从抽象类Agent继承的.
我得到....错误:无法声明字段'Node :: data'是抽象类型'Agent'
我的main.cpp文件是:
int main()
{
LinkedList<Agent> *agentList= new LinkedList<Agent>();
agentList->push_front(*(new BadCruisingShootingAgent));
agentList->push_front(*(new BadFollowingDisarmedAgent));
agentList->push_front(*(new BadFollowingShootingAgent));
agentList->push_front(*(new BadStationaryDisarmedAgent));
agentList->push_front(*(new BadStationaryShootingAgent));
agentList->push_front(*(new GoodCruisingDisarmedAgent));
agentList->push_front(*(new GoodCruisingShootingAgent));
agentList->push_front(*(new GoodFollowingDisarmedAgent));
agentList->push_front(*(new GoodFollowingShootingAgent));
agentList->push_front(*(new GoodStationaryDisarmedAgent));
agentList->push_front(*(new GoodStationaryShootingAgent));
for(int i=0; i<agentList->size(); i++)
{
cout << agentList->at(i).getType()<<" "<<agentList->at(i).nextMovingDirection(10,10)<<" "<<agentList->at(i).shootingDirection(10,10)<<endl;
}
return(0);
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这不起作用,如果我只是手动写,没有问题.
Agent *a= new BadCruisingShootingAgent;
cout << a->getType()<<" "<<a->extMovingDirection(10,10)<<" "<<a->shootingDirection(10,10)<<endl;
Run Code Online (Sandbox Code Playgroud)
然后我的链表的类函数push_front定义为:
template <typename T>
void LinkedList<T>::push_front(const T& val)
{
//make a new node
Node<T>* newOne = new Node<T>(val);
//push it onto the …
Run Code Online (Sandbox Code Playgroud)