Depending on compiler, C-style string literals may be allocated in readonly memory. Thus they are const char[N+1]
(N
is the string length) (which is implicitly convertible to const char*
because of array to pointer decay).
The problem you're having is that it's illegal to drop const
qualifiers (with the exception of the infamous const_cast
or equivalent C-style cast).
Since you're only reading from sir
, you can fix this by making sir
be const char*
instead, which doesn't violate const
:
class student {
...
student(int = 8, const char* =" "); // problem solved
...
};
student::student(int nr_marks, const char* sir) : // remember to change it here as well
marks(nr_marks)
{
strcpy(name, sir);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…