Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9159111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:24:49+00:00 2026-06-17T13:24:49+00:00

I have incorporated polymorphism with a single subclass for now. Two of these functions,

  • 0

I have incorporated polymorphism with a single subclass for now. Two of these functions, as seen in the following code, Draw() and SetValue(int,int,int) are causing linker errors.

 #include "Header.h"

 class Object{
int tag;
 public:
void SetValues(int,int,int);
void Draw();
int getTag(){
    return tag;
}
 };
class Square: public Object{
int red;
int green;
int blue;
void Draw();
void SetValues(int red2,int green2, int blue2){
red=red2;
green=green2;
blue=blue2;
}
};
void Square::Draw(){
 // Draws a square with a gradient color at coordinates 0, 10
  glBegin(GL_QUADS);
  {
glColor3f(red, green, blue);
glVertex2i(1, 11);
glColor3f(red * .8, green * .8, blue * .8);
glVertex2i(-1, 11);
glColor3f(red * .5, green * .5, blue * .5);
glVertex2i(-1, 9);
glColor3f(red * .8, green * .8, blue * .8);
glVertex2i(1, 9);
  }
  glEnd();
}

The errors

Error   1   error LNK2019: unresolved external symbol "public: void __cdecl Object::SetValues(int,int,int)" (?SetValues@Object@@QEAAXHHH@Z) referenced in function "public: void __cdecl State::DrawAll(void)" (?DrawAll@State@@QEAAXXZ)    C:\Users\Asher\documents\visual studio 2012\Projects\Procedural Terrain\Procedural Terrain\State.obj    Procedural Terrain
Error   2   error LNK2019: unresolved external symbol "public: void __cdecl Object::Draw(void)" (?Draw@Object@@QEAAXXZ) referenced in function "public: void __cdecl State::DrawAll(void)" (?DrawAll@State@@QEAAXXZ)    C:\Users\Asher\documents\visual studio 2012\Projects\Procedural Terrain\Procedural Terrain\State.obj    Procedural Terrain

In a larger class, which does no inherit Object’s functions, uses DrawAll() with a Draw() call in it.
The cpp file and the two respective header files are as follows.

#include "Header.h"
#include "Object.h" 
float rotate_z=0;
class State{
private:
std::vector<Object> storage;
public:
State();
State Interpolate(State, State, double);
void Integrate(State,double, const double);
void DrawAll();
void AddObject(Object);
void RemoveObject(int);
};
State::State(){

}
State State::Interpolate(State current,State previous,const double alpha){
//current*alpha + previous * ( 1.0 - alpha );
return current;
}
void State::Integrate(State current, double t, const double dt){
}
void State::AddObject(Object object){
storage.push_back(object);
}
void State::RemoveObject(int tag){
//for(int i=0;i<storage.size;i++){
//  if(storage.at(i).getTag==tag){
//storage.erase(storage.begin()+i);
//  }
//}
}
void State::DrawAll(void)
{
  // reset view matrix
  glLoadIdentity();
// move view back a bit
glTranslatef(0, 0, -30);
// apply the current rotation

glRotatef(rotate_z, 0, 0, 1);
rotate_z += 5;
// by repeatedly rotating the view matrix during drawing, the
// squares end up in a circle
int i = 0, squares = 15;
float red = 0, blue = 1;
for (; i < squares; ++i){
  Square square;
Object * squareP=&square;
glRotatef(360.0/squares, 0, 0, 1);
// colors change for each square
red += 1.0/12;
blue -= 1.0/12;
squareP->SetValues(red,0.6,blue);
squareP->Draw();
  }
}

The Object header –

#ifndef Object_H
#define Object_H

class Object{
int tag;

public:
void SetValues(int,int,int);
void Draw();
int getTag();
};
class Square: public Object{
int red;
int green;
int blue;
void Draw();
void SetValues(int red2,int green2, int blue2);
};
#endif

Lastly the State header –

#ifndef State_H
#define State_H

#include "Object.h"
#include <vector>
class State{
private:
std::vector<Object> storage;
public:
State();
State Interpolate(State, State, double);
void Integrate(State,double, const double);
void DrawAll();
void AddObject(Object);
void RemoveObject(int);
};
#endif

This is the first C++ project I have worked on and have not fully transferred from a Java background. What could the problem be?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:24:50+00:00Added an answer on June 17, 2026 at 1:24 pm

    Your Object class has no implementation of SetValues function. You may want a pure virtual function. Same for Draw.

    class Object {
        virtual void SetValues(int,int,int) = 0;
    }
    

    Also note that in C++ functions are not virtual by default. You have to use the virtual keyword explicitly in the base class.

    Also class Object seems to be defined at multiple places. Why? Defining it in Object.h would be sufficient.

    Also please indent your code because it is very hard to read.

    Also std::vector<Object> will not do what you want! Unline Java, where everything is a reference, in C++ things are stored by value in an std::vector and therefore your code is subject to the slicing problem. You want to use at lease a pointer there (std::vector<Object*>) but a smart pointer would be even better (std::vector<std::shared_ptr<Object>>)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 10 .vbs file and incorporated them into a single .vbs file namely
I'm still working on my multi-stage form (http://jsfiddle.net/xSkgH/93/) and have incorporated the following solution
I have a worldmap.swf, were I have incorporated a small logo in any continent,
After reading some articles about XSS I have incorporated HTMLPurifier into my zend framework
I have made a custom formwizard and incorporated it into my admin interface. Basically
I have incorporated the fb:fan control onto my web page. The problem I have
I have a C# .NET 3.5 app that I have incorporated the DragDrop event
I'm using this free Web Template - EliteCircle and have just incorporated it into
I have a 6 .vbs files. and I incorporated them into a file said
I have an iOS project hosted on Bitbucket which uses MapBox-iOS-sdk which I incorporated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.