c++ - Way around "first defined here" error? -
c++ - Way around "first defined here" error? -
i need have 2 alternate classes same name, can switch between each other changing class included in main.
for example;
mode_1.h
class draw{ private: // private stuff public: void render(int x, char y); }; mode_2.h
class draw{ private: // private stuff public: void render(int x, char y); }; main.cpp
#include "mode_1.h" int main(){ draw d; int x = 2; char y = 'x'; d.render(x, y); } currently i'm having comment out .h , .cpp files i'm not using avoid "first defined here" error. want have switch between them change
#include "mode_1.h" to
#include "mode_2.h"
you should set them in different namespaces:
namespace mode2 { class draw{ private: // private stuff public: draw(int x, char y); }; } in main can select namespace want use:
#include "mode_1.h" #include "mode_2.h" using namespace mode2; int main() { draw d; int x = 2; char y = 'x'; d.draw(x, y); homecoming 0; } c++
Comments
Post a Comment