473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

std::endl type unknown

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
2 2234
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Michael Mellor | last post by:
I see so many posts on this newsgroup where people use std::endl but I can't see why or where they are getting it from. std::endl outputs a new line and flushes the stream's buffer. It is even 15.7...
12
by: Filipe Sousa | last post by:
Hi! Could someone explain to me why this operation is not what I was expecting? int main() { int x = 2; std::cout << x << " " << x++ << std::endl; return 0; }
3
by: silverburgh.meryl | last post by:
I have this linker error, and I would need some help in resolving it: I have put "#include <iostream>" in my .cpp. I am not sure why I can't link. It compiles fine. /usr/bin/ld:...
0
by: Dilip | last post by:
I am not sure if this is a VC++/ATL related problem or with the way std::endl works, so I have cross-posted this to 2 newsgroups. Please trim appropriately if you feel this is OT for c.l.c++ I...
9
by: Xian | last post by:
Is there a right and proper (tm) way to end a line? Thinking about portability and the mess that the 'wrong' line endings can cause. E.g. std::cout << "Hello World!\n"; or std::cout << "Hello...
9
by: andrew.smith.cpp | last post by:
hi, whts the difference between the std::endl or "\n" ? because both do the same work Thanks
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.