Apr 5, 2015 at 3:34pm UTC
What is wrong at line 29 ? I can't see the problem :(. Half an year has passed since I worked the last time with C++, so it might be something really dumb.
I know that the program will print nothing, but I only want to know where is the problem.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include <iostream>
#include <set>
#include <string>
using namespace std;
class macl{
public :
macl();
macl(char );
string print();
private :
char c;
};
macl::macl() : c('X' ){}
macl::macl(char c) : c(c){}
string macl::print(){
return "meh " +c+'/n' ;
}
int main(){
set<macl> ms{'a' ,'e' ,'n' ,'p' ,macl()};
for (set<macl>::iterator i=ms.begin();i!=ms.end();i++){
(*i).print();
}
//plus endl
cin.sync();
cin.ignore();
return 0;
}
Last edited on Apr 5, 2015 at 3:35pm UTC
Apr 5, 2015 at 3:42pm UTC
line 29 seems fine but:
return "meh " +c+'/n' ;
you can't add const char*'s together like that.
anyway, what does the compiler say?
maybe try: i->print
instead of *i.print
?
Last edited on Apr 5, 2015 at 3:42pm UTC
Apr 5, 2015 at 3:56pm UTC
tried all variants, still the same error :/
Apr 5, 2015 at 4:02pm UTC
Ok, but where's a const object in my code ?
Apr 5, 2015 at 4:04pm UTC
Guessing the "i" is const.
Read what the error is saying -
Error 1 error C2662: 'std::string macl::print(void)' : cannot convert 'this' pointer from 'const macl' to 'macl &
Last edited on Apr 5, 2015 at 4:06pm UTC
Apr 5, 2015 at 4:06pm UTC
well it isn't const iterator... strange