Z
Zalek Bloom
Hello,
Created a simple class with following member functions:
class student
{
private:
char Name[20];
int studentID;
Curriculum Program;
public:
void setName(char fn[20]);
char* getName() ;
void setStudentID(int sID);
int getStudentID() const;
void setCurriculum(Curriculum c) ;
Curriculum getCurriculum() ;
};
void student::setName(char a[20])
{
strcpy(Name, a);
}
void student::setStudentID(int a)
{
studentID = a;
}
void student::setCurriculum(Curriculum a)
{
Program = a;
}
char* student::getName()
{
return Name;
}
int student::getStudentID() const
{
return studentID ;
}
Curriculum student::getCurriculum()
{
return Program ;
}
Curriculum is a class defined down the line.
"const" is working with getStudentID() function, but when I try add
"const" to getCurriculum() or getName() I am getting message:
C:\\MyProjects\Aug25\prog1.cpp(53) : error C2440: 'return' : cannot
convert from 'const char [20]' to 'char *'
Conversion loses qualifiers
Error executing cl.exe.
prog1.obj - 1 error(s), 0 warning(s)
Without "const" on getName() I am getting a clear compile.
Thanks,
Zalek
Created a simple class with following member functions:
class student
{
private:
char Name[20];
int studentID;
Curriculum Program;
public:
void setName(char fn[20]);
char* getName() ;
void setStudentID(int sID);
int getStudentID() const;
void setCurriculum(Curriculum c) ;
Curriculum getCurriculum() ;
};
void student::setName(char a[20])
{
strcpy(Name, a);
}
void student::setStudentID(int a)
{
studentID = a;
}
void student::setCurriculum(Curriculum a)
{
Program = a;
}
char* student::getName()
{
return Name;
}
int student::getStudentID() const
{
return studentID ;
}
Curriculum student::getCurriculum()
{
return Program ;
}
Curriculum is a class defined down the line.
"const" is working with getStudentID() function, but when I try add
"const" to getCurriculum() or getName() I am getting message:
C:\\MyProjects\Aug25\prog1.cpp(53) : error C2440: 'return' : cannot
convert from 'const char [20]' to 'char *'
Conversion loses qualifiers
Error executing cl.exe.
prog1.obj - 1 error(s), 0 warning(s)
Without "const" on getName() I am getting a clear compile.
Thanks,
Zalek