| 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.
.
|
|
|
|
|

|
Related Articles |
|
|