-
Return a char
Hi here is my problem.
class VRLessonRecord
{
private:
char Nom[ 64]; Has to be char.
char PathLecon[ 64];
public:
CString GetPath();
CString GetName();
};
CString VRLessonRecord::GetName()
{
return Nom; //error how do I return a char pointer?
}
CString VRLessonRecord::GetPath()
{
return PathLecon;
}
-
Re: Return a char
If You are not using functionality of CString in the program , It is better to declare return type of GetPath() and GetName() as char*.
Then it won't give error "Can not convert from char* to CString&"
---Deep
-
Re: Return a char
Sophie,
Are you serious, if you're. First of all you cant return those member variables of the class. Although 'nom' is a pointer,all arrays are also pointers and will be released when class is destructed, so if you really want to send it back, you have to make sure, the class will be alive long enough and that you won't access the returnvalue after the parent class is dead. Then protype is char* not CString. It can be LPSTR also, but if you have to pass a pointer back, allocate that pointer using new
char* m_Nom;
char* m_PathLecon[ 64];
in the constructor
m_Nom = new char[ 64];
m_PathLecon = new char[ 64];
The thing is , you have to allocate of the heap with new, not use the data segment allocation. Ok ???
Else use CString m_strNom and use GetBuffer() & GetLength(), copy using strcpy the CString to the buffer and pass it back.
-
Re: Return a char
void CVRUtilitiesApp::RecalcLessonRawList()
{
//lessonRawList.clear();
CString lessonBasePath = iniInfo.GetLessonBasePath();
File f;
f.Open(O_RDONLY);
VRLessonRecord lr;
while(lr.Read){
CString name = lr.GetName();
CString path = lr.GetPath();
}
}
class VRLessonRecord
{
private:
char Nom[ 64];
char PathLecon[ 64];
};
CString VRLessonRecord::GetName()
{
return Nom;
}
CString VRLessonRecord::GetPath()
{
return PathLecon;
}
Not sure I Understand the "If don't use CString functionailty in program?"
Could you show me what you mean with the code I gave you? I think I am using CString functionality
-
Re: Return a char
CString& VRLessonRecord::GetName()
{
return CString(Nom);
}
CString& VRLessonRecord::GetPath()
{
return CString(PathLecon);
}