Click here to Skip to main content
15,895,084 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionUse template with "Conversion Functions" get problem. [modified] Pin
hawkgao012921-Jul-09 0:28
hawkgao012921-Jul-09 0:28 
AnswerRe: Use template with "Conversion Functions" get problem. Pin
«_Superman_»21-Jul-09 0:36
professional«_Superman_»21-Jul-09 0:36 
GeneralRe: Use template with "Conversion Functions" get problem. Pin
hawkgao012921-Jul-09 0:52
hawkgao012921-Jul-09 0:52 
GeneralRe: Use template with "Conversion Functions" get problem. Pin
«_Superman_»21-Jul-09 0:59
professional«_Superman_»21-Jul-09 0:59 
GeneralRe: Use template with "Conversion Functions" get problem. Pin
hawkgao012921-Jul-09 1:10
hawkgao012921-Jul-09 1:10 
GeneralRe: Use template with "Conversion Functions" get problem. Pin
«_Superman_»21-Jul-09 1:20
professional«_Superman_»21-Jul-09 1:20 
GeneralRe: Use template with "Conversion Functions" get problem. Pin
hawkgao012921-Jul-09 3:13
hawkgao012921-Jul-09 3:13 
AnswerRe: Use template with "Conversion Functions" get problem. Pin
Stuart Dootson21-Jul-09 3:25
professionalStuart Dootson21-Jul-09 3:25 
This case is covered by section 14.6.5 of the C++ Standard. The CString operator+ is defined as a class-scope friend function of the underlying template class, CStringT. The rules of C++ mean that when compiling t1 + t2, those friend functions of CStringT are invisible.

hawkgao0129 wrote:
the following code is really compilable in VC++6.0


Which was really, really non-compliant with the standard...Them's the breaks!

The easiest solution is to add a suitable operator to your TestString class:

class TestString {
   CString m_str;
public:
   TestString(TCHAR* str):m_str(str) {}
   operator CString() const {return m_str;}
   <big>friend CString operator+(const TestString& t1, const TestString& t2) { return (CString)t1 + t2; }</big>
};


Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: Use template with "Conversion Functions" get problem. Pin
hawkgao012921-Jul-09 16:30
hawkgao012921-Jul-09 16:30 
GeneralRe: Use template with "Conversion Functions" get problem. Pin
Stuart Dootson21-Jul-09 16:44
professionalStuart Dootson21-Jul-09 16:44 
GeneralRe: Use template with "Conversion Functions" get problem. Pin
hawkgao012921-Jul-09 19:02
hawkgao012921-Jul-09 19:02 
GeneralRe: Use template with "Conversion Functions" get problem. Pin
Stuart Dootson21-Jul-09 19:53
professionalStuart Dootson21-Jul-09 19:53 
GeneralRe: Use template with "Conversion Functions" get problem. Pin
hawkgao012921-Jul-09 21:40
hawkgao012921-Jul-09 21:40 
GeneralRe: Use template with "Conversion Functions" get problem. Pin
Stuart Dootson21-Jul-09 22:27
professionalStuart Dootson21-Jul-09 22:27 
GeneralRe: Use template with "Conversion Functions" get problem. Pin
hawkgao012921-Jul-09 23:01
hawkgao012921-Jul-09 23:01 
GeneralRe: Use template with "Conversion Functions" get problem. Pin
Stuart Dootson21-Jul-09 23:13
professionalStuart Dootson21-Jul-09 23:13 
GeneralRe: Use template with "Conversion Functions" get problem. [modified] Pin
hawkgao012921-Jul-09 23:25
hawkgao012921-Jul-09 23:25 
GeneralRe: Use template with "Conversion Functions" get problem. Pin
Stuart Dootson22-Jul-09 0:11
professionalStuart Dootson22-Jul-09 0:11 
QuestionPosting too many messages Pin
Russell'21-Jul-09 0:13
Russell'21-Jul-09 0:13 
AnswerRe: Posting too many messages Pin
«_Superman_»21-Jul-09 0:23
professional«_Superman_»21-Jul-09 0:23 
QuestionDiable F12 in word using automation Pin
gadag21-Jul-09 0:12
gadag21-Jul-09 0:12 
QuestionOpp Concept Pin
zakkas248320-Jul-09 23:25
zakkas248320-Jul-09 23:25 
AnswerRe: Opp Concept Pin
_AnsHUMAN_ 20-Jul-09 23:31
_AnsHUMAN_ 20-Jul-09 23:31 
GeneralRe: Opp Concept Pin
zakkas248320-Jul-09 23:33
zakkas248320-Jul-09 23:33 
GeneralRe: Opp Concept Pin
_AnsHUMAN_ 20-Jul-09 23:49
_AnsHUMAN_ 20-Jul-09 23:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.