I have this code:
class A
{
public:
A(int _a, int _b = 0) : a(_a), b(_b) {}
void f(){}
#if _b == 0
void g(){}
#endif
private:
int a;
int b;
};
int main()
{
A x(1);
x.g();
return 0;
}
I want A to have the method g() only if b is 0. I know the code above doesn’t work, but I want to know if there is some way of achieving this.
You should use a template and provide the number of dimensions as a template argument (compile time constant). Then use specialization to provide the different interfaces: