Dynamic type checking

V

Vinodh Kumar P

Whenever I read any C++ literature I find the words "C++ is statically type
checked".OK.Agreed.
Is there any language that supports "Dynamic type checking"?
In such a case any type can be assigned to any other type during compile
time?
 
G

Gernot Frisch

Vinodh Kumar P said:
Whenever I read any C++ literature I find the words "C++ is statically type
checked".OK.Agreed.
Is there any language that supports "Dynamic type checking"?
In such a case any type can be assigned to any other type during compile
time?

Maybe inheritance or cast-operators would do? I mean - what do you
expect when you assign a void* to a CMyClass?? See, you have to define
it to get what you want.
-Gernot
 
R

Rolf Magnus

Vinodh said:
Whenever I read any C++ literature I find the words "C++ is statically
type checked".OK.Agreed.
Is there any language that supports "Dynamic type checking"?

Most scripting languages do.
In such a case any type can be assigned to any other type during
compile time?

You variables might not even have a type at compile time since that type
can change at run-time. So if you assign a variable to another one,
that other variable changes its type accordingly.
Consider python:

x = 3 # x is an integer
y = "Hello world" # y is a string
x = y # now x is a string, too

In C++, a variable can never change its type. You can however use
polymorphism to get a more dynamic behaviour, within some limits.
 
P

Pete C.

Rolf said:
Most scripting languages do.


You variables might not even have a type at compile time since that
type can change at run-time. So if you assign a variable to another
one, that other variable changes its type accordingly.
Consider python:

x = 3 # x is an integer
y = "Hello world" # y is a string
x = y # now x is a string, too

In C++, a variable can never change its type. You can however use
polymorphism to get a more dynamic behaviour, within some limits.

You can implement a VB6- style variant class, which I'm doing now. Of course
on the inside you must use static type checking, but so does VB's variant.

variant x = 3; // it's an int
variant y = "hello"; // this one's a string
x = y; // now it's a string too

Mine so far supports that, and operator+, but I've got the basic framework
done and it will be easy to do the rest of the operators. I'll post it here
when I'm done.

- Pete
 

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,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top