Click to See Complete Forum and Search --> : Return a char
Sophie
April 1st, 1999, 01:11 PM
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;
}
deep
April 1st, 1999, 01:22 PM
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
Santhosh Cheeran
April 1st, 1999, 01:28 PM
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.
April 1st, 1999, 01:57 PM
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
Santhosh Cheeran
April 1st, 1999, 02:29 PM
CString& VRLessonRecord::GetName()
{
return CString(Nom);
}
CString& VRLessonRecord::GetPath()
{
return CString(PathLecon);
}
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.