Don't no whether to laugh

O

Old Wolf

Catalin Pitis said:
I don't think they referred to polymorphism from the OOP point of view. I
think that they meant that a type can have different meanings, depending on
how it is used. For example, WORD can be used as an integer value or as a
reference to an object.

What amuses me is that DWORD means a single word and QWORD
means a double word, on most Windows systems.
 
J

Julie

Old said:
What amuses me is that DWORD means a single word and QWORD
means a double word, on most Windows systems.

Yes, an inaccurate hold-over from the earlier Wintel days when the CPU
architecture was 16-bit word.
 
C

Catalin Pitis

Vyacheslav Kononenko said:
Does C++ guarantee that long can be casted to a pointer? Will you assume
that long will keep a pointer? Was long designed to hold pointer type? So
does long satisfy this condition?

C++ doesn't guaratee this. However, on Windows (we are talking about WinAPI)
you can do this.

Catalin
 
C

Chris Theis

Vyacheslav Kononenko said:
Does C++ guarantee that long can be casted to a pointer?
[SNIP]

Hmm, I don´t think that the language guarantees this, aat least I haven´t
yet stumbled over an explicit statement regarding this issue. However, you
know that you can swing C-style casts like a hammer ;-) and this approach is
commonly used and works if you´re for example accessing objects via pointers
from the VBScript engine.

Chris
 
V

Vyacheslav Kononenko

Chris said:
chris wrote:



Does C++ guarantee that long can be casted to a pointer?

[SNIP]

Hmm, I don´t think that the language guarantees this, aat least I haven´t
yet stumbled over an explicit statement regarding this issue. However, you
know that you can swing C-style casts like a hammer ;-) and this approach is
commonly used and works if you´re for example accessing objects via pointers
from the VBScript engine.

Chris
OK looks like your previous definition does not work for LPARAM then. So
can you make an example on non polymorphic data type? Or clearly specify
how can we separate where is polymorphic data type and where is not?
 
H

Howard

Vyacheslav Kononenko said:
OK looks like your previous definition does not work for LPARAM then. So
can you make an example on non polymorphic data type? Or clearly specify
how can we separate where is polymorphic data type and where is not?

Given the ability to cast, there really is no difference. It's mainly one
of intention. Those parameter (and return) types were *intended* to be
cast to other types, as a kind of "generic" place-holder for information.
The only thing that really makes them "polymorphic" is how they're used,
nothing inherent in the types themselves.

So, I guess the answer to both your questions is "no". :)

-Howard
 
R

Richard Herring

Catalin Pitis said:
C++ doesn't guaratee this. However, on Windows (we are talking about WinAPI)
you can do this.
The standard (5.2.10) _does_ guarantee that you can reinterpret_cast a
pointer to an integral type and back again without changing its value,
provided that the integral type is large enough to hold it.
 
C

Chris Theis

Vyacheslav Kononenko said:
OK looks like your previous definition does not work for LPARAM then. So
can you make an example on non polymorphic data type? Or clearly specify
how can we separate where is polymorphic data type and where is not?

Howard was faster in his response and there is not much to add. In principle
they´re used as placeholders which you´ll see very often in windows
programming. For example you cast pointers to arbitrary objects to DWORD*
and attach them to listbox items. However, this is far from the standard and
very MS specific.

HTH
Chris
 
V

Vyacheslav Kononenko

Chris said:
Howard was faster in his response and there is not much to add. In principle
they´re used as placeholders which you´ll see very often in windows
programming. For example you cast pointers to arbitrary objects to DWORD*
and attach them to listbox items. However, this is far from the standard and
very MS specific.

HTH
Chris
So can we rephrase your: "A polymorphic data type is (I would say, and
first few links on google agree) is a data type which can be store more
than one kind of type. WPARAM, LPARAM, LRESULT and void* all seem to
satisfy this requirement." to "In their definition MS developers mean a
polymorphic data type as data type which is intended to be cast to other
types (properly or not which is another big question)" ?
 
C

Chris Theis

Vyacheslav Kononenko said:
So can we rephrase your: "A polymorphic data type is (I would say, and
first few links on google agree) is a data type which can be store more
than one kind of type. WPARAM, LPARAM, LRESULT and void* all seem to
satisfy this requirement." to "In their definition MS developers mean a
polymorphic data type as data type which is intended to be cast to other
types (properly or not which is another big question)" ?

Well, I´m sorry to tell you that you cannot rephrase my "A polymorphic data
type...." because it´s not my statement. If you read the name of the poster
carefully it says "chris" but not "Chris Theis" ;-)

However, what it boils down to is yes - polymorphic data type is a data type
which can be transformed to any distinct type as required. It´s created by
the use of a generic pointer (e.g., void*) which simply points to an address
without an associated type.

Cheers
Chris
 
V

Vyacheslav Kononenko

Chris said:
Well, I´m sorry to tell you that you cannot rephrase my "A polymorphic data
type...." because it´s not my statement. If you read the name of the poster
carefully it says "chris" but not "Chris Theis" ;-)
Oh I am sorry, I've completely lost.
However, what it boils down to is yes - polymorphic data type is a data type
which can be transformed to any distinct type as required. It´s created by
the use of a generic pointer (e.g., void*) which simply points to an address
without an associated type.

OK looks like we started again. Any data type is polymorphic in such
definition, isn't it? For example we can use "char" as an offset to a
object of some type in the array. Any data type is a number by nature
and what that number means only determined by how we use it. So I don't
see the way you can make a definition of polymorphic data type by what
it can hold. It can hold a set of bits and nothing more.
 
C

Chris Theis

Vyacheslav Kononenko said:
Oh I am sorry, I've completely lost.

OK looks like we started again. Any data type is polymorphic in such
definition, isn't it? For example we can use "char" as an offset to a
object of some type in the array. Any data type is a number by nature
and what that number means only determined by how we use it. So I don't
see the way you can make a definition of polymorphic data type by what
it can hold. It can hold a set of bits and nothing more.

In principle you already phrased what I meant: "In their definition MS
developers mean a
polymorphic data type as data type which is intended to be cast to other
types (properly or not which is another big question)" ?

You can use a reinterpret_cast to cast a pointer to an integral type and
back again, without changing the value of the pointee. The only requirement
is that the integral type is large enough. This is something which is
commonly done under Windows. For example think of the following situation,
which is not OS specific. You´re implementing a listbox and want to provide
a mechanism that the users can attach whatever objects they have created to
an item in the listbox. However, you do not know anything about the objects
because they have not been implemented at the time you´re writing your GUI.
So what you need is a generic pointer (which equals a polymorphic data
type). This is exactly what is done with the MFC listbox classes where the
user can attach his objects by casting them to DWORD pointers. Consequently
the polymorphic data type is not a data type in the common sense like
int/double/etc, but rather a generic pointer which can be used to store
pointers to objects of whatever types you like. Naturally, you´ll loose the
original type information by the cast & have to recast correctly before
accessing the pointee.

Cheers
Chris
 
I

Ioannis Vranos

Vyacheslav said:
OK looks like we started again. Any data type is polymorphic in such
definition, isn't it? For example we can use "char" as an offset to a
object of some type in the array. Any data type is a number by nature
and what that number means only determined by how we use it. So I don't
see the way you can make a definition of polymorphic data type by what
it can hold. It can hold a set of bits and nothing more.


You are following a wrong path here.


As I said in another message, in C++ the term polymorphism means a
"run-time type identification" in calling the appropriate member function.


As it was used in this Win32 API it means generic programming. In C
generic programming is done by using void * and the appropriate casts.
 
D

DaKoadMunky

As I said in another message, in C++ the term polymorphism means a
"run-time type identification" in calling the appropriate member function.

You don't consider function overloading and class and function generation via
templates to be forms of polymorphism?

I have heard numerous others refer to them as such.
 
I

Ioannis Vranos

DaKoadMunky said:
You don't consider function overloading


Yes this is what I meant above, virtual member functions.


and class and function generation via
templates to be forms of polymorphism?



That is more accurately termed as generic programming in C++ world.
 
D

DaKoadMunky

You don't consider function overloading
Yes this is what I meant above, virtual member functions.

Having a derived class implement a virtual function declared in a base class is
overriding, not overloading.

Overloading is having more than one function with the same name in the same
scope.

The former is a form of dynamic polymorphism.

The latter is a form of static polymorphism.

That is if you believe this fellow...

http://www.research.att.com/~bs/glossary.html#Goverloading
http://www.research.att.com/~bs/glossary.html#Goverriding
http://www.research.att.com/~bs/glossary.html#Gpolymorphism

His credentials seem solid :)
 
I

Ioannis Vranos

DaKoadMunky said:
Having a derived class implement a virtual function declared in a base class is
overriding, not overloading.

Overloading is having more than one function with the same name in the same
scope.

The former is a form of dynamic polymorphism.

The latter is a form of static polymorphism.

That is if you believe this fellow...

http://www.research.att.com/~bs/glossary.html#Goverloading
http://www.research.att.com/~bs/glossary.html#Goverriding
http://www.research.att.com/~bs/glossary.html#Gpolymorphism

His credentials seem solid :)


OK, very interesting. So in other words, virtual member functions is
dynamic polymorphism, and generic programming (including overloaded
functions) is static polymorphism.


Very interesting. Thanks for the info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top