Hello vasanthsena and all Dev-C++ users,
Monday, November 3, 2003, 9:13:09 PM, vasanthsena wrote as follows:
vx> Hi I have written a program where I want to access a
vx> structure member.when I use "->" it gives me an error
vx> which says invalid type of argument."." on the other
vx> hand works just fine. Any thoughts on why this could
vx> happen.
Huh, problems with major C++ features we have??? So remember this till end
of your life:
- use . for references to objects created normally ( Class_name object) and
for object passed by reference or value:
void function( Class_name object )//pass by value, copy object created
{
object.value = 13;
void function( const Class_name &object ) //pass by reference
{
if( object.value == 3 )
use -> for object created on stack using operator new or passed using
pointer:
//example of passing object using pointer
Class_name object;
function( &object );
//function body
void function( Class_name *object )
{
object->value = 11;
//creating object on stack
Class_name *object = new Class_name( 7 );
if( object->value == 6 )
...
btw. get a good book and start learning C++ from the begining - these are
fundamental features of C++
--
regards, Zodiaq
|