Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
I have 4 classes:
Point inherits from Shape,Circle from Point and Cylinder from Circle.
point, circle, cylinder are objects to Point, Circle, Cylinder.
Shape *shapeVector[3];
shapeVector[0]=&point;
shapeVector[1] = &circle;
shapeVector[2] = &cylinder;
 
When I do this:
 Shape *baseClassPtr=shapeVector[ 1 ];
 baseClassPtr->GetName();
It is working.But when I do this:
virtualViaPointer( shapeVector[ i ] ); // for all i(0,1,2)

   void virtualViaPointer(  Shape *baseClassPtr )    
   {                         	   
	   cout << baseClassPtr->GetName() << ": " ; 
   }
I'm getting this error:
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 19-Jan-13 23:05pm
Edited 20-Jan-13 1:26am
v4

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Unless I am missing something, it looks like you simply have to add the parenthesis:
cout << baseClassPtr->GetName() << ": " ;
 
You did not actually show the GetName() declaration, but to me this looks like it would fix it.
 
Soren Madsen
  Permalink  
v2
Comments
missak boyajian at 20-Jan-13 5:19am
   
I dont know why i havent put the paranthesis. I will update the question
SoMad at 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 at 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 at 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 at 20-Jan-13 5:46am
   
Thanks it worked. I forgot I was using constant functions.
SoMad at 20-Jan-13 5:48am
   
Glad I could help.
 
Soren Madsen

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 471
1 Maciej Los 325
2 Yogesh Kumar Tyagi 304
3 OriginalGriff 298
4 Prakriti Goyal 200
0 OriginalGriff 6,367
1 Sergey Alexandrovich Kryukov 5,296
2 Maciej Los 3,384
3 Peter Leow 3,259
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100