When working with class inheritance, an incomprehensible error pops up. There is a suspicion that this is due to the lack of get and set (but there is a constructor) methods.
Below are 2 listings: 1 is the main program, and 2 is the listing of the TRectangle class. The TTriangle class is empty. I also attach a parent class (there is just a dummy with virtual dummy methods.

 //основной Ρ„Π°ΠΉΠ» ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ #include "stdafx.h" #include "TRectangle.h" #include "TTriangle.h" int _tmain(int argc, _TCHAR* argv[]) { TRectangle *Rect1 = new TRectangle; Rect1.Move(); return 0; } 

The class for the rectangle with the overridden Move method. In the class TFigure (virtual class-parent) is empty, contains the virtual method Move .

 #include "stdafx.h" #include "TRectangle.h" #include <iostream> using namespace std; TRectangle::TRectangle() { rx1 = 0; // x1,y1 x2,y2 ry1 = 0; // x3,y3 x4,y4 rx2 = 10; ry2 = 0; rx3 = 0; ry3 = 4; rx4 = 10; ry4 = 4; rStepX = 0; rStepY = 0; } TRectangle::~TRectangle() { } void TRectangle::Move() { cin >> rStepX; cin >> rStepY; cout << "rectangle is moved!" << endl; rx1 = rx1 + rStepX; //здСсь происходит ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ ΠΌΠ΅Ρ‚ΠΎΠ΄Π° Move rx2 = rx2 + rStepX; //ΠΈ Π² Π½Ρ‘ΠΌ происходит ΠΏΡ€ΠΈΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΊ Ρ‚ΠΎΡ‡ΠΊΠ°ΠΌ Π΄Π°Π½Π½ΠΎΠ³ΠΎ расстояния двиТСния rStep rx3 = rx3 + rStepX; rx4 = rx4 + rStepX; ry1 = ry1 + rStepY; ry2 = ry2 + rStepY; ry3 = ry3 + rStepY; ry4 = ry4 + rStepY; cout << rx1 << " " << rx2 << " " << rx3 << " " << rx4 << endl; cout << ry1 << " " << ry2 << " " << ry3 << " " << ry4 << endl; } 

Question: why the error occurs:

Error 1 error C2228: the expression to the left of ".Move" must represent a class, structure, or union [full path erased by me] classes_legacy_v2.cpp 10 1 Classes_Legacy_V2

    2 answers 2

    Rect1 you have a pointer!

     Rect1->Move() 

    You are using the wrong expression; to access through the pointer, use -> (or (*Rect1).Move() ).

    PS You are not from Java to C ++ come from? :)

    • Well, you can clarify the essence of this arrow. How many pros have already passed, I still have not understood its essence. I read on the wiki that this is an appeal to an object to which the dynamic structure refers (like so, if in your own words., And literally: a-> b Object B from the Object referred to by A - MarKo
    • I am a first-year student. Gnawing granite of science) hitherto very poorly wrote on PascalABC .NET - MarKo
    • 2
      If you have an object with members (data, functions) obj , how do you refer to them? Well, as they wanted - c point: obj.func() . But if you have a pointer, you must first dereference it , turning it into an object: *obj . And then to address through a point: (*obj).func() - exactly, with brackets, because of the priorities of operations. Sad? Still would. So the operator -> introduced -> as a replacement for this record: (*obj).func() identically obj->func() . That's all. As far as I remember, in Pascal this is obj^.func ... - Harry
    • @Harry: Operator -> originally appeared in prehistoric C and at the same time its functionality was broader than the functionality of the combination of * and . . Therefore, to say that -> was introduced purely as a "replacement" to reduce the entry would be wrong. Initially, the operator -> had its own reasons for existence. Only later (in K & R C) he became the full equivalent of a combination of * and . . - AnT

    You have a typo - the wrong syntax. For a pointer, there should be an expression referring to a class member as

     Rect1->Move(); 

    or how

     ( *Rect1 ).Move();