# apt-get install g++
azan@ubuntu:~$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
#include <stdio.h>
//将类定义在命名空间中
namespace Diy{
class Student{
public:
char *name;
int age;
float score;
public:
void say(){
printf("%s的年龄是 %d,成绩是 %f\n", name, age, score);
}
};
}
int main(){
Diy::Student stu1;
stu1.name = "小明";
stu1.age = 15;
stu1.score = 92.5f;
stu1.say();
return 0;
}
azan@ubuntu:~/work/azan$ g++ maintest.cpp -o maintest
azan@ubuntu:~/work/azan$ ls
maintest maintest.cpp
azan@ubuntu:~/work/azan$ ./maintest
小明的年龄是 15,成绩是 92.500000
原文:https://www.cnblogs.com/azan777/p/14845487.html