为什么我可以成功编译而不实现其中一个函数?

Ema*_*res 0 c++ oop compilation class

我想了解如何在C++中编译类.

为什么下面的代码编译成功?是否Foo()需要编译实现才能成功?

class Test{
public:
    Test()  {}
    int Foo();
};

int main()
{
    Test obj;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Kar*_*ath 7

没有人试图调用Foo,因此链接器不会抱怨缺少实现,因为它不需要.

如果你写了virtual int Foo();,你会看到链接器错误.