类的成员函数能否在定义过程中调用该类中的成员函数?

Yanger_xy 2009-02-19 10:29:25
#include <iostream>
#include <string>
using namespace std;

class Student
{
public:
Student (int n, string nam)
{
number = n;
name = nam;
}
void display ();
private:
int number;
string name;
};

void Student::display ()
{
cout << number << endl;
cout << name << endl;
}

class Student_1:public Student
{
public:
Student_1 (int number, string name, int n1, string nam1, int a, string addr):Student (number, name),monitor (n1, nam1), age (a), address (addr) {};
void show_monitor ()
{
cout << "the monitor is:" << endl;
display ();
}
void show ()
{
cout << "this student is:" << endl;
display ();
cout << age << endl;
cout << address << endl;
//show_mointor ();//此处如果去掉就正确,若不去掉就不正确...
}
private:
Student monitor;
int age;
string address;
};

int main ()
{
Student_1 stud1 (801, "liu na", 801060127, "yang xiaoying", 21, "liujiading");
#include <iostream>
#include <string>
using namespace std;

class Student
{
public:
Student (int n, string nam)
{
number = n;
name = nam;
}
void display ();
private:
int number;
string name;
};

void Student::display ()
{
cout << number << endl;
cout << name << endl;
}

class Student_1:public Student
{
public:
Student_1 (int number, string name, int n1, string nam1, int a, string addr):Student (number, name),monitor (n1, nam1), age (a), address (addr) {};
void show_monitor ()
{
cout << "the monitor is:" << endl;
display ();
}
void show ()
{
cout << "this student is:" << endl;
display ();
cout << age << endl;
cout << address << endl;
//show_mointor ();//此处如果去掉就正确,若不去掉就不正确...
}
private:
Student monitor;
int age;
string address;
};

int main ()
{
Student_1 stud1 (801, "liu na", 801060127, "yang xiaoying", 21, "liujiading");
stud1.show ();
stud1.show_monitor ();
return 0;
}




stud1.show_monitor ();
return 0;
}

我的本意是将在主函数中只调用stud1.show ();这一个函数就将所有的内容都输出来,
但是如果将带注释的那一行写出来后,结果出现编译错误:error C2065: 'show_mointor' : undeclared identifier
不知为何,望指教...

...全文
147 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lixinzdx 2009-02-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 cpp_yangzuoshi 的回复:]
我知道了!show_mointor ()写错了!
马虎....
[/Quote]
UP
bfhtian 2009-02-20
  • 打赏
  • 举报
回复
找到答案是关键,呵呵
南郁 2009-02-20
  • 打赏
  • 举报
回复
error C2065: 'show_mointor' : undeclared identifier

多碰几次,就会熟悉这些信息在说什么了。:)
fairchild811 2009-02-19
  • 打赏
  • 举报
回复
呵呵,省得我们再看这么长代码了
Yanger_xy 2009-02-19
  • 打赏
  • 举报
回复
我知道了!show_mointor ()写错了!
马虎....

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧