if condition for class constructor

I'm trying to have a class constructor in an if condition but the compiler dos not accept that. here is the code,

1
2
3
4
5
6
7
8
LattModel::LattModel()
	:VelocitySet(
		{ 4.0 / 9.0, 1.0 / 9.0, 1.0 / 9.0, 1.0 / 9.0 , 1.0 / 9.0, 1.0 / 36.0, 1.0 / 36.0, 1.0 / 36.0, 1.0 / 36.0 },
		{ {0, 0}, {1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, 1}, {-1, 1}, {-1, -1}, {1, -1} },
		1.0 / 3.0
	)
{
}


I already defined following part in the code.
1
2
3
4
5
6
7
8
9
10
#define Dimension2

#ifdef Dimension2
constexpr int _dim{ 2 };
constexpr int _nLattdir{ 9 };
#else
constexpr int _dim{ 3 };
constexpr int _nLattdir{ 27 };

#endif  


now I want the code to construct
1
2
3
4
5
6
7
8
LattModel::LattModel()
	:VelocitySet(
		{ 4.0 / 9.0, 1.0 / 9.0, 1.0 / 9.0, 1.0 / 9.0 , 1.0 / 9.0, 1.0 / 36.0, 1.0 / 36.0, 1.0 / 36.0, 1.0 / 36.0 },
		{ {0, 0}, {1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, 1}, {-1, 1}, {-1, -1}, {1, -1} },
		1.0 / 3.0
	)
{
}


if _dir==2 and if _dir==3 use another constructor definition. is it possible to do that?

here is the definition of VelocitySet,
1
2
3
4
VelocitySet::VelocitySet(std::vector<double> weights, std::vector<std::vector<int>> directions, double cSquare)
	: m_weights(weights), m_directions(directions), m_cSquare(cSquare), m_nrOfDimensions(directions[0].size())
{
}
Last edited on
1
2
3
4
5
#ifdef Dimension2
// Put constructor definition for 2 dimensions here ...
#else
// Put constructor definition for 3 dimensions here ...
#endif   
Ops,you're right. I should've used macro instead of if condition.Thank you.
Last edited on
Topic archived. No new replies allowed.