CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2002
    Location
    Moscow, Russia
    Posts
    97

    Difference in template resolving (MSVC, gcc)

    Hi again!

    This is the simple sample of code:

    Code:
    //...
    
    template<class T, T t_inst>
    void dosmth(T& ret){
    	ret = t_inst;
    }
    
    void dosmth(int& ret){
    	ret = 5;
    }
    
    int main(int argc, char* argv[])
    {
    	int toret;
    	dosmth(toret);
    
    	return 0;
    }
    By design, void dosmth(int&) should be used. It's really so - in gcc. But Visual C++ refuses to compile this code, saying: error C2783: 'void __cdecl dosmth(T &)' : could not deduce template argument for 't_inst'.

    Why VC doesn't use non-template function? And how this behaviour can be overriden?

    Regards!

  2. #2
    Join Date
    Jun 2002
    Posts
    224
    As far as I know there is no way to change vc++’s behavior. It simply does not implement the whole standard. Your code works on Borland’s 5.5 and Comeau's 4.3.

    Regards,
    Last edited by zdf; November 4th, 2002 at 07:27 AM.
    ZDF

    What is good is twice as good if it's simple.
    "Make it simple" is a complex task.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured