Is there any way to use a template parameter as a variable?
for example if I have a function
template<int dim>
void DomainGrid<dim>::getData(Data data_, int field_dim)
{
int size_ = field_dim *dim; // Compiler Error Here
for(int i =0; i<size_; ++i)
std::cout<<data_[i]<<std::endl;
}
Can I get a similar functionality? Compiling this function produces an error at
invalid use of member (did you forget the ‘&’ ?)
the error appears regardless of whether the function is called or not
Which I guess is because of this problem…
Rename either the template parameter or the member function?
That seems like the simplest, most straightforward solution. Whenever multiple symbols have the same name, you risk name clashes. So don’t use the same name for multiple symbols in such cases.
(This is assuming you have a member function
dim(). I assume so based on the error message, but it might have been useful information to actually include in the question.)