Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 4 classes:
Point inherits from Shape,Circle from Point and Cylinder from Circle.
point, circle, cylinder are objects to Point, Circle, Cylinder.
XML
Shape *shapeVector[3];
shapeVector[0]=&point;
shapeVector[1] = &circle;
shapeVector[2] = &cylinder;


When I do this:
C++
Shape *baseClassPtr=shapeVector[ 1 ];
baseClassPtr->GetName();

It is working.But when I do this:
C++
virtualViaPointer( shapeVector[ i ] ); // for all i(0,1,2)

   void virtualViaPointer(  Shape *baseClassPtr )    
   {                         	   
	   cout << baseClassPtr->GetName() << ": " ; 
   }

I'm getting this error:
VB
Error   2   error LNK1120: 1 unresolved externals 
Error	1	error LNK2019: unresolved external symbol "void __cdecl virtualViaPointer(class Shape const *)" (?virtualViaPointer@@YAXPBVShape@@@Z) referenced in function _wmain
Posted
Updated 20-Jan-13 1:26am
v4

1 solution

Unless I am missing something, it looks like you simply have to add the parenthesis:
C++
cout << baseClassPtr->GetName() << ": " ;


You did not actually show the GetName() declaration, but to me this looks like it would fix it.

Soren Madsen
 
Share this answer
 
v2
Comments
missak boyajian 20-Jan-13 5:19am    
I dont know why i havent put the paranthesis. I will update the question
SoMad 20-Jan-13 5:23am    
The new error message you are getting looks to me like you copy/pasted the code from your question and did not remove the <pre> tags - at least not the </pre> at the end.

Soren Madsen
missak boyajian 20-Jan-13 5:29am    
I copy pasted the error from visual studio. I tried many things I dont know why its not working. GetName is a pure virtual function and i have implement it in the 3 classes except shape.
SoMad 20-Jan-13 5:37am    
That is fine, but that is not the problem. Look at the error message. It is saying that your function virtualViaPointer(class Shape const *) is not declared. Look closely at the parameter, it says const. You should be able to simply modify your function to take the parameter as const.

Soren Madsen
missak boyajian 20-Jan-13 5:46am    
Thanks it worked. I forgot I was using constant functions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900