std::endl type unknown

X

Xav

#include <iostream>

using namespace std;

class CLog
{
public:
template<typename paramT>
CLog& operator<<(const paramT& param)
{
return *this;
};
};

int main()
{
CLog Log;

Log << endl; // no match for `CLog& << <unknown type>' operator
}

Why is endl type unknown ?
How can i do this ?
 
A

Andrey Tarasevich

Xav said:
#include <iostream>

using namespace std;

class CLog
{
public:
template<typename paramT>
CLog& operator<<(const paramT& param)
{
return *this;
};
};

int main()
{
CLog Log;

Log << endl; // no match for `CLog& << <unknown type>' operator
}

Why is endl type unknown ?
How can i do this ?
...

'std::endl' is a function template. It doesn't have a type until it is
specialized. You method is also template and its only parameter also
doesn't have a type until it is specialized. The compiler cannot perform
the specialization in this situation because it has nothing to start
from. You have to specialize at least one of these templates explicitly.
For example

Log << endl<char, char_traits<char> >;
 
A

Alf P. Steinbach

'std::endl' is a function template. It doesn't have a type until it is
specialized. You method is also template and its only parameter also
doesn't have a type until it is specialized. The compiler cannot perform
the specialization in this situation because it has nothing to start
from. You have to specialize at least one of these templates explicitly.
For example

Log << endl<char, char_traits<char> >;

I'll just add to that,


CLog& operator<<( std::eek:stream& (*f)(std::eek:stream&) )
{
return *this;
}


as the definition of "<<", instead of a template, would also do the trick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top