类的成员函数能否在定义过程中调用该类中的成员函数?
#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
不知为何,望指教...