single character to String conversion

string exp; //expression getline(cin,exp); stack<int> vs; //value stack (postfix evaluation) stack<string> infix; //infix stack (postfix conversion) stack<string> prefix; //prefix stack (postfix conversion) for(int i=0;i<exp.length();i++){ char ch = exp[i]; if(isdigit(ch)){ vs.push(ch – ‘0’); infix.push(string(1,ch)); prefix.push(string(1,ch)); } } Here I have used string(1,ch) inbuilt constructor to convert single character to a String. But I wanna know, is… Read More single character to String conversion

Is there a speed problem when using pragma pack?

struct window_data { window_props win_props; bool VSync; Window::event_callback_fn EventCallback; }; I have this struct in my program. sizeof(window_data) equals 120. #pragma pack(push, 2) struct window_data { window_props win_props; bool VSync; Window::event_callback_fn EventCallback; }; #pragma pack(pop) If i use #pragma pack(push, 2), sizeof(window_data) equals 114. #pragma pack(push, 1) struct window_data { window_props win_props; bool VSync; Window::event_callback_fn… Read More Is there a speed problem when using pragma pack?

Do I need a virtual destructor for a second interface class?

I’ve got classes called "Base" and "Derived". struct Base { Base() = default; virtual ~Base() = default; Base(const Base&) = delete; Base& operator=(const Base&) = delete; virtual void DoStuff() = 0; }; The "Base" class needs virtual destructor and it’s understandable. Also I don’t allow copying of this class struct Derived : Base { Derived()… Read More Do I need a virtual destructor for a second interface class?

How to pass a reference to an object to another class

I’m trying to pass a reference to an object from my main.cpp to menux.cpp however I’m getting this error: error: conflicting declaration ‘MenuX alpha4’ MenuX(alpha4); main.cpp #include "MenuX.h" Adafruit_AlphaNum4 alpha4 = Adafruit_AlphaNum4(); MenuX(alpha4); MenuX.h #ifndef MENUX_H #define MENUX_H #include "Adafruit_LEDBackpack.h" #include <Adafruit_GFX.h> // Core graphics library class MenuX { public: MenuX(Adafruit_AlphaNum4 *alpha4); void addX(); private:… Read More How to pass a reference to an object to another class