Question

Setting: On Qt Creator, I call this function. I have imported all sstream, string, etc. all of it is in the same class and is defined well in the header file:

std::string int2str(int x) {
    std::stringstream ss;
    ss << x;
    return ss.str();
}

and inside a for loop:

for (int i = 0; i < 10; i++) {
    std::string s = int2str(i); // error lies on this line
    // a line of Qt code
}

I get the error "Invalid conversion from int to const char* [-fpermissive]". Which is weird, because isn't that exactly what this function is supposed to be doing?

EDIT: Didn't know how to use Qt Creator to get more details...Sorry everyone.

Error:

Initializing argument 1 of 'std::basic_string<_CharT, _Traits,_Alloc>::basic_string(const_charT*, const_Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' [-fpermissive] @ basic_string.tcc line 214 (/usr/include/c++/4.6/bits/basic_string.tcc)

EDIT2:: Dumb mistakes, one of which includes, speaking of namespaces. never specifying where int2str was; used myClass:: in front of it and now it's all good - as everyone thought.

Was it helpful?

Solution

False information was given; header function was not defined properly since the function returned an int instead of a std::string. Additionally namespaces: did not have myClass:: in front of the function int2str in its implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top