I
ishekara
Hi,
I am having a class template which is used to convert from one type another.
I am having a problem when i use the copy constructor with same type.
code.
#include "stdio.h"
template <class T>
class SPtr
{
public:
// Default constructor
SPtr() : mSptr(NULL){}
// constructor to convert. takes a different type i.e. T2
template<class T2>
SPtr(T2& p){}
// copy constructor.
template<>
SPtr(const SPtr<T>& p) {}
private:
T* mSptr;
};
void main()
{
const SPtr<int> p1;
SPtr<int> p2(p1);
}
here the SPtr<int> p2(p1) gives me an "ambiguous call to overloaded
function" error.
but if i put a const in the template for SPtr(const T2&p), it reolves the
ambiguity,
template<class T2>
SPtr(const T2& p){} // this will correct the problem.
Could someone explain this behaviour?
TFH
shekar
I am having a class template which is used to convert from one type another.
I am having a problem when i use the copy constructor with same type.
code.
#include "stdio.h"
template <class T>
class SPtr
{
public:
// Default constructor
SPtr() : mSptr(NULL){}
// constructor to convert. takes a different type i.e. T2
template<class T2>
SPtr(T2& p){}
// copy constructor.
template<>
SPtr(const SPtr<T>& p) {}
private:
T* mSptr;
};
void main()
{
const SPtr<int> p1;
SPtr<int> p2(p1);
}
here the SPtr<int> p2(p1) gives me an "ambiguous call to overloaded
function" error.
but if i put a const in the template for SPtr(const T2&p), it reolves the
ambiguity,
template<class T2>
SPtr(const T2& p){} // this will correct the problem.
Could someone explain this behaviour?
TFH
shekar