C++ 类的 this 指针 语法练习
来源:互联网 发布:java 开启定时器 编辑:程序博客网 时间:2024/05/16 08:20
#include <iostream>#include <string>using namespace std;// 定义一个类 Studentclass Student{private:string name;int age;string address;public:// 存void setname(string s){name = s;}void setage(int y){age = y;}void setaddress(string add){address = add;} // 取string getname(){return name;}int getage(){return age;}string getaddress(){return address;}void Show(){ cout<<"this = "<<this<<endl;}protected:};int main(void){ Student x; x.Show(); cout<<"&x = "<<&x<<endl; // 以上表明this指向的就是当前的对象x cout<<"----------------------"<<endl; Student y; y.Show(); cout<<"&y = "<<&y<<endl; // 以上表明this指向的就是当前的对象y// --------------------return 0;}
第一次调用时,this地址与对象x的一样;
第二次调用是,this地址与对象y的一样.
- C++ 类的 this 指针 语法练习
- C++ 类的 this 指针 语法练习2
- C++ 类的 this 指针 语法练习3
- C++ 类的 this 指针 语法练习4
- C++ 类的 this 指针 语法练习5
- C ++的this指针
- 【c++】this 指针和类的继承
- C++, 类的构造函数 语法练习
- C++this指针的理解
- C++this指针的理解
- C++this指针的用法
- 【c++】this指针的使用
- 【C++】隐含的this指针
- C语言指针的练习
- 类的this指针
- C++Primer学习-类(隐含的this指针)
- 【C++】谈谈类定义里的this指针
- 【C++】【学习笔记】【016】this指针和类的继承
- VCL组件之方法
- Java做的摘要小软件
- win7笔记本设置WiFi热点详解
- C++,返回对象的引用,语法练习
- c/c++常见面试题 .
- C++ 类的 this 指针 语法练习
- Derby入门教程
- Html之【Text文本框】综合技巧大全(持续更新中...)
- 与php大版主xuzuning不得不说的事儿~~
- Hibernate的Firebird配置
- 线段树——Powered By God horses are clouds
- 博弈——Powered By God horses are clouds
- 线段树——Powered By 漂泊是为了更好的停驻
- 搜索——Powered By 漂泊是为了更好的停驻