I am new to CPP programming and I am trying to create a class vmConsole that has another class vmColor embedded into it. I understand that because my console class "has a" color, I need to program my class like this. Once I have resolved this I wish to add another class vmCursor as a console program "has a" cursor. Here is the cut down version to show the issue:
The compiler errors:Code:#include <iostream> #include <windows.h> #define BLACK 0 #define WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE #define RED FOREGROUND_RED #define GREEN FOREGROUND_GREEN #define BLUE FOREGROUND_BLUE #define YELLOW FOREGROUND_RED | FOREGROUND_GREEN #define CYAN FOREGROUND_GREEN | FOREGROUND_BLUE #define MAGENTA FOREGROUND_BLUE | FOREGROUND_RED class vmColor { public: vmColor(int fg = WHITE, int bg = BLACK); void SetColor(int fg, int bg = BLACK); private: int m_nForegroundColor; int m_nBackgroundColor; }; class vmConsole { public: void SetColor(int fg, int bg = BLACK) { cColor.SetColor(int fg, int bg); } // Error is here ? private: vmColor cColor; }; vmColor::vmColor(int fg, int bg) { SetColor(fg, bg); } void vmColor::SetColor(int ForgC, int BackC) { WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor | FOREGROUND_INTENSITY); m_nForegroundColor = ForgC; m_nBackgroundColor = BackC; return; } int main() { vmConsole cHcsConsole; cHcsConsole.SetColor(RED); std::cout << "Hello there!" << std::endl; system("Pause"); return 0; }
Code:D:/Programming/Test/consoleTest.cpp: In member function `void vmConsole::SetColor(int, int)': D:/Programming/Test/consoleTest.cpp:28: error: expected primary-expression before "int" D:/Programming/Test/consoleTest.cpp:28: error: expected primary-expression before "int" Execution terminated Compilation Failed. Make returned 1




Reply With Quote