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