Hi,
Please see the code below.
void Allocate( char* s )
{
s = (char*)malloc( 100 );
}
int main( )
{
char* s = NULL;
Allocate( s );
strcpy( s,"Test");/*I know that this will fail. b'coz I still have a NULL pointer in s. Initially s was pointing to NULL, and from the function Allocate 100 bytes of memory was allocated in some memory location, and address of s was made to point to that location. But inside the main, s is still pointing to NULL. Pl. correct me if I am wrong.*/
}
Now my question is
void Allocate( Base* s )
{
s = new Base;
}
int main( )
{
Base* obj = NULL;
Allocate( obj );
obj->some_member = 20; // this works...
}
<< moderator edit: added [code][/code] tags >>
So I assume, object pointers are passed to functions in a different way compared to primitive type pointers. Can anyone pl. comment on this.