错误C2039:"getNumberOfCorners":不是"Shape"的成员 [英] error C2039: 'getNumberOfCorners' : is not a member of 'Shape

查看:98
本文介绍了错误C2039:"getNumberOfCorners":不是"Shape"的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的错误是错误C2039:" getNumberOfCorners":不是C ++中"Shape"的成员如何解决?

解决方案

<一旦将其向下转换为形状,Circle类中的方法将不可见.您已经将它们扔掉了(或至少将它们隐藏了).当您具有形状类时,仅Shape上的方法可见.派生类型是什么无关紧要,您需要将其强制转换为该类型.


Gosh.好吧,C ++中没有Shape类,所以我想问题可能出在您正在使用的某个类上,该类不包含名为getNumberOfCorners的方法,称为Shape.

你想做什么 ?这个班是从哪里来的?为什么无法理解基本错误消息?是什么让您认为此方法应该存在?


好吧,我尝试编写形状层次结构.一个抽象基类(其名称为Shape),该类包含两个纯虚函数(totalArea& shapeName),然后从Shape类继承twoDshape抽象类. twoDshape类也包含两个抽象函数. (perimeter& numberOfCorners),然后我从twoDshape实现一个具体的类.它的名字叫圆....

最后,我的问题是; :)

然后我制作一个形状指针,然后我使用->操作员达到对象的周边功能...

圈出myCircle; //我的圈子对象

形状* sPtr =& myCircle;

cout<< sPtr-> perimeter(); //我在这行有问题

它说:perimeter()不是形状的成员


I have an error which is "error C2039: ''getNumberOfCorners'' : is not a member of ''Shape" in C++ how can we correct ?

解决方案

Once you downcast it to a shape, the methods in the Circle class are not visible. You''ve thrown them away ( or at least, hidden them ). Only methods on Shape are visible, when you have a shape class. It is irrelevant what the derived type is, you need to cast it to that type.


Gosh. Well, there''s no Shape class in C++, so I guess the problem must lie with some class you''re using, a class which does NOT contain a method called getNumberOfCorners, and is called Shape.

What are you trying to do ? Where did this class come from ? Why can''t you understand a basic error message ? What makes you think that this method should exist ?


well i try to write a shape hierarchy. an abstract base class (its name is Shape) and that class contain two pure virtual functions (totalArea & shapeName ) and then i inherit twoDshape abstract class from Shape class. twoDshape class contains two abstract functions, too. (perimeter & numberOfCorners) then i implement a concrete class from twoDshape. And its name is circle....

Finally, my problem is ; :)

Then i make a shape pointer and i use -> operator to reach to perimeter function of the object...

circle myCircle; //my circle object

shape *sPtr = &myCircle;

cout << sPtr->perimeter() ; // i have the problem in this line

it says: perimeter() is not member of shape


这篇关于错误C2039:"getNumberOfCorners":不是"Shape"的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆