I'm sure this was answered somewhere on the site but can not find it... I'm writing under VS10 in C++. I'm writing a class that holds details of a student. One of the members is
string studentName[30];
There should be a function that returns this string on request, this could be done using traditional C strings and a pointer however I would like to use C++ strings.
My get function looks like so:
string Student::getName()
{
return studentName;
}
On compile, I get this error from VS10:
Error 1 error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 1 from 'std::string [30]' to 'const std::basic_string<_Elem,_Traits,_Ax> &' f:\c++\hw1\hw1\hw3\hw3.cpp 56 1 HW3
I'm not sure what this means. If anyone can clarify I would be thankful. Also, in these get functions is it common to return a reference for the string or actual literal values (hope this is the correct lingo).
StudentName declared as such:
protected:
string studentName[30];
int studentGrades[8];
int studentAge;
};
string studentName[30];
is an array of thirty strings - is that really what you wanted? – RichieHindlestudentName
is defined to be not a string, but an array of 30 strings. You cannot pass an array of strings as a string. – ach