[英]This declaration has no storage class or type specifier when Initializing static member
this is my code.这是我的代码。
lib.hpp
库文件
class MainMenuDriver {
public:
static LiquidCrystal lcd;
static std::vector<std::string> menu_items;
static std::stack<std::string> menu_stack;
static std::stack<std::string> temp_stack;
// ...
main.cpp
主程序
#include "lib.hpp"
MainMenuDriver::lcd = LiquidCrystal(8, 9, 4, 5, 6, 7); // Error
// ...
Assume LiquidCrystal
actually exists, as you can see here, I want to seperate the Blueprint and Operation into two different parts.假设
LiquidCrystal
确实存在,正如您在此处看到的,我想将蓝图和操作分成两个不同的部分。 I already know you can initialize lcd
in MainMenuDriver
's constructor but I want to call this constructor in a static way, meaning i do not want to create an instance of MainMenuDriver.我已经知道你可以在
MainMenuDriver
的构造函数中初始化lcd
但我想以静态方式调用这个构造函数,这意味着我不想创建 MainMenuDriver 的实例。
Thank you all in advance and have a nice day!提前谢谢大家,祝你有美好的一天!
You have to also specify the type when initializing the static data member lcd
as shown below.您还必须在初始化静态数据成员
lcd
时指定类型,如下所示。 Use用
LiquidCrystal MainMenuDriver::lcd = LiquidCrystal(8, 9, 4, 5, 6, 7);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.