我的代碼哪里有問題
以下是有問題的代碼
2.cpp
# include <iostream>
# include<stdlib.h>
# include<string>
# include "Teacher.h"
using namespace std;
int main(void)
{
Teacher t1("Merry", 12, 150);
cout << t1.getName() << " " << t1.getAge() << " " << t1.getMax() << endl;
system("pause");
return 0;
}
Teacher.h
#include<iostream>
#include<string>
using namespace std;
class Teacher
{
public:
Teacher(string name = "Jim",int age = 1,int m = 100);
void setName(string name);
string getName();
void setAge(int age);
int getAge();
private:
string m_strName;
int m_iAge;
const int m_iMax;
};
2018-08-07
你的私有成員都沒有的得到有效的賦值傳遞,函數構造里面都是把值默認給了name,age,這些并不是你定義的變量,函數那些好像也沒實現。Teacher(string name = "? 默認",int age = 1, int max = 100){m_strName = name;m_iAge = age, m_iMax = max;}如果還有錯,就把set和get函數實現了,比如int getAge(){return m_iAge;}? ? ? void setAge(int age){m_iAge = age;}類推,把name函數和max函數全部實現,建議簡單的函數直接在Teacher.h文件里一并實現,你也可以重新創建一個.cpp但是在里面要導入.h頭文件
2018-08-04
m_iMax 沒有定義set 和 get