Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Color.h
- class Color {
- protected:
- int id;
- Color(int id) : id(id) {}
- void operator&(); //undefined
- public:
- Color(const Color& r) : id(r.id) {}
- Color& operator=(const Color& r) {id=r.id; return *this;}
- bool operator==(const Color& r) const {return id==r.id;}
- bool operator!=(const Color& r) const {return id!=r.id;}
- operator int() const {return id;} //so you can still switch on it
- static Color Blue;
- static Color Red;
- };
- // Color.cpp
- #include "Color.h"
- Color Color::Blue(0);
- Color Color::Red(1);
- // main.cpp
- #include "Test.h"
- using namespace std;
- const Color mainColors[] = {Color::Red, Color::Red }; // values should be [1, 1]
- int main()
- {
- cout << "Main file-scoped colors: " << mainColors[0] << ", " << mainColors[1] << endl; // prints [1, 1]
- Test();
- return 0;
- }
- // Test.h
- #include "Color.h"
- void Test();
- // Test.cpp
- #include "Test.h"
- const Color fooColors[] = {Color::Red, Color::Red}; // values should be [1, 1]
- void Test()
- {
- cout << "Test file-scoped colors: " << fooColors[0] << ", " << fooColors[1] << endl; // prints [0, 0]
- }
- static Color Blue();
- static Color Red();
- Color Color::Blue() {return Color(0);}
- Color Color::Red() {return Color(1);}
- const Color mainColors[] = {Color::Blue(), Color::Red() };
- const Color fooColors[] = {Color::Blue(), Color::Red()};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement