Doubt about const in constructor char*


1)
 
	Cadena(char* c) : cad(c){}


2)
 
	Cadena(const char* c) : cad(c){}


2) isn't possible, but why? in 1) you haven't "warranty" of not to modify the char* c parameter. is this supposition ok? Thanks a lot

PD:

if you need here you have the complete code:

1
2
3
4
5
6
class Cadena {
public:
	Cadena(char* c) : cad(c){}
private:
	char* cad;
};



Last edited on
You can't assign a const char* to a char*. It you could the char* could modify the const char*.
Topic archived. No new replies allowed.