std::endl type unknown



 DEVELOP > c-Plus-Plus > std::endl type unknown

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Xav"
Date: 12 Dec 2003 03:26:37 PM
Object: std::endl type unknown
#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 ?
.

User: "Andrey Tarasevich"

Title: Re: std::endl type unknown 12 Dec 2003 03:48:57 PM
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
.
User: "Alf P. Steinbach"

Title: Re: std::endl type unknown 12 Dec 2003 03:54:30 PM
On Fri, 12 Dec 2003 13:48:57 -0800, Andrey Tarasevich <andreytarasevich@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.
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER