Accces through pointers

A pointer to the derived class can point to the objects of the base class.
True/Flase?
What is the answer to this statement , i guess it should be true becuase
1
2
3
  Derive *ptr;
ptr=&base;
ptr->functionofbase();

which is valid isn't it?
???
closed account (NUj6URfi)
Do you have more code?
No its just a true and false statement i had in my exam , why do you need more code?
closed account (NUj6URfi)
Oh. I thought functionofbase(); was involved. My understanding is that the pointer in question can point to the copy of the object in the derived class. Just not the object in the base class.
Thank you i don't know why but i guess it can't i want to ask another question

char name[20];
void displayn()
	{
		cout<<"Name :"<<name<<endl;
	}
	void setn(char *c)
	{
		strcpy(name,c);
	}
	char getn()
	{
		return *name;
	}

int main()
{
	
	char result[20];
	char p[20]="sharan";
	displayn();
	setn(p);
	displayn();
	cout<<getn()<<endl;
	strcpy(result,name);
	cout<<result<<endl;
	getch();
}

over here for getn i get a single character s how can i get full stored value
You declared getn to return a single character, so that's what you're getting.

Change getn to return a pointer to the name.

1
2
3
const char * getn()
{ return name;
}




Thank you :)
Topic archived. No new replies allowed.