B:
private:
string m_strName="世間第一帥氣人";
};
Student::Student(string name) :m_strName(name) {}
void Student::setName(string name) {
m_strName = name;
}
string Student::getName() {
return m_strName;
}
int main(void) {
Student *stu = new Student;
stu->setName("慕課網(wǎng)");
private:
string m_strName="世間第一帥氣人";
};
Student::Student(string name) :m_strName(name) {}
void Student::setName(string name) {
m_strName = name;
}
string Student::getName() {
return m_strName;
}
int main(void) {
Student *stu = new Student;
stu->setName("慕課網(wǎng)");
2019-01-26
A:
#include <iostream>
#include <string>
using namespace std;
class Student {
public:
Student(string name) ;
Student(const Student & stuc) {};
Student() {};
~Student() {};
void setName(string name);
string getName();
#include <iostream>
#include <string>
using namespace std;
class Student {
public:
Student(string name) ;
Student(const Student & stuc) {};
Student() {};
~Student() {};
void setName(string name);
string getName();
2019-01-26
頭文件B:
int getMax();
private:
string m_strName;
int m_iAge;
const int m_iMax = 1;
};
int getMax();
private:
string m_strName;
int m_iAge;
const int m_iMax = 1;
};
2019-01-26
頭文件A:
#include"string"
#include"iostream"
using namespace std;
class Student {
public:
Student(string name = "小白", int Age = 1, int Max = 100);//初始化構(gòu)造函數(shù) 構(gòu)造函數(shù)——用以初始化
Student(const Student &stu);//拷貝構(gòu)造函數(shù)
void setName(string name);
string getName();
void setAge(int Age);
int getAge();
#include"string"
#include"iostream"
using namespace std;
class Student {
public:
Student(string name = "小白", int Age = 1, int Max = 100);//初始化構(gòu)造函數(shù) 構(gòu)造函數(shù)——用以初始化
Student(const Student &stu);//拷貝構(gòu)造函數(shù)
void setName(string name);
string getName();
void setAge(int Age);
int getAge();
2019-01-26
源2B:
void Student::setName(string name) {
m_strName = name;
}
string Student::getName() {
return m_strName;
}
void Student::setAge(int Age) {
m_iAge = Age;
}
int Student::getAge() {
return m_iAge;
}
int Student::getMax() {
return m_iMax;
}
void Student::setName(string name) {
m_strName = name;
}
string Student::getName() {
return m_strName;
}
void Student::setAge(int Age) {
m_iAge = Age;
}
int Student::getAge() {
return m_iAge;
}
int Student::getMax() {
return m_iMax;
}
2019-01-26
源2A:
#include"標(biāo)頭.h"
Student::Student(string name, int Age, int Max) :m_strName(name), m_iAge(Age), m_iMax(Max) { cout << "you used initialization_code"<<endl; } //初始化列表
Student::Student(const Student & stu) { cout << "you used copy_code"<<endl; }//拷貝構(gòu)造函數(shù)
#include"標(biāo)頭.h"
Student::Student(string name, int Age, int Max) :m_strName(name), m_iAge(Age), m_iMax(Max) { cout << "you used initialization_code"<<endl; } //初始化列表
Student::Student(const Student & stu) { cout << "you used copy_code"<<endl; }//拷貝構(gòu)造函數(shù)
2019-01-26
源1:
#include"標(biāo)頭.h"
int main() {
Student *str = new Student;//初始化——指針?lè)绞?br /> Student stu1("小白", 12, 150);//初始化
str->setName("慕課網(wǎng)");
Student stu2 = stu1;//測(cè)試拷貝函數(shù)部分
cout << stu1.getName() << " \t " << str->getAge() << "\t" << str->getMax();
delete str;
str = NULL;
return 0;
}
#include"標(biāo)頭.h"
int main() {
Student *str = new Student;//初始化——指針?lè)绞?br /> Student stu1("小白", 12, 150);//初始化
str->setName("慕課網(wǎng)");
Student stu2 = stu1;//測(cè)試拷貝函數(shù)部分
cout << stu1.getName() << " \t " << str->getAge() << "\t" << str->getMax();
delete str;
str = NULL;
return 0;
}
2019-01-26
#include"string"
#include"iostream"
using namespace std;
class Student {
public:
Student(string name = "小白",int Age=1,int Max=100);//構(gòu)造函數(shù)初始化
void setName(string name);
string getName();
void setAge(int Age);
int getAge();
int getMax();
private:
string m_strName;
int m_iAge;
const int m_iMax
#include"iostream"
using namespace std;
class Student {
public:
Student(string name = "小白",int Age=1,int Max=100);//構(gòu)造函數(shù)初始化
void setName(string name);
string getName();
void setAge(int Age);
int getAge();
int getMax();
private:
string m_strName;
int m_iAge;
const int m_iMax
2019-01-25
Student::Student(string name,int Age,int Max) :m_strName(name), m_iAge(Age),m_iMax(Max){} //初始化列表
void Student::setName(string name) {
m_strName = name;
}
string Student::getName() {
return m_strName;
}
void Student::setAge(int Age) {
m_iAge = Age;
}
int Student::getAge() {
return m_iAge;
}
void Student::setName(string name) {
m_strName = name;
}
string Student::getName() {
return m_strName;
}
void Student::setAge(int Age) {
m_iAge = Age;
}
int Student::getAge() {
return m_iAge;
}
2019-01-25
DEMO1:
#include"標(biāo)頭.h"
int main() {
Student *str = new Student;
Student stu1("小白", 12, 150);
str->setName("慕課網(wǎng)");
cout << stu1.getName() << " \t " << str->getAge() << "\t" << str->getMax();
delete str;
str = NULL;
return 0;
}
#include"標(biāo)頭.h"
int main() {
Student *str = new Student;
Student stu1("小白", 12, 150);
str->setName("慕課網(wǎng)");
cout << stu1.getName() << " \t " << str->getAge() << "\t" << str->getMax();
delete str;
str = NULL;
return 0;
}
2019-01-25
class Student {
public:
void setName(string name) {
m_strName = name;
}
string getName() {
return m_strName;
}
private:
string m_strName;
};
int main() {
Student *str = new Student;
str->setName("慕課網(wǎng)");
cout << str->getName();
delete str;
str = NULL;
return 0;
}
public:
void setName(string name) {
m_strName = name;
}
string getName() {
return m_strName;
}
private:
string m_strName;
};
int main() {
Student *str = new Student;
str->setName("慕課網(wǎng)");
cout << str->getName();
delete str;
str = NULL;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main(){
class student {
public:
string m_strName = "王發(fā)財(cái)";
int m_iAge = 199;
}stu;
stu.m_iAge = 2;
stu.m_strName = "慕課網(wǎng)";
cout << stu.m_iAge <<endl<< stu.m_strName << endl;
}
#include <string>
using namespace std;
int main(){
class student {
public:
string m_strName = "王發(fā)財(cái)";
int m_iAge = 199;
}stu;
stu.m_iAge = 2;
stu.m_strName = "慕課網(wǎng)";
cout << stu.m_iAge <<endl<< stu.m_strName << endl;
}
最贊回答 / __盛夏光年__
無(wú)參構(gòu)造函數(shù)和有參構(gòu)造函數(shù)放在類(lèi)外定義沒(méi)有返回值,所以去掉void即可。ps:在定義類(lèi)的時(shí)候Student()后面沒(méi)有;
2019-01-08