Click here to Skip to main content
15,890,336 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
I did notice that. Which is why (when I compiled your code), I tried sticking TestString in the ATL namespace (same as CStringT). And it didn't work - but I'm starting to think I got the wrong namespace - I've tried some more experiments that confuse things a little, and seem to indicate that there is at least one bug associated with name lookup in VC.

I wrote this code:

namespace Test
{
   class A
   {
   public:
      friend void TestFn(const A&) { }
   };
   class B
   {
   public:
      operator A(){ return A(); }
   };
}


class C
{
public:
   operator Test::A(){ return Test::A(); }
};

using namespace Test;

void X()
{
   A a;
   B b;
   C c;
   
   TestFn(a);    // Should be OK
   TestFn((A)b); // Should be OK, as explicitly calling out A as parameter type
   TestFn((A)c); // Should be OK, as explicitly calling out A as parameter type
   TestFn(b);    // Should fail to compile - although in same namespace, friends at class scope are invisible outside the class.
   TestFn(c);    // Should fail to compile - different namespace, ADL won't be used.
}


You can see what I *thought* should happen in the comments. However, VC++ compiles the second last line (TestFn(b);) instead of raising an error. gcc, on the other hand, conforms exactly to my reading of the standard, compiling the first three function calls but not the last two.

Oh - and the error that VC++ raises for the line TestFn(c);? It's this:

error C3767: 'TestFn': candidate function(s) not accessible
        could be the friend function at 'd.cpp(6)' : 'TestFn'  [may be found via argument-dependent lookup]


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

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 
AnswerRe: Opp Concept Pin
Adam Roderick J20-Jul-09 23:50
Adam Roderick J20-Jul-09 23:50 
AnswerRe: Opp Concept Pin
Stuart Dootson20-Jul-09 23:54
professionalStuart Dootson20-Jul-09 23:54 
Questionrunning exe without having Visual studio installed Pin
MahaKh20-Jul-09 23:22
MahaKh20-Jul-09 23:22 
AnswerRe: running exe without having Visual studio installed Pin
_AnsHUMAN_ 20-Jul-09 23:29
_AnsHUMAN_ 20-Jul-09 23:29 
GeneralRe: running exe without having Visual studio installed Pin
MahaKh20-Jul-09 23:39
MahaKh20-Jul-09 23:39 
GeneralRe: running exe without having Visual studio installed Pin
_AnsHUMAN_ 20-Jul-09 23:44
_AnsHUMAN_ 20-Jul-09 23:44 
GeneralRe: running exe without having Visual studio installed Pin
MahaKh20-Jul-09 23:46
MahaKh20-Jul-09 23:46 
GeneralRe: running exe without having Visual studio installed Pin
Randor 21-Jul-09 1:38
professional Randor 21-Jul-09 1:38 
AnswerRe: running exe without having Visual studio installed Pin
Stuart Dootson20-Jul-09 23:50
professionalStuart Dootson20-Jul-09 23:50 
AnswerRe: running exe without having Visual studio installed Pin
Randor 21-Jul-09 0:36
professional Randor 21-Jul-09 0:36 

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.