Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于在C+中实现抽象函数的问题+;? 我正在学习和测试一段C++代码,如下: #include "stdafx.h" #include <iostream> using namespace std; #include <conio.h> #include <cstring> class Shape { public: Shape() {}; ~Shape() {}; virtual void display() const = 0; virtual double volume() const = 0; }; class Square : public Shape { public: Square() {}; ~Square() {}; void display() const; double volume() const; }; void Square::display() const { cout << "Square!!!!!!!!!!!!!!" << endl; } double Square::volume() const { cout << "Square Volume........." << endl; return 0.0; } int _tmain(int argc, _TCHAR* argv[]) { Shape *s; s = new Square; // error here (*s).display(); return 0; } #包括“stdafx.h” #包括 使用名称空间std; #包括 #包括 阶级形态{ 公众: Shape(){}; ~Shape(){}; 虚空显示()常量=0; 虚拟双卷()常量=0; }; 阶级广场:公共形态{ 公众: 正方形({}); ~Square(){}; void display()常量; 双卷()常数; }; void Square::display()常量{ 我敢肯定你的问题是你的主要声明_C++ - Fatal编程技术网

关于在C+中实现抽象函数的问题+;? 我正在学习和测试一段C++代码,如下: #include "stdafx.h" #include <iostream> using namespace std; #include <conio.h> #include <cstring> class Shape { public: Shape() {}; ~Shape() {}; virtual void display() const = 0; virtual double volume() const = 0; }; class Square : public Shape { public: Square() {}; ~Square() {}; void display() const; double volume() const; }; void Square::display() const { cout << "Square!!!!!!!!!!!!!!" << endl; } double Square::volume() const { cout << "Square Volume........." << endl; return 0.0; } int _tmain(int argc, _TCHAR* argv[]) { Shape *s; s = new Square; // error here (*s).display(); return 0; } #包括“stdafx.h” #包括 使用名称空间std; #包括 #包括 阶级形态{ 公众: Shape(){}; ~Shape(){}; 虚空显示()常量=0; 虚拟双卷()常量=0; }; 阶级广场:公共形态{ 公众: 正方形({}); ~Square(){}; void display()常量; 双卷()常数; }; void Square::display()常量{ 我敢肯定你的问题是你的主要声明

关于在C+中实现抽象函数的问题+;? 我正在学习和测试一段C++代码,如下: #include "stdafx.h" #include <iostream> using namespace std; #include <conio.h> #include <cstring> class Shape { public: Shape() {}; ~Shape() {}; virtual void display() const = 0; virtual double volume() const = 0; }; class Square : public Shape { public: Square() {}; ~Square() {}; void display() const; double volume() const; }; void Square::display() const { cout << "Square!!!!!!!!!!!!!!" << endl; } double Square::volume() const { cout << "Square Volume........." << endl; return 0.0; } int _tmain(int argc, _TCHAR* argv[]) { Shape *s; s = new Square; // error here (*s).display(); return 0; } #包括“stdafx.h” #包括 使用名称空间std; #包括 #包括 阶级形态{ 公众: Shape(){}; ~Shape(){}; 虚空显示()常量=0; 虚拟双卷()常量=0; }; 阶级广场:公共形态{ 公众: 正方形({}); ~Square(){}; void display()常量; 双卷()常数; }; void Square::display()常量{ 我敢肯定你的问题是你的主要声明,c++,C++,如果您将其更改为标准的主定义,我相信您的链接问题将得到解决 int main() { Shape *s = new Square(); // error here s->display(); return 0; } 我很确定你的问题是你的主要声明 如果您将其更改为标准的主定义,我相信您的链接问题将得到解决 int main() { Shape *s = new Square(); // error here s->display();

如果您将其更改为标准的主定义,我相信您的链接问题将得到解决

 int main()
 {
   Shape *s = new Square(); // error here
   s->display();
   return 0;
 } 

我很确定你的问题是你的主要声明

如果您将其更改为标准的主定义,我相信您的链接问题将得到解决

 int main()
 {
   Shape *s = new Square(); // error here
   s->display();
   return 0;
 } 

上面的代码可以在VS2010和Ideone上正确编译和运行

检查


在上述代码片段中实现抽象函数的方式没有任何错误。

上述代码在VS2010和Ideone上正确编译和运行

检查



在上面的代码段中,您实现抽象函数的方式没有任何错误。

上面应该有更详细的消息,说明LNK1120错误的确切含义。请提供这些信息。不要忘记将析构函数设置为虚拟的(我认为这不是您的问题,但这是一个问题)。标准的
main
intmain(intargc,char*argv[])
(或者
intmain()
,如果不使用这些参数)。别再胡说八道了。而且你不需要
conio.h
。正如@Zilchonum的评论所暗示的,在我看来,这似乎是一个问题,要么是关于你如何安装或使用编译器,要么是关于代码(至少不是你发布的代码)。这并不是说代码是完美的,但我没有看到任何应该给出未解析外部的内容。旁注:不要编写
(*s)。display()
。使用
s->display()
相反。上面应该有更详细的消息,说明LNK1120错误的确切含义。请提供这些信息。不要忘记将析构函数设置为虚拟的(我认为这不是你的问题,但这是一个问题)。标准的
main
int main(int argc,char*argv[])
(或者
int main()
,如果你不使用这些参数的话)。去掉那些VC++的废话。你不需要
conio.h
。正如@Zilchonum的评论所暗示的那样,在我看来,这是一个关于你如何安装或使用编译器的问题,而不是关于代码的问题(至少不是你发布的代码)。这并不是说代码是完美的,但我没有看到任何应该给出未解析外部的内容。旁注:不要编写
(*s)。display()
。使用
s->display()
相反。他使用的是MSVC++2005。所以这不应该是问题所在。@Nawaz确实如此,但这仍然是一种不好的做法,除非有人明确针对Windows。从未使用过VS,没有意识到他们可以使用这个非标准主声明。@Etienne:不好的做法是一回事,说这是问题是另一回事。@Etienne,这是一种不好的做法od-新程序应专门使用unicode API当人们需要从同一个代码库生成一个针对unicode windows NT的版本,另一个针对非unicode windows 9x的版本时,它很有用,但实际上不应该再使用了。他使用的是MSVC++2005。所以这不应该是问题。@Nawaz确实如此,但除非明确针对windows,否则这仍然是一种不好的做法。Never使用了VS,没有意识到他们可以使用这个非标准的主声明。@Etienne:错误的做法是一回事,说这是问题是另一回事。@Etienne,这是错误的做法期-新程序应该只使用unicode API。_tmain()当人们需要从同一个代码库生成一个针对unicode windows NT的构建,另一个针对非unicode windows 9x的构建时,它非常有用,但它真的不应该再使用了。