By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

std::endl type unknown

P: n/a
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 ?

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Xav wrote:
#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> >;

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #2

P: n/a
On Fri, 12 Dec 2003 13:48:57 -0800, Andrey Tarasevich <an**************@hotmail.com> wrote:
Xav wrote:
#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> >;


I'll just add to that,
CLog& operator<<( std::ostream& (*f)(std::ostream&) )
{
return *this;
}
as the definition of "<<", instead of a template, would also do the trick.

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.