C++:如何将 FLTK 文本框的值存储在另一个类的变量中
C++: How to store the value of an FLTK textbox in a variable within another class
这是我的代码框架 -
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和setters,但对它们的了解还不够,不知道它们是否是答案。
提前感谢您的帮助!
如果要访问文本框,最简单的方法是将定义放在函数之前。
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();
...
}
相关文章:
- 存储变量的更有效方法是什么?
- 使用 system() 不存储变量C++?
- 在递归DP中,通过存储变量来分解递归调用:效率低下
- 使用 LDAP 存储C++变量
- 在满足特定条件时运行迭代C++以存储变量
- 使用getline解析和存储变量
- 如何存储变量的地址并使用指针打印值
- C++ / Objective-C++ - 如何在 NSDictionary 中存储C++变量?
- 如何从文件中读取并存储变量
- 指针是否延长了自动存储变量的生存期
- 如何在 INI、CFG 或 XML 文件中存储C++变量
- 如何在 c++ 中的字符串数组中存储变量
- 如何在特定偏移量处存储变量
- 如何存储变量的前一个值并更新它以进行比较
- 存储变量的有效方法是什么?(自制虚拟机)
- 在C++中存储变量
- 在c++中按值调用时,存储变量的副本
- 为什么lambda只捕获自动存储变量
- 如何在寄存器中存储c++变量
- Getline()结合cin.ignore()不存储变量?(错误)