|
Thanks Sandip,
"In that case i think preference is given to overridden method." -- you mean when calling D.Display, there are two choices,
1. D::B::Display;
2. D::C::A::Display.
But since (1) is "more" overridden than (2), (1) is preferred, but if we derive Display in both B and C, D will have no choice and there will be ambiguity compile error?
regards,
George
|
|
|
|
|
George_George wrote: "In that case i think preference is given to overridden method." -- you mean when calling D.Display, there are two choices,
1. D::B::Display;
2. D::C::A::Display.
But since (1) is "more" overridden than (2), (1) is preferred,
Yes from the behavior it seems like that.
Even i did not come across any documents that states above behavior.
Regards,
Sandip.
|
|
|
|
|
Thanks Sandip,
Here is what I learned from you -- virtual inheritance solves both member method and member data issue -- so we can say virtual inheritance solves all diamond problem issues (both ambiguity member method and data member). Could you review and confirm my understanding now is correct please?
regards,
George
|
|
|
|
|
Yes unless there is no overriding of methods from the common ancestor as i said earlier.
Regards,
Sandip.
|
|
|
|
|
I agree, thanks Sandip!
regards,
George
|
|
|
|
|
I have some queries here..
1. By making the inheritance virtual how the ambiguity is actually resolved?
I mean, what this virtual inheritance does internally? Does it create another vptr of another vtable?
if it is so how does the new vtable looks like??
2. And as the diamond problem says that there is an ambiguity that whether D will have path
A->B->D
or
A->C->D
A
/ \
B C
\ /
D
So after removing ambiguity which path is taken?
|
|
|
|
|
Hi,
Is there any memory leak in the following code? I cannot see any one. But bound checker telling there is a leak? Please advice me. Thanks in advance.
class test<br />
{<br />
char* m_name;<br />
public:<br />
test():m_name(NULL)<br />
{}<br />
void Set(const char* name)<br />
{<br />
<br />
if(name!=NULL && strlen(name))<br />
{<br />
m_name = new char[strlen(name)+1];<br />
strcpy(m_name,name);<br />
}<br />
else<br />
delete [] m_name;<br />
}<br />
~test()<br />
{<br />
Set(NULL);<br />
}<br />
void display()<br />
{<br />
cout<<m_name<<endl;<br />
}<br />
};<br />
int main(int argc, char* argv[])<br />
{ test tst;<br />
tst.Set("123456");<br />
tst.display(); <br />
return 0;<br />
}<br />
|
|
|
|
|
SRKSHOME wrote: void Set(const char* name)
{
if(name!=NULL && strlen(name))
{
m_name = new char[strlen(name)+1];
strcpy(m_name,name);
}
else
delete [] m_name;
}
Assuming name is valid
On first call to Set method, m_name is NULL and you allocate memory to it.
On second call to Set method, m_name had valid allocated memory from first call. But prior to allocating new memory, the previous allocated memory is not deallocated
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Thanks for your reply. But if you look at the main function I have called set("123456"). I have never called set(..) for second time. Second time this functin is called from destructor and NULL is passed to Set(). Hence I cannot see memory leak here. Please correct me if I am wrong.
|
|
|
|
|
I see the above as obvious memory leak in code. Also Sarath (in the reply below) pointed to the same problem. Try fixing the problem and then see if there is still memory leak.
You may also want to re-think about how m_name is deallocated when object lifetime ends.
modified 21-Apr-21 21:01pm.
|
|
|
|
|
The program will be having memory leak, if you call set twice. You can rewrite the code better.
class test
{
char* m_name;
public:
test():m_name(NULL)
{}
void Set(const char* name)
{
if( name == NULL || 0 == strlen(name))
return;
if( m_name )
delete []m_name;
m_name = new char[strlen(name)+1];
strcpy(m_name,name);
}
~test()
{
if( m_name )
delete [] m_name;
}
void display()
{
cout<<m_name<<endl;
}
};
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Thanks for your better code reply.
|
|
|
|
|
Hi All
I have a problem to copy .exe file.I am useing
GetLastError()
then found error no.32 and 3.
error No. 3 show
The system cannot find the path specified.
And Error no. 32 show
The process cannot access the file because it is being used by another process.
Code is
void On_FileAdded(const CString & strFileName)
{
USES_CONVERSION;
CString CStrfilename=strFileName;
char* charfilename;
charfilename=CStrfilename.GetBuffer();
LPCTSTR lp;
lp=CStrfilename;
PathSkipRoot(lp);
CString cs = "C:\\Backup\\";
cs += PathSkipRoot(lp);
CString st;
if ( CopyFile(strFileName, cs, TRUE) != TRUE)
{
DWORD dwError = GetLastError();
CString szMsg;
szMsg.Format("Error number %d", dwError);
AfxMessageBox(szMsg);
}
else
{
AfxMessageBox("Success");
}
CopyFile(strFileName, cs,TRUE);
}
Plz help me
|
|
|
|
|
vcprog wrote: if ( CopyFile(strFileName, cs, TRUE) != TRUE)
Did you check the contents of strFileName and cs when you use them in CopyFile.
vcprog wrote: else
{
AfxMessageBox("Success");
}
CopyFile(strFileName, cs,TRUE);
}
BTW why do you wan't to do CopyFile again?
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Thx's for reply
yes i check the contents of strFileName and cs both are right.
And when comment these line
CopyFile(strFileName, cs,TRUE);
then file is not not copy..
Plz help me
|
|
|
|
|
Did you try with SHFileOperation ?
|
|
|
|
|
No i have no idea about SHFileOperation..
Can you give me example..
Plz help me
|
|
|
|
|
ShFileOperation Demo[^]
The secret of life is not enjoyment
but education through experience.
- Swami Vivekananda.
|
|
|
|
|
Like this:
TCHAR m_Files[256];
sfo.wFunc = FO_COPY;
sfo.hwnd = NULL;
sfo.pFrom = m_Files;
sfo.pTo = "c:\\Pics";
sfo.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;
hr = SHFileOperation(&sfo);
|
|
|
|
|
vcprog wrote: The process cannot access the file because it is being used by another process.
Which part of this error message do you not understand?
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
yes you are right i am not understand where is error showing?Can you help me?
|
|
|
|
|
The error means that this particular file is being exclusively locked by another process. So, until that process would release this lock, you will not be able to copy this file. You may try copying some other file to verify this.
See if this[^] helps.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Sir it's not help me..Plz tell me how can i solve that problem..
Plz help me
|
|
|
|
|
|
There is no point in all that, because the problem is that the OP is trying to copy a file which is being exclusively locked by another process.
The problem is not in choosing the method to copy a file, but with copying the file itself, as it is locked.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|