Any Bug?

D

david0002004

Here is the code:

template <class T>
inline std::string To_String (const T& t)
{
std::stringstream ss;
ss << t;
return ss.str();
}

When I uses this function to convert an int to string, I got a core
dump. But I couldn't see anything wrong in the function. Thanks for
your help.
 
V

Victor Bazarov

Here is the code:

template <class T>
inline std::string To_String (const T& t)
{
std::stringstream ss;
ss << t;
return ss.str();
}

When I uses this function to convert an int to string, I got a core
dump. But I couldn't see anything wrong in the function. Thanks for
your help.

Are you sure this is your actual code? I could think it might core-dump
if you attempted to return a reference.

V
 
J

Jeff Flinn

Victor said:
Are you sure this is your actual code? I could think it might core-dump
if you attempted to return a reference.

Or T is a UDT with something wrong in it's implementation of operator<<...

Jeff
 
M

Marcel Müller

Here is the code:

template <class T>
inline std::string To_String (const T& t)
{
std::stringstream ss;
ss << t;
return ss.str();
}

When I uses this function to convert an int to string, I got a core
dump.

This code will not core dump, surely! It is never executed.
It will not even compile because of the missing includes.
But I couldn't see anything wrong in the function.

Maybe. But this says nothing about the invisible rest of your code.

Most probably you passed a dangling reference to To_String.


Marcel
 

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

Forum statistics

Threads
474,158
Messages
2,570,882
Members
47,414
Latest member
djangoframe

Latest Threads

Top