为什么我会报不允许成员函数重新申明?
代码如下:
teacher.cpp的代码:
#include<iostream>
#include<string>
#include"teacher.h"
using namespace std;
void teacher::setName(string name)
{m_strName=name;}
string teacher::getName()
{return m_strName;}
void teacher::setAge(int age)
{m_iAge=age;}
int teacher::getAge()
{return m_iAge;}
teacher::teacher(){
m_strName="jim";
m_iAge=114;
cout<<"teacher()"<<endl;
}
teacher::teacher(string name,int age);
int main(){
teacher t;
t.setName("kongzi");
cout<<t.getName()<<endl;
t.setAge(111);
cout<<t.getAge()<<endl;
system("pause");
return 0;
}
这是·teacher.h的代码:
#include<string>
using namespace std;
class teacher{
public:
teacher();
teacher(string name,int age);
void setName(string name);
string getName();
void setAge(int age);
int getAge();
private:
string(m_strName);
int(m_iAge);
};
这是demo.cpp的代码:
#include<iostream>
#include<string>
#include"teacher.h"
using namespace std;
int main(void){
teacher t1;
teacher t2("merry", 12);
cout<<t1.getName()<<t1.getAge()<<endl;
cout<<t2.getName()<<t2.getAge()<<endl;
}
按照这样的代码运行会报如下错误:1>d:\vs 2010\project\test8\test8\teacher.cpp(23): error C2761: “{ctor}”: 不允许成员函数重新声明
就是不知道怎么解决,老师不也在teacher.cpp里面定义了两个构造函数吗?有参和无参,怎么我这里定义会显示是重新申明了?表示不懂