接口:不能实例化的东西,只需把构造函数私有化即可!
源码如下:
#ifndef __PRINTMAINVIEWPROXY_H__
#define __PRINTMAINVIEWPROXY_H__
class PrintMainViewProxy{
public:
static char *getHelloWorld();
static char *getHowAreYou();
private:
PrintMainViewProxy();
};
#endif //__PRINTMAINVIEWPROXY_H__
#include 'PrintMainViewProxy.h'
char * PrintMainViewProxy::getHelloWorld()
{
return 'Hello World';
}
char * PrintMainViewProxy::getHowAreYou()
{
return 'How Are You';
}
PrintMainViewProxy::PrintMainViewProxy()
{
}
#include
#include 'PrintMainViewProxy.h'
using namespace std;
void main(){
char *helloWorld = PrintMainViewProxy::getHelloWorld();
char *howAreYou = PrintMainViewProxy::getHowAreYou();
cout << helloWorld << endl;
cout << howAreYou << endl;
getchar();
}
程序运行截如下:
如果实例化就会报错!
文章为作者独立观点,不代表股票交易接口观点