类内定义

class Teacher
{
private:
	string _name;
	int _age;
public:
	Teacher()
	{
		printf("create techer \n");
	}
	Teacher(string name)
	{
		_name = name;
		printf("create techer with name \n");
	}

	void SetName(string name)
	{
		_name = name;
	}
	string GetName()
	{
		return _name;
	}
	void Say()
	{
		string des = "I'm Teacher and my name is ";
		des += _name;
		cout<< des<< endl;
		//printf(des);
	}
};

  

 

类外定义

namespaceDemo.h

namespace MyPrintSpace
{
    void Say();
}

namespaceDemo.cpp
#include "namespaceDemo.h"
//为了调用带有命名空间的函数或变量,需要在前面加上命名空间的名称,
void MyPrintSpace::Say()
{
	cout<<"MyPrintSpace say()"<<endl;
}

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-11-13
  • 2021-08-24
猜你喜欢
  • 2021-05-27
  • 2021-10-23
  • 2021-12-13
  • 2021-08-16
  • 2021-09-23
  • 2021-08-28
相关资源
相似解决方案