类的对象指针和二级指针
1 #include <iostream> 2 3 class myclass 4 { 5 public: 6 int x; 7 int y; 8 public: 9 myclass(int, int);//构造函数 10 void printxy(); 11 }; 12 13 myclass::myclass(int a, int b) :x(a), y(b)//构造函数 14 { 15 16 } 17 18 void myclass::printxy() 19 { 20 std::cout << x << " " << y << std::endl; 21 } 22 23 void main() 24 { 25 myclass *p(new myclass(10, 9));//一级指针 26 27 p->printxy(); 28 29 myclass class1(20, 1); 30 31 myclass **pp = &p;//二级指针 32 33 (*pp)->printxy();//一级指针 34 (**pp).printxy();//0级指针 35 36 system("pause"); 37 }
123
时间: 2024-10-07 02:21:40