首页| 论坛| 消息

标题:问一个比较幼稚的问题
作者:crespo102418
日期:2007-02-06 21:09
内容:

我定义了一个class Video,由于其他的一些因素,我只能在main函数中Video *video=new Video;现在我想在其他的函数中使用*video,我该怎么办?谢谢大家帮帮我!


#1 [浪漫天使 02-06 21:29]
大概的思路吧
extern Video *video;
int main(int argc,char *argv[])
{
…………
Video *viewo = new Video;
…………
}
或者 把 *viewo 定义成全局变量,反正就那个意思吧。
#2 [crespo102418 02-07 16:44]
不行啊,还是说子函数的video没有定义
#3 [浪漫天使 02-08 00:36]
qt422,g++,windows 编译通过,只是涉及到编译,功能方面的问题没有测试,因为只想表达一个思路。vedio.h #include class VideoWgt : public QWidget{public:VideoWgt(QWidget *parent = 0):QWidget(parent){;}~VideoWgt(){;} };another.h class Another {public:Another(){;}~Another(){;}public:void func();};another.cpp#include "another.h"#include "vedio.h"extern VideoWgt *dlg; void Another::func(){dlg->setWindowTitle("hah");}main.cpp #include "vedio.h"#include VideoWgt *dlg; int main(int argc, char *argv[]){ QApplication app(argc,argv); dlg = new VideoWgt(); dlg->show();app.connect(&app,SIGNAL(lastWindowClosed()),&app,SLOT(quit())); return app.exec();}附件上传不了…………
#4 [myer 02-12 07:17]
extern当然可以,但是不太好维护
你可以将Video *指针作为需要它的类的构造函数的一个参数,当然也可以实现一个setVideo(Video *)函数。

回复 发表
主题 版块