|
To expand on what I said earlier, the problem will typically show when the memory manager checks the borders of yout allocation, so if your code would look like:
CMyclass * pCMyclass = new CMyclass ();
...
delete pCMyclass;
then the problem would occur when executing the delete statement, although the error could be anywhere in the CMyclass object.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Please tell me how function call is resolve, how vptr works in this case CODE:
class base
{
public:
virtual void f1()
{
cout<<"base f1";
}
virtual void f2()
{
cout<<"base f2";
}
};
class d1: public base
{
public:
virtual void f1()
{
cout<<"d1's f1";
}
virtual void f2()
{
cout<<"d1's f2";
}
};
class d2: virtual public base,virtual public d1
{
public:
d2()
{
cout<<"d2 class construxtor\n";
}
~d2()
{
cout<<" d2 class destructor\n";
}
};
void main()
{
clrscr();
base* obj= new d2;
obj->f1();
obj->f2();
}
modified on Sunday, July 12, 2009 2:46 PM
|
|
|
|
|
vptrs don't come into it - you have no virtual functions, so therefore there will be no vtable.
If the compiler was able to construct your base pointer obj (it can't because it inherits from base twice - which one should it upcast through?), there would be no runtime resolution of f1 and f2 ; they're non-virtual functions, so they will be resolved using the static type of obj , i.e. base . That means that the program (if it could compile) would output base f1base f2
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Actually the code will (and does) compile. Note that base is inherited virtually (note the use of virtual public base in the declaration of class d2 ). This ensures that only one version of the base class will be included in d2
However, you are completely correct in that there is no vtable, and the output wil be base f1base f2 .
Graham
Librarians rule, Ook!
|
|
|
|
|
Better tell that to gcc, then - it gives this warning and error:
a.cpp:30: warning: direct base ‘base’ inaccessible in ‘d2’ due to ambiguity
a.cpp: In function ‘int main()’:
a.cpp:46: error: ‘base’ is an ambiguous base of ‘d2’
VC++ 2008 agrees
a.cpp(30) : error C2584: 'd2' : direct base 'base' is inaccessible; already a base of 'd1'
a.cpp(5) : see declaration of 'base'
a.cpp(16) : see declaration of 'd1'
The virtual qualifier needs to be applied to all inheritance instances of the shared base, so you need this code for it to compile (note virtual wherever 'base' is inherited):
class base
{
public:
void f1()
{
cout<<"base f1";
}
void f2()
{
cout<<"base f2";
}
};
class d1: virtual public base
{
public:
void f1()
{
cout<<"d1's f1";
}
void f2()
{
cout<<"d1's f2";
}
};
class d2: virtual public base, public d1
{
public:
d2()
{
cout<<"d2 class construxtor\n";
}
~d2()
{
cout<<" d2 class destructor\n";
}
};
int main()
{
base* obj= new d2;
obj->f1();
obj->f2();
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
OK, you caught me.
That'll learn me not to trust VS2005
Graham
Librarians rule, Ook!
|
|
|
|
|
Graham Shanks wrote: VS2005
That compiled in VS2005? I guess I can understand why, I think. Maybe.
Also yet another example why it's good to keep clear of tricksy inheritance features in C++. a) the programmer isn't 100% sure what should happen (I'm definitely including myself in that group), and b) neither's the compiler.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: That compiled in VS2005?
No. Doesn't compile in VS 2005, 2008 or VC++ 6.0.
|
|
|
|
|
The code doesn't compile with VC++ 6.0, VS 2005 and VS 2008.
(clrscr() is also undeclared in Visual C++; I vaguely recall it being in Turbo C. Perhaps he has an early version of Turbo C++ and it's not showing this as an error.)
|
|
|
|
|
all right I got it...but if I am making f1() and f2() virtual in base class and d1 class, how vptr will work?
|
|
|
|
|
As base is declared virtual, there is one instance of base in d2. This means (IIUC) that the functions in d1 will hide the functions in base from the point-of-view of d2 because d1 is more derived than base.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
For the working of vptr, allow me to redirect you to one of my articles Polymorphism in C[^]
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
How to capture the currently playing song using visual c++?
|
|
|
|
|
just can't understand how to make it.especially how to get the pathname of the document using begindrag message.
|
|
|
|
|
Have a look at this article[^]. The list control needs to be a drop target. Look at the OnDragOver and OnDrop handlers - they mention a data object (of type COleDatObject). That object will contain data of a number of formats. I'd suggest you implement the drop target thing and then experiment with dropping explorer files onto the list control and see what data formats the data object contains, to see which is the format you want to access. CFSTR_SHELLIDLIST is probably a good one - it returns an array of PIDLISTs, one for each explorer item. You can get paths from that using SHGetPathFromIDList[^]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
WOW!!sound so difficult!!~~
i didn't find it in mfc class wizard messages
that's too professional to me,thanks anyway
|
|
|
|
|
It's very easy in .NET if you get the chance to use that. The .NET controls have drag/drop related methods that wrap the ones I was talking about and provide simpler access to the underlying data object. I was able to create a list-control that could accept Explorer style data in about 20 minutes.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I really must apologise - I completely missed the easy way of doing file drag-drop when I answered you. All you need to do is this:
- Call the
CWnd::DragAcceptFiles method for your top-level window (e.g. I called it for a dialog window in the dialog's OnInitDialog) - Override and implement the window's
CWnd::OnDropFiles method - here's some code I've knocked together that demonstrates how it works:
void CMyDlg::OnDropFiles(HDROP hDropInfo)
{
const UINT nFiles = DragQueryFile(hDropInfo, (UINT)-1, 0, 0);
std::vector<CString> files;
for(UINT i=0;i<nFiles;++i)
{
CString thisFile;
const UINT nChars = DragQueryFile(hDropInfo, i, thisFile.GetBufferSetLength(MAX_PATH), MAX_PATH);
files.push_back(thisFile);
}
CDialog::OnDropFiles(hDropInfo);
}
Again - sorry for giving you misleading advise earlier!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi,
i know that name of the parent of exe files in windows, is explorer.exe.
explorer.exe there is in list of windows running processes in Windows task manager.
can it is this exe (explorer) there is whit other name in Windows task manager list?
Zo.Naderi-Iran
|
|
|
|
|
zon_cpp wrote: i know that name of the parent of exe files in windows, is explorer.exe.
I'm presuming you're saying that the parent process of processes you (the user) run in explorer.exe. Mostly true. but explorer.exe may be parent of the parent, or parent of the parent of the parent.
Unfortunately, I'm not quite sure what the rest of your question is answering. But I'll suggest you download and run Process Explorer[^] - it can show the hierarchy of processes
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
in any windows, can this exe (explorer.exe) be with other name, in Windows task manager list?
Zo.Naderi-Iran
|
|
|
|
|
Do you mean 'can you change the shell to something other than explorer' (the answer's yes[^]) or 'does explorer change its name' (I think the answer's pretty much no)
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello!
i'm making a mini-game by MFC
i want to make a class to ctrl some bitmaps,
i've written some menber founctions like this:
.................
in the constructor:
{
bitmap.loadbitmap...
xxx=0...//a bool to make sure CreateCompatibleDC(pDC) will only run once time.
}
setDC(CDC pdc);
{
if(xxx==0)
{
mDC.CreateCompatibleDC(pdc);// mDC used to store the picture
xxx=1
}
mDC.SelectObject(&bitmap[i]);
PDC=pdc;// PDC to store the target CDC
}
draw()//draw the picture
{
PDC->BitBlt(0,0,600,450,&mDC,0,0,SRCCOPY);
}
...........
but there's a problem:
when i use this class as a menber of CView; everything's OK ;
but when i use this class as menber of class X,and make X a menber of CView;
while using the founction setDC ;the mistake appears! a messagebox of"A\Retry\Ignore" comes out!!!
why things can be like this??
how should i write this class?
i just call setDC in founction"OnDraw".
modified on Sunday, July 12, 2009 4:12 AM
|
|
|
|
|
Please post relevant code where you're calling setDC.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
i just call setDC in founction"OnDraw".
|
|
|
|