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.. :)
4 3004
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.
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.. :)
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.
Ohhhhh thx a lot dude !!.. :D
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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;
|
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";...
|
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...
|
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...
| |
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...
|
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 *'...
|
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...
|
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,...
|
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
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| | |