Static class?
May 20, 2014 at 4:00pm UTC
Can I add 'static' before 'class' instead of adding it before each function to make them all static in this?
1 2 3 4 5 6
class Render {
void DrawPlayground();
void DrawBalls();
public :
void DrawAll();
};
May 20, 2014 at 4:05pm UTC
Short answer, no.
Long answer, possibly.
Last edited on May 20, 2014 at 4:06pm UTC
May 20, 2014 at 4:31pm UTC
Use a namespace.
Header file (.h)
1 2 3
namespace Render {
void DrawAll();
};
Implementation file (.cpp)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// #include header file
namespace Render {
namespace {
void DrawPlayground() { /* ... */ }
void DrawBalls() { /* ... */ }
// variables
}
void DrawAll()
{
// ...
DrawPlayground() ;
// ...
DrawBalls() ;
// ...
}
};
May 20, 2014 at 5:27pm UTC
If all methods are static then you should ask yourself why they are in a class. The only thing a class gives in this case is the scoping rules which JLBorges pointed out can be done with a namespace also.
Topic archived. No new replies allowed.