【发布时间】:2021-12-18 10:51:28
【问题描述】:
这是我的代码。
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
// ...
假设LiquidCrystal 确实存在,正如您在此处看到的,我想将蓝图和操作分成两个不同的部分。我已经知道你可以在MainMenuDriver 的构造函数中初始化lcd,但是我想以静态方式调用这个构造函数,这意味着我不想创建 MainMenuDriver 的实例。
提前谢谢大家,祝大家有个愉快的一天!
【问题讨论】:
标签: c++ oop constructor static