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

Dynamic type checking

P: n/a
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?
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Vinodh Kumar P" <th*************@yahoo.com> schrieb im Newsbeitrag
news:ca**********@news.mch.sbs.de...
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
Jul 22 '05 #2

P: n/a
Vinodh Kumar P wrote:
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.

Jul 22 '05 #3

P: n/a
Rolf Magnus wrote:
Vinodh Kumar P wrote:
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.


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
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.