Click here to Skip to main content
11,921,898 members (39,282 online)
Rate this:
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[1] = &circle;
shapeVector[2] = &cylinder;

When I do this:
Shape *baseClassPtr=shapeVector[ 1 ];
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 20-Jan-13 0:05am
Edited 20-Jan-13 2:26am

1 solution

Rate this: bad
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
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.
SoMad 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 OriginalGriff 493
1 Dave Kreskowiak 285
2 Sergey Alexandrovich Kryukov 243
3 Richard MacCutchan 155
4 ppolymorphe 135
0 OriginalGriff 7,231
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,356
3 George Jonsson 2,865
4 Suvendu Shekhar Giri 2,216

Advertise | Privacy | Mobile
Web04 | 2.8.151120.1 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2015
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