gpt4 book ai didi

c++ - 未解析的外部符号 1 以及黑白虚拟和纯虚拟的区别?

转载 作者:行者123 更新时间:2023-11-28 06:52:56 26 4
gpt4 key购买 nike

<分区>

这可能出了什么问题?我们在哪里使用纯 virtual func() = 0;?此外,是否可以在一个 virtual 命令下使用不同的功能?我的意思是像 rotate,我可以写 move() 吗?努力掌握多态性。

using namespace std;

class shape
{
public:
virtual void rotate();
};

class triangle : public shape
{
public:
void rotate()
{
cout << "in triangle";
}
};

class line : public shape
{
public:
void rotate()
{
cout << "in line";
}
};

class circle : public shape
{
public:
void rotate()
{
cout << "in circle";
}
};

int main()
{
shape s;
triangle t;
circle c;
line l;
shape* ptr;

ptr = &s;
ptr->rotate();
ptr = &t;
ptr->rotate();
ptr = &l;
ptr->rotate();

system("PAUSE");
return 0;
}
error: LNK 1120: 1 unresolved externals   
error: LNK 2001: unresolved external symbol "public: virtual void_thiscall shape::rotate(void)"(?rotate@shape@@UAEXXZ)

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com