This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/15339] New: function call error


//*******mytest.hpp******* 
#ifndef MYTEST_H 
#define MYTEST_H 
#include <iostream> 
#include <string> 
template<typename T>    //declaration 
void fun(T val, const std::string seperator); //error, change to 
                                         //seperator = " " , then it works well

template<typename T>    //definition 
void fun(T val, const std::string seperator = " ") 
{ 
    std::cout<<val<<seperator<<std::endl; 
} 
#endif 

//***********test.cpp********* 
#include "mytest.hpp" 
int main() 
{ 
   fun(10); 
}

g++ test.cpp -o test
and reads "test.cpp:4:error: no matching function for call to `fun(int)'".
I think the function should be resolved from its definition not its 
declaration the first one it encountered. It means that although no default 
argument is provided in function declaration, as long as it has one default in 
the definition, it should also work well.

-- 
           Summary: function call error
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: MichaelLi8195 at hotmail dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15339


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]