问一个C++编译出现的问题...简单,拿分请进...

Viali 2005-12-12 07:45:17
//不明白为何会出错..关键是Factory里头的static函数.
#include <iostream>
#include <Wtypes.h>
#include <wincon.h>
using namespace std;

HANDLE console_ = GetStdHandle(STD_OUTPUT_HANDLE);
void gotoxy( int x, int y )
{
COORD coord;
coord.X = x-1;
coord.Y = y-1;
SetConsoleCursorPosition( console_, coord );
}

class Gadget
{
public:
Gadget( char ch ){
ch_ = ch;
}
virtual void draw(long x_, long y_, long w_)
{
int i;
gotoxy( x_, y_ );
for (i=0; i < w_; i++) cout << ch_;
cout << endl;
gotoxy( x_, y_+1 );
cout << ch_;
for (i=0; i < w_-2; i++) cout << ' ';
cout << ch_ << endl;
gotoxy( x_, y_+2 );
for (i=0; i < w_; i++) cout << ch_;
cout << endl;
}
private:
char ch_;
};

class Label : public Gadget
{
public:
Label() : Gadget('@') { }
};

class Edit : public Gadget
{
public:
Edit() : Gadget('#') { }
};
class Factory
{
private:
static Gadget* array[2];
public:
static Gadget* getFlyweight(char* str)
{
if(strcmp(str,"label")==0)
{
if(array[0]==NULL) array[0]=new Label();
return array[0];
}
else if(strcmp(str,"edit")==0)
{
if(array[1]==NULL) array[1]=new Edit();
return array[1];
}
else return NULL;
}
};

int main( void ) {
Gadget* list[6];
list[0] = Factory::getFlyweight( "label" );
system("PAUSE");

}
...全文
109 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
cunsh 2005-12-12
  • 打赏
  • 举报
回复
楼主真义气呀.
newzai 2005-12-12
  • 打赏
  • 举报
回复
static Gadget* array[2];
没有初始化。
chunhai12 2005-12-12
  • 打赏
  • 举报
回复
Factory里的array没有初始化
cunsh 2005-12-12
  • 打赏
  • 举报
回复
把那句加在main()前面呀.你没有定义这个呀;
cunsh 2005-12-12
  • 打赏
  • 举报
回复
Gadget* Factory::array[2];
Viali 2005-12-12
  • 打赏
  • 举报
回复
晕死啊....拿回去编译一下看看错误在哪里???其实就是在Factory类里头的静态函数....但是偶不知道哪里出错了...
TonnyQ 2005-12-12
  • 打赏
  • 举报
回复
不好意思,实在看不懂。

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧