这是我的代码的骨架 -
class FLTK_win; //class declaration before full definition so it can be used in the other class
//first of the classes
class functions {
public:
void example_function();
.....
};
void example_function() {
std::string input = FLTK_win::Textbox->value();
/*so here I want to make a string that takes the value of whatever the user has
entered in the text box in the FLTK window class*/
........
}
//second class which is a friend of the first
class FLTK_win : public Fl_Window {
friend class functions;
Fl_Input* Textbox;
......//and the rest of the stuff to open the FLTK window when an instance of the class is created
};
从这一行:
std::string input = FLTK_win::Textbox->value();
我收到错误:
"incomplete type 'FLTK_win' used in nested name specifier"
我想知道我的班级是否按错了顺序?但是,我不知道这会给出这个错误。
否则必须有一种不同的(正确的)方法来调用另一个类中的FLTK文本框的值而不是" FLTK_win :: Textbox-> value()" ?
我尝试在'函数中创建一个名为 testwin 的FLTK_win实例。上课然后写作:
testwin.Textbox->value();
但是我认为这不起作用,因为文本框的值不是变量,因此不能以这种方式调用。我也研究过getters&塞特犬,但他们不了解他们,知道他们是不是答案。
提前感谢您的帮助!
答案 0 :(得分:0)
如果您想访问文本框,最简单的方法是将定义放在函数之前。
class FLTK_win: public Fl_window
{
...
Fl_Input* Textbox;
...
};
然后声明你的类的实例
FLTK_win* awin;
在你的函数中,你现在可以使用它,因为编译器现在知道awin是什么以及它的成员函数/变量是什么。
std::string input = awin->Textbox->value();
最后,在主程序中,您需要创建实例
int main()
{
awin = new FLTK_win();
...
}