Hi I've just started out in c++, can anyone tell me how to use pointers which hold addresses of objects ?

How do you access the object fields from this type of pointer, especially strings (array of chars)...

I'm using a Dev c++ 4.9.9.2 compiler....

Hi I've just started out in c++, can anyone tell me how to use pointers which hold addresses of objects ?

How do you access the object fields from this type of pointer, especially strings (array of chars)...

I'm using a Dev c++ 4.9.9.2 compiler....

you might want to post some code of your attempts so far...

When I try to compile this prog., it says that age and name were not declared and 'request for member of non-aggregate type before '<<' token '.....

Thanks...

Its the same as holding a address of a pointer to primitive data type.

Object* obj, obj1;
obj = &obj1;

An agregate type is a structure or class or union that holds (possibly) an agregate of serveral members of other types.

In you print function you do not have an agregate type you have a pointer to an aggreagate type. You can get the agregate type by dereferencing the pointer so for a structure type T

T obj;
T* pointer = &obj;  // Always initialise pointers

obj.member;  // Access a member of an agregate type

pointer.member;  // Error pointer is not an agregate type it is a pointer to an agregate type

(*pointer).member;  // OK pointer is derefernced to the agregate type 

pointer->member;   // The -> operator is a shortcut for above syntax

I closed the * and the object pointer name in parentheses and it worked!

thanks....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.