By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 985 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

COM and Polymorphism

P: 36
From what I've read, it isn't possible to have true polymorphism (well... function overloading...) using COM functions. I wanted to double check here to find out if there is a hack/work-around/bit-of-magic that can be done to mimic function overloading.

If not, then I will just have to use different function names.
Aug 7 '07 #1
Share this Question
Share on Google+
8 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Yes. When you implement a COM interface, you are implementing a set of pure virtual functions. Check your IDL. There you see the word interface which is a #define of a struct.

The only (gag) problem is that you need to typecast your object to the interface type by using IUnknown::QueryInterface.

All polymorphism requires is substitution of a specific object for a general object. It does not specify the rules for the substitution. Maybe it's a typecast. Maybe a duck. Maybe a Lishkov substitution.
Aug 8 '07 #2

P: 36
Yes. When you implement a COM interface, you are implementing a set of pure virtual functions. Check your IDL. There you see the word interface which is a #define of a struct.

The only (gag) problem is that you need to typecast your object to the interface type by using IUnknown::QueryInterface.

All polymorphism requires is substitution of a specific object for a general object. It does not specify the rules for the substitution. Maybe it's a typecast. Maybe a duck. Maybe a Lishkov substitution.

Ahhh yes... Interesting question... (Have you seen the movie IQ?)
Aug 8 '07 #3

Expert 10K+
P: 11,448
Ahhh yes... Interesting question... (Have you seen the movie IQ?)
The reply wasn't silly at all: design a bare bones DAO (Data Access Object) that
handles your COM object directly. Implement wrapper classes around that DAO
class that implement all the method overloading you want/need.

kind regards,

Jos
Aug 8 '07 #4

P: 36
The reply wasn't silly at all: design a bare bones DAO (Data Access Object) that
handles your COM object directly. Implement wrapper classes around that DAO
class that implement all the method overloading you want/need.

kind regards,

Jos
In the movie IQ, a smart but uneducated guy tries to pass himself off (with the help of Albert Einstein) as a super genius physicist to a very smart physicist girl. The guy asks Albert what to say if she asks him a question he can't answer. The response was something to the effect of "Just look thoughful and say, "Hmmm Interesting question." I didn't understand what he was trying to say. (Happens to me WAY to often...) So I put that silly reply in there while I thought about what he was saying.

The solution that you mentioned will work I think. And it also solves one or two other problems I was preparing to tackle with this project.

Thanks for the help.

- Matt
Aug 9 '07 #5

weaknessforcats
Expert Mod 5K+
P: 9,197
So I put that silly reply in there while I thought about what he was saying.
I have done the same thing myself. Usually in a classroom where my example won't compile and I can't see the error. So I ask the class: "Can anyone tell me what the compiler is saying??". I can ask several students all the while I am racking my brain for an answer. By the time the class runs out of ideas, I have found the problem.

So, was Einstein really smart or did he just pose interesting questions?
Aug 9 '07 #6

Expert 10K+
P: 11,448
So, was Einstein really smart or did he just pose interesting questions?
He was really smart; I mean he attended every single Saturday night party at
'good time Johny's' (John von Neumann) place and never got thrown out ;-)

kind regards,

Jos
Aug 9 '07 #7

weaknessforcats
Expert Mod 5K+
P: 9,197
never got thrown out ;-)
So you are saying he was un-exceptional.
Aug 10 '07 #8

Expert 10K+
P: 11,448
So you are saying he was un-exceptional.
Read "who took Einstein's place" for all the gory details ;-)

kind regards,

Jos
Aug 10 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.