| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 720 人关注过本帖
标题:关于 C++ 中 this 指针的使用~
取消只看楼主 加入收藏
S140131022
Rank: 2
来 自:重庆邮电大学
等 级:论坛游民
帖 子:205
专家分:35
注 册:2014-10-9
结帖率:90.24%
收藏
已结贴  问题点数:20 回复次数:1 
关于 C++ 中 this 指针的使用~
#include<iostream>
#include<string>
using namespace std;

class student
{
private:
    int num;
    string name;
    float grade;
public:
    student();
    void put(student *this);
};

student::student()
{
num=0;
name="none";
grade=0;
}

void student::put(student *this)
{
cout<<this->num<<endl;
cout<<this->name<<endl;
cout<<this->grade<<endl;
}

void main()
{
student stu;
stu.put(&stu);
}

本想用此程序来验证一下this指针的用法的,却无论如何都无法运行~请问哪儿出了错?
搜索更多相关主题的帖子: private include public 
2014-10-26 16:36
S140131022
Rank: 2
来 自:重庆邮电大学
等 级:论坛游民
帖 子:205
专家分:35
注 册:2014-10-9
收藏
得分:0 
#include<iostream>
using namespace std;

class time
{
private:
int hour;
int minu;
int seco;
public:
void put();
void set();
time(int a,int b,int c);
};
time::time(int a,int b,int c):hour(a),minu(b),seco(c){}

void time::set()
{
cin>>hour>>minu>>seco;
}

void time::put()
{
cout<<hour<<':'<<minu<<':'<<seco<<endl;
}

void main()
{
time t1(17,34,30);
time *const p;
p=&t1;

}
主函数中关于常指针又编译出错~我感觉没错呀~哎·....

既然还有不甘心
就还没到放弃的时候~
2014-10-26 17:53
快速回复:关于 C++ 中 this 指针的使用~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015111 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved