Qt c++ aggregate 'std::stringstream ss' has incomplete type and cannot be defined

tyty5949 picture tyty5949 · Aug 1, 2012 · Viewed 124.9k times · Source

I have this function in my program that converts integers to strings:

    QString Stats_Manager::convertInt(int num)
    {
        stringstream ss;
        ss << num;
        return ss.str();
    }

But when ever i run this i get the error:

aggregate 'std::stringstream ss' has incomplete type and cannot be defined

Im not really sure what that means. But if you know how to fix it or need any more code please just comment. Thanks.

Answer

Luchian Grigore picture Luchian Grigore · Aug 1, 2012

You probably have a forward declaration of the class, but haven't included the header:

#include <sstream>

//...
QString Stats_Manager::convertInt(int num)
{
    std::stringstream ss;   // <-- also note namespace qualification
    ss << num;
    return ss.str();
}