G
garfunkelorama
Hi all,
I'm sure there is a simple solution to this but it's beyond me. Please
can someone help?
You have a class like this:
class A
{
public:
template<typename T>
void f(key &k, T& t)
{
// need to store the address of t
}
void g(key &k)
{
// somehow get the address of the t variable above from the
supplied key
}
};
and then usage could be:
A a;
string str = "hello";
double d = 3.2;
int i = 2;
a.f(1, str);
a.f (2, d);
a.f(3, i);
//....
a.g(); //do something to alter values of str, d, i
How can you store the variable t but make it accessible to the rest of
the class ? You cannot have any variable in the class mention T as
it's not a template class. No void ptr if possible as that has its
associated headaches.
The boost "variant" library looks helpful but still i can't see how.
Other than resort to scrapping the template and just have regular int,
double and string pointers within A.
Thank you.
G.
I'm sure there is a simple solution to this but it's beyond me. Please
can someone help?
You have a class like this:
class A
{
public:
template<typename T>
void f(key &k, T& t)
{
// need to store the address of t
}
void g(key &k)
{
// somehow get the address of the t variable above from the
supplied key
}
};
and then usage could be:
A a;
string str = "hello";
double d = 3.2;
int i = 2;
a.f(1, str);
a.f (2, d);
a.f(3, i);
//....
a.g(); //do something to alter values of str, d, i
How can you store the variable t but make it accessible to the rest of
the class ? You cannot have any variable in the class mention T as
it's not a template class. No void ptr if possible as that has its
associated headaches.
The boost "variant" library looks helpful but still i can't see how.
Other than resort to scrapping the template and just have regular int,
double and string pointers within A.
Thank you.
G.