P
paidojoao-groups
Given this code:
#include <iostream>
#include <string>
class timestamp
{
public:
timestamp() {
std::cout << "--> default constructor" << std::endl;
}
template <class charT, class traits>
friend
std::basic_ostream<charT, traits>&
operator<< (std::basic_ostream<charT, traits>& strm, const timestamp& ts);
private:
// implementation not relevant
};
template<class charT, class traits>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& strm, const timestamp& ts)
{
using namespace std;
strm << "--> operator<<()";
return strm;
}
int main()
{
timestamp p;
std::cout << p << std::endl; // line 36
return 0;
}
-------------------------------------------
VC 7.1 (13.10.3077) complains with
bug.cpp(36) : error C2563: mismatch in formal parameter list
bug.cpp(36) : error C2568: '<<' : unable to resolve function overload
Borland C++ 5.6.4 and G++ 3.2 compile without errors.
Who is wrong and who is right?
Changing to
friend
std:stream&
operator<< (std:stream& strm, const timestamp& ts);
and the compiler stops complaining.
Josue Gomes
josuegomes at yahoo dot com
#include <iostream>
#include <string>
class timestamp
{
public:
timestamp() {
std::cout << "--> default constructor" << std::endl;
}
template <class charT, class traits>
friend
std::basic_ostream<charT, traits>&
operator<< (std::basic_ostream<charT, traits>& strm, const timestamp& ts);
private:
// implementation not relevant
};
template<class charT, class traits>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& strm, const timestamp& ts)
{
using namespace std;
strm << "--> operator<<()";
return strm;
}
int main()
{
timestamp p;
std::cout << p << std::endl; // line 36
return 0;
}
-------------------------------------------
VC 7.1 (13.10.3077) complains with
bug.cpp(36) : error C2563: mismatch in formal parameter list
bug.cpp(36) : error C2568: '<<' : unable to resolve function overload
Borland C++ 5.6.4 and G++ 3.2 compile without errors.
Who is wrong and who is right?
Changing to
friend
std:stream&
operator<< (std:stream& strm, const timestamp& ts);
and the compiler stops complaining.
Josue Gomes
josuegomes at yahoo dot com