casting Class<typename> to Class<const typename>
hello i am having the follow problem.
Code:
template<typename T>
struct A
{
private:
T* t;
};
template<typename T>
struct B
{
inline A<T>& GetA()
{
return a;
}
inline A<const T>& GetA() const // <<<<<<<<
{
return a; // <<<<<<<<<<
}
private:
A<T> a;
};
the problem is obviously that there is no cunstructor in A<const T> to accept A<T>.
i have been brain cracking how to to create the constructor solution.
I was thinking i might as well make a public instead of private.
Any help please?
Re: casting Class<typename> to Class<const typename>
Is this what you are looking for?
Code:
inline const A1<T>& GetA() const // <<<<<<<<
{
return a; // <<<<<<<<<<
}
Re: casting Class<typename> to Class<const typename>
no im talking about constructing a A<const T> from A<T>,.
where did u get the "A1" class from.. there isnt any in my code..
Re: casting Class<typename> to Class<const typename>
I don't think you can.
You can get a const A<T> from an A<T>, but not a A<const T> from a A<T>
That's just the way templates are.
However....
What you could do is provide a way to cast a T to a const T to construct a new A<const T> using a T, but not a A<T>.