0

C++: What are the differences between using "const" or not?

I learnt from this app that "const" is to make constant numbers or strings or something else. But when I was doing some practice on operator overloading on my own, some errors occurred if I didn't use "const" with parameters in the operator overloading function. (Sorry for poor english) #include <iostream> #include <string> class sample { int data; std::string word; public: sample(){} sample(int a, const char b[]):data(++a),word(b){} sample operator+(sample& s) { sample d; d.word = this->word + s.word; return d; } }; int main() { sample me(1, "I am learning C++"); } In the above case, (In line 9 of the code) if I use "char b[]" instead of "const char b[]", some errors occurred. Why?

25th Nov 2019, 1:04 PM
æ±éąšç•™ć
æ±éąšç•™ć - avatar
4 RĂ©ponses
+ 3
Oh....thx~
25th Nov 2019, 2:00 PM
æ±éąšç•™ć
æ±éąšç•™ć - avatar
+ 1
so const* char represent a string type?đŸ€”
25th Nov 2019, 1:17 PM
æ±éąšç•™ć
æ±éąšç•™ć - avatar