I want the class member can be changed depending on the template args. I want something like follow
template<int value>
class MyClass
{
public:
void print()
{
// using the member
std::cout << sizeData() << std::endl;
for (int i=0;i<sizeData();i++)
{
std:cout << data[i] << std::endl;
}
}
static int sizeData()
{
#if value == 1
return 3;
#endif
#if value == 2
return 6;
#endif
}
static int sizeArray()
{
#if value == 1
return 40;
#endif
#if value == 2
return 200;
#endif
}
private:
#if value == 1
int data[3];
const static int array[40];
#endif
#if value == 2
int data[6];
const static int array[200];
#endif
}
I do not know can it be implemented in c++.
Thanks for your time.
add
Many sir already give the answer in C++11 and C++17. Thanks all your's advises.
If the code can be settled in C++98, it will be perfect. Because my code should run on a platform which only support C++98.