C++类的对象和类对象指针

来源:互联网 发布:卸载macbook软件 编辑:程序博客网 时间:2024/05/29 18:35

  
class Student  
{  
    public:  
    static int number;  
    string name;  
  
public:  
    Student() { }  
};  

int main(int argc, char** argv)  
{  
    Student* s1;  
    s1 = new Student();  
    Student s2;  
    return 0;  

1)类的指针:Student* s1;  还没有分配内存,他是一个内存地址值,他指向内存中存放的类对象(包括一些成员变量所赋的值)  

2)对象,他是利用类的构造函数在内存中分配一块内存(包括一些成员变量所赋的值).