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. 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.
Thank you all in advance and have a nice day!
CodePudding user response:
You have to also specify the type when initializing the static data member lcd
as shown below. Use
LiquidCrystal MainMenuDriver::lcd = LiquidCrystal(8, 9, 4, 5, 6, 7);