// 使用new关键字,实例化对象 Student *str = new Student();需要括号啊?
为什么 // 使用new关键字,实例化对象 Student *str = new Student(); 需要括号啊?
为什么 // 使用new关键字,实例化对象 Student *str = new Student(); 需要括号啊?
2018-01-27
#include <iostream>
#include <string>
using namespace std;
/**
* 定义类:Student
* 数据成员:名字、年龄
*/
class student
{
public:
// 定义数据成员名字 m_strName 和年龄 m_iAge
string m_strName;
int m_iAge;
};
int main()
{
// 实例化一个Student对象stu
student *stu = new student;
// 设置对象的数据成员
stu->m_strName = "慕课网";
stu->m_iAge = 2;
// 通过cout打印stu对象的数据成员
cout << stu->m_strName << " " << stu->m_iAge<< endl;
return 0;
}
不需要括号的
举报