Ok, this is going to be a bit hard to explain.
I have two classes. Ones called CString and another is called CBuffer.
CString has 5 constructors:
The first is a copy constructor, the second (default) is for copying a c-string into
CString(const CString& pString);
CString(const char* pString = "");
the string class and the last 3 convert numbers to a c-string than copy them
into the string class.
The CBuffer class has 4 constructors:
The first is a default constructor, the second is a copy constructor, the third is for
CBuffer(const CBuffer& pBuffer);
CBuffer(const CString& pString);
template <class T> CBuffer(const T& pData);
copying a CString class and the fourth is a template constructor to copy simple data types
such as int, float, doubles, structures, etc.
CBuffer also has this:
Now i want to know how come when i do this:
CBuffer& operator=(const CBuffer& pData);
It converts the const char* to a CString() (using the CString(const char*) constructor) than calls
myBuff = "Hello";
the CBuffer(const CString& pString) constructor to convert it to a CBuffer() object, THAN
calls the "=" operator. WHICH IS WHAT I WANT.
BUT when i do this:
It does NOT convert the integer into a CString() than convert the CString() into a CBuffer() than
myBuff = 1234;
pass the CBuffer() to the '=" operator. Instead it calls "template <class T> CBuffer(const T& pData);"
and than passes the resulting CBuffer() into the "=" operator. WHICH IS WHAT I WANT.
So although im not having any troubles, i just want to know how it knows to convert "const char*" to a
CString() object but not an integer even though they both have constructors in the CString() object.
The compiler is mingw.
Hmm let me simplify it. How come CBuffer(32) calls the template constructor, while CBuffer("32") calls the
CBuffer(const CString& pString); constructor even though CString() has a constructor for both of these datatypes?