|
I don't really understand why you are creating a MFC application if you don't want to use MFC ?
|
|
|
|
|
Hi Cedric,
sorry if there are confusions there, what i mean is i am creating a atl/wtl application not MFC.
Thanks
|
|
|
|
|
Are you building MFC application?
If you go to your project properties under Configuration Properties | General, there is a setting whether to use MFC and/or to use ATL.
If your project is not a MFC application, you should set the Use of MFC to Use Standard Windows Libraries
Cheers
|
|
|
|
|
Hi Ryu,
Its set to use Standard Windows Libraries i cannot use MFC i must only use standard windows libraries, atl and wtl.
Thanks
|
|
|
|
|
Thanks for the Information.
|
|
|
|
|
Hello everyone,
When debugging the following code in VS 2008. I think the vtable of object instance z should contain 2 sub-vtables for IFoo and IGoo, the sub-vtable for IFoo should contain func/foo and the sub-vtable for IGoo should contain func/goo), but why actually it only contains 2 sub-vtable, and each of them has only one function item func?
class IBase
{
public:
virtual void func() = 0;
};
class IFoo : IBase
{
public:
virtual void foo() { cout << "IFoo : IBase" << endl; }
};
class IGoo : IBase
{
public:
virtual void goo() { cout << "IGoo : IBase" << endl; }
};
class Zoo : IFoo, IGoo
{
public:
virtual void func() {cout << "Zoo : IBase" << endl; }
};
int main()
{
Zoo z;
return 0;
}
thanks in advance,
George
|
|
|
|
|
You didn't specialize those functions in the Zoo class. vtable are used to redirect a function call to the function of the child class which specialize this function. Here, there's no need to redirect the function call because neither of the child classes specialize the function.
I guess this is the reason (it's only a guess) why it doesn't appear in the table. Remember that the table is filled by the child classes when they are being constructed. So, if the child class doesn't specialize the function, there's no need to add it to the vtable.
|
|
|
|
|
Hi Cedric,
1.
I am confused about your term of "specialize this function". Do you mean overriding?
2.
"vtable are used to redirect a function call to the function of the child class" -- I disagree vtable is used for redirecting to child class, but I think it is used for find the actual function to call through run time type identification. We may call the function is current class if we have overriden function in current class, and we may call function in based class if we have not overridden the function in current class.
But I think whether or not we override, all visible virtual functions (including inherited ones) should be in vtable. Any comments or ideas?
regards,
George
|
|
|
|
|
George_George wrote: I am confused about your term of "specialize this function". Do you mean overriding?
Yes, sorry, I was typing too fast
George_George wrote: "vtable are used to redirect a function call to the function of the child class" -- I disagree vtable is used for redirecting to child class, but I think it is used for find the actual function to call through run time type identification. We may call the function is current class if we have overriden function in current class, and we may call function in based class if we have not overridden the function in current class.
Yes of course, if the child class doesn't override the function, then the function of the base class will be called. I think we are saying the same thing here
George_George wrote: But I think whether or not we override, all visible virtual functions (including inherited ones) should be in vtable
As far as I know, the C++ spec doesn't say anything about how vtables should be implemented. It only specifies how virtual functions should behave, and the implementation is left to the compiler. In this case, the compiler might be smart enough to produce code that will not add this function to the vtable because it is never overriden. In this case, there's a performance hit if you add this function in the vtable because there's no need to redirect the call. So, in each case, the same function should be called (the one from the base class).
|
|
|
|
|
Thanks Cédric!
I have modified the code to make foo and goo overridden in class Zoo, but foo and goo are still not in vtable. Any ideas?
Here is my updated code.
class IBase
{
public:
virtual void func() = 0;
};
class IFoo : IBase
{
public:
virtual void foo() { cout << "IFoo : IBase" << endl; }
};
class IGoo : IBase
{
public:
virtual void goo() { cout << "IGoo : IBase" << endl; }
};
class Zoo : IFoo, IGoo
{
public:
virtual void foo() { cout << "Zoo : IBase" << endl; }
virtual void goo() { cout << "Zoo : IBase" << endl; }
virtual void func() {cout << "Zoo : IBase" << endl; }
};
int main()
{
Zoo z;
return 0;
}
regards,
George
|
|
|
|
|
|
Thanks CPallini,
Why virtual methods are not in the vtable? I think all virtual methods should be in vtable. What's wrong?
regards,
George
|
|
|
|
|
|
I am using VS 2008 under debug mode. Could you try my code in VS and check whether you could reproduce this issue? CPallini?
regards,
George
|
|
|
|
|
|
It is ok, CPallini. I just want to know your option about whether do you think foo and goo should be in vtable of Zoo?
regards,
George
|
|
|
|
|
I think they should. Anyway I have to admit my ignorance: I don't know what's happening (is it a debugger issue?)
I changed my mind about. See http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=2729211[^]
Sorry for the chaos.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Thursday, September 18, 2008 6:40 AM
|
|
|
|
|
Sure, let me know when you have any ideas why foo and goo are not in vtable of class Zoo.
regards,
George
|
|
|
|
|
Sorry for changing my mind several times this morning.
Anyway, now, I think I was right the very first time: the Zoo class actually does NOT override foo & goo , hence such methods should not be inits VTABLE .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi CPallini,
I have tried even if we override foo and goo in class Zoo, in vtable of class Zoo, there is still no entries for foo/goo.
regards,
George
|
|
|
|
|
CPallini wrote: Why should foo & goo be in the VTABLE (I mean, no class overrides them)?
Yes, the Zoo class overrides them.
|
|
|
|
|
Thanks Cedric,
Sorry my English is not good. You mean foo and goo should be in vtable?
regards,
George
|
|
|
|
|
No, I was only replying to CPallini, not to you.
|
|
|
|
|
Thanks Cedric!
My careless. I want to confirm with you in the code link I posed below, you think foo and goo should be in vtable, correct?
http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=2728926
regards,
George
|
|
|
|
|
I played a bit with your code and I think the problem is due to the "diamond pattern". I don't have a clear explanation of what is happening but if IFoo and IGoo inherits virtually from IBase, then the functions appear in the virtual table (in fact, looking with the debugger shows that a vtable has been added for IFoo and for IGoo).
|
|
|
|