Points.h
Points_main.cppcodice:class Points{ public: void setX(int); void setY(int); void setZ(int); void setOrtogonal(int,int); void setCartesian(int,int,int); private: int x; int y; int z; };
Errori:codice:#include <iostream> #include "Points.h" using namespace std; void Points::setX(int a){ x = a; } void Points::setY(int a){ y = a; } void Points::setZ(int a){ z = a; } void Points::setOrtogonal(int a, int b){ setX(a); setY(b); } void Points::setCartesian(int a, int b, int c){ setX(a); setY(b); setZ(c); } int main(){ Points* p; p = new Points(); p->setOrtogonal(5,10); cout << "x = " << p.x << endl; cout << "y = " << p.y << endl; return 0; }
C:\Points_main.cpp(31) : error C2228: left of '.x' must have class/struct/union type
C:\Points_main.cpp(32) : error C2228: left of '.y' must have class/struct/union type
Sinceramente non ho capito l'uso del puntatore per la classe, per ho utilizzato la sintassi di
http://programmazione.html.it/cplusp...lusplus_34.htm
Tra l'altro ho fatto diverse prove. Damn, alla prima compilazione dei programmi c++ ho sempre errori su errori; questo perchè non ci ho mai programmato, seppur ho letto molto.
Vabbè, help![]()

Rispondi quotando