[英]Linking with g++ undefined reference
我编写了以下代码:
//--a.cpp--//
#include <stdio.h>
class A
{
public:
void bar();
virtual void foo()=0;
};
class B: public A
{
public:
void foo()
{
A::bar();
}
}
int main()
{
B *b= new B();
b->foo();
return 0;
}
//--b.cpp--//
#include <stdio.h>
class A
{
public:
void bar()
{
printf("class A");
}
}
现在,我按照以下步骤进行comipilng和链接该模块:
g++ -c a.cpp
g++ -c b.cpp
g++ -o bin a.o b.o
但是链接器会引发undefined reference error
。 我不明白,为什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.