473,505 Members | 15,381 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Type Cast Pointer, Child and Parent Interaction

3 New Member
Hello there, until now i am still confused about this one, i mean what for we cast the child class to parent class?.. since child class can access all of the member of the parent class, yeah since its has public modifier..

And also, we can cast the parent as a child using dynamic_cast right?.. but what for?..

I still relly confused about pointer interaction, why we need access the pointer thingy..

Thx very much, very very appreciate a little help.. thx thx a lot, already read so many article but still confused.. :)
Dec 16 '11 #1
4 3004
weaknessforcats
9,208 Recognized Expert Moderator Expert
In C++ you are not supposed to cast at all.

The cast syntax is there for emergency use. Generally, any cast in a C++ program means you are calling C functions with void* arguments.

For a beginner, any cast in your program means your design is faulty.

Certainly, the type cast of child to parent is almost akways an error. Where did you hear to do that?

As to dynamic_cast, if you can't tell me what it is, then don't use it.
Dec 16 '11 #2
hinomotoblade
3 New Member
thanks a lot for replying.. :)

yeah, i just often saw scripts. And several ppl said the reason that for getting the pointer, they just always said, to get address diadadiada, but i think as far as i know, i never use type cast for classes thingy..

For example, the simple one about getting pointer is, making new object from other class, there are 2 way right? using new, and not..
and to access the member is different too, with pointer we use "->", and the other just use ".".. but i think they have same value right..

Thx a lot.. :)
Dec 16 '11 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
When you create an object as a local variable you have to know at compile time that you need to create it. But what if you don't? What if the user has to answer a question at run time to determine what kind of object to create? That's where the new operator comes in. This allows you to create an object at run-time and the new operator returns the address of the object. You keep this address in your pointer variable.

C++ provides the "->" operator when useing a pointer to the object and the "." syntax when working with the object directly.
Dec 16 '11 #4
hinomotoblade
3 New Member
Ohhhhh thx a lot dude !!.. :D
Dec 18 '11 #5

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

Similar topics

3
4716
by: Hiusing Ngai | last post by:
Hello, I'm porting some C code to VC++ 7. A line of C code is: int (*v); and the C code allocate memory: v = calloc (width*5, sizeof **v); The VC++ 7 has the following erorr when I compile...
2
4733
by: Jacek Dziedzic | last post by:
Hi! Say a have a class called black_box which, among other things, contains an array of cells like this: class black_box { private: // ... public: black_box_details_struct details;
4
547
by: Richard Lee | last post by:
Hi, I have a question when I do a data type cast. the common way when we do a cast, is we know the type we want to cast to, i.e. we want to cast object to string, object xyz = "question";...
1
2119
by: martin | last post by:
hi guys, have you ever tried to create a type-cast operator to a 'reference/pointer to an array'? i hadn't, not until yesterday when i discovered that it is not exactly the trivial task one'd...
3
21200
by: mra | last post by:
I want to cast an object that I have created from a typename to the corresponding type. Can anycone tell me how to do this? Example: //Here, Create the object of type "MyClass" object...
7
2527
by: Paul | last post by:
Hello, I'm coming from a PHP background and am working on a large-scale VB.NET project. One of the cornerstones of this project is a reusable form class, to standardize our web forms. My goal...
7
5237
by: llothar | last post by:
When i use -W4 on visual c 7.0 i get warning C4054 translator1.c(1703) : warning C4054: 'type cast' : from function pointer 'void * (__cdecl *)(se_agent *)' to data pointer 'void *'...
3
29671
by: David Mathog | last post by:
I have a program for which this line: if(! lstrtol(&atoken,length-2,(long *) &(lclparams->pad)) || (lclparams->pad< 0)){ generates the warning below, but ONLY if the gcc compiler is at -O2 or...
1
3039
by: andrewst | last post by:
Originally posted by Divya OK:- SQLcreate table parent( parent_id number primary key, parent_name SQLvarchar2(10) ); Table created. SQLcreate table child( child_id number primary key,...
7
3939
by: * Tong * | last post by:
Hi, I couldn't figure out how to properly type cast in this case: $ cat -n type_cast.c 1 #include <stdio.h> 2 3 typedef unsigned char Byte; 4 typedef signed char Small_Int; 5
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.