使用指针访问类

#include<iostream>
using namespace std;

class Node{
public: int y;
        int x;
};


int main(){

    Node *pPointer=new Node();
    cout<<"未赋值前:"<<(*pPointer).y<<endl;

    pPointer->y=10;
    cout<<"赋值后:"<<(*pPointer).y<<endl;

    return 0;
}


备注:类的指针是一个指针而不是类,当类的指针访问子成员的时候,用—>成员或(*类).成员等效.

猜你喜欢

转载自blog.csdn.net/huang123307/article/details/8710614