c-style arrays are not copyable like that, if you want to
copy one, you have to copy the content instead:
int arr1[10] = {1,2,3,4,5,6,7,8,9,10};
int arr2[10];
std::copy(arr1, arr1+10, arr2);
// std::copy() lives in <algorithm>
// content of arr2 is a now copy of arr1
However, low-level features like c-style arrays, are best avoided.
If what you really wanted was a variable length string, use std::string
instead, it supports copying via assignment operator.
If you really wanted a fixed length array, use std::array<T,N>
instead,
it also supports copying via assignment operator.
Also note, a recommendation is that parameter names and member variable names are distinct, except for constructors where you use the member initialization syntax:
#include <string>
class UCSDStudent
{
std::string name;
public:
UCSDStudent( std::string name )
: name(name)
{
}
void SetName( std::string new_name )
{
name = new_name;
}
};
Also note, if you planning on having setters and getters for all member
variables, may I recommend public data instead, at least if the class
does not have an class-invariant.
std::string name;
andthis->name = name;
. – Valericstd::array
. It supports assignment, among other things.std::string
is what you should use here, though. – Valeric