CPP rookie, compile hint according to the code typed in the book example:
"private: static int value::total_length" (?total_length@value@@0HA)
Project1 C:\Users\Kellen\source\repos\Project1\Project1\ex3_10.obj 1
the source code is as follows:
-sharpinclude <iostream>
-sharpinclude <string>
using namespace std;
class value {
static int total_length;
int length;
char *contents;
public:
value(const char *s) {
length = strlen(s);
contents = new char[length + 1];
strcpy(contents, s);
}
static int set_total_length(value &obj) {
total_length += obj.length;
return total_length;
}
~value() {
delete[]contents;
}
};
int main(void) {
value obj1("the first object");
cout << obj1.set_total_length(obj1) << endl;
value obj2("the second object");
cout << obj2.set_total_length(obj2) << endl;
}
Baidu is fruitless. I hope some friends can help me solve my problem, or tell me how it works. Thank you very much!