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:
Code:
CString(const CString& pString);
CString(const char* pString = "");
CString(int pInteger);
CString(float pFloat);
CString(double pDouble);
The first is a copy constructor, the second (default) is for copying a c-string into
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:
Code:
//Constructors
CBuffer();
CBuffer(const CBuffer& pBuffer);
CBuffer(const CString& pString);
//Template constructor
template <class T> CBuffer(const T& pData);
The first is a default constructor, the second is a copy constructor, the third is for
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:
Code:
CBuffer& operator=(const CBuffer& pData);
Now i want to know how come when i do this:
Code:
CBuffer myBuff;
myBuff = "Hello";
It converts the const char* to a CString() (using the CString(const char*) constructor) than calls
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:
Code:
CBuffer myBuff;
myBuff = 1234;
It does NOT convert the integer into a CString() than convert the CString() into a CBuffer() than
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?