What's wrong ?

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
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
tried all variants, still the same error :/
Googled around, your problem can be summed up with

You cannot call a non-const method with a const object.
Ok, but where's a const object in my code ?
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
well it isn't const iterator... strange
Topic archived. No new replies allowed.