首页  

c++ 面向对象 例子     所属分类 c 浏览量 673
类 Class  
实例 Instance
C++ 类(Class)可看做C结构体(Struct)的升级版
类成员  变量 或 函数
成员变量称为属性(Property)
成员函数称为方法(Method)
通过类定义出来的变量 叫对象(Object)


#include "stdio.h"

class Student{
public:
    const char *name;
    int age;
    float score;

    void display(){
        printf("name=%s,age=%d,score=%f\n", name, age, score);
    }
};

int main(){  
    Student student; 
    student.name = "tiger";
    student.age = 7;
    student.score = 92.5f;
    student.display();
    return 0;
}

上一篇     下一篇
预定义宏 __cplusplus

c/c++标准预定义宏

c++ 结构体例子

C++11 智能指针

C++类成员初始化

c++ 初始化列表