I am trying to pass a pointer to a templated object to another class.
template <int size>
class A {
public:
int a[size] = {0};
int getA(int n) {
return a[n];
}
};
class B {
public:
A<>* b;
void setB(A<>* n) {
b = n;
}
};
int main()
{
const int size1 = 10;
A<size1> data1;
B b1;
b1.setB(&data1);
}
Which doesn't work.
As a solution, I can create the B class as a template class and create B object as B<A<size1>> b1; but this will create multiple objects if I multiply A<sizeX>, which I don't want since this code is for an embedded project which has finite resources.
All I want is to pass the pointer of data1 object to another class function and store it inside. The code I'm looking for is for C++03, I cannot use C++11 features such as shared pointers.
Is there a way to do this?
Appreciate any help,
class Ba template as well?std::any b;?A<N>types? What about registering pointers to base type?Ainherit from a base class, and then inByou store a pointer to that base class.