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 7050475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:08:53+00:00 2026-05-28T03:08:53+00:00

I’ve checked the most common undefined reference to vtable question on here, and while

  • 0

I’ve checked the most common undefined reference to vtable question on here, and while that gave me a better understanding of what is going on, I still wasn’t able to gather enough information to figure out why I’m having this error.

I have a simple Square class, which, originally I was trying to inherit from a Polygon class. Since I’ve been relatively knew to C++ and still learning, I haven’t experimented with Polymorphism all that much.

Anyway, after I tried getting rid of the base class (Polygon), I thought that might help things. Unfortunately, I’m still getting the same error, and I don’t quite know what is going on. What I do know is that originally, the Polygon class required a source file with at least a constructor definition, which I did give. That got rid of the vtable error for the Polygon class.

My main issue is that I’m still getting this for the Square class, which was supposed to inherit from the Polygon class. What I’d like to know is how can I implement this properly to avoid getting a vtable error while still getting the benefits of Polymorphism?

Code

Polygon.h/.cpp

#ifndef POLYGON_H
#define POLYGON_H

#include "Shape.h"
#include "vector3f.h"

class Polygon
{
public:
    Polygon();
    virtual void Collide(Shape &s) = 0;
    virtual void Collide(Polygon &p) = 0;
    virtual bool Intersects(const Shape &s) = 0;
    virtual bool Intersects(const Polygon &s) = 0;
protected:
    virtual void Draw() const = 0;
};

#endif // POLYGON_H

//------------------

#include "Polygon.h"

Polygon::Polygon() {


}

*Square.h/.cpp

#ifndef SQUARE_H
#define SQUARE_H

#include "Polygon.h"
#include "Shape.h"
#include "Vec3f.h"
#include <QGLWidget>

class Square //: public Polygon
{
public:
    Square(Vec2f lenwidth = Vec2f(), Vec3f color = Vec3f());
    ~Square();

    virtual void Collide(Shape &s);
    virtual void Collide(Square &s);
    virtual void Collide(Polygon &p);
    virtual bool Intersects(const Shape &s);
    virtual bool Intersects(const Polygon &p);
    virtual bool Intersects(const Square &s);
    virtual float Area(void) const;

protected:
    virtual void Draw();

private:
    Vec2f mDimensions;
    Vec3f mColor;

};

#endif // SQUARE_H

//----------------

#include "Square.h"

/**********/
/* PUBLIC */
/**********/

Square::Square(Vec2f lenwidth, Vec3f color) //: Polygon()
{
    this->mDimensions = lenwidth;
    this->mColor = color;
}

Square::~Square() {

}

void Square::Collide(Polygon &p) {

}

/************/
/* PRIVATE  */
/************/

void Square::Draw() {
    const int numPoints = mDimensions.X * mDimensions.Y;
    glBegin(GL_LINE_STRIP);
    glColor3f(mColor.X, mColor.Y, mColor.Z);

    for (double i = 0; i <= numPoints; i++) {
        const float x = mDimensions.X;
        const float y = mDimensions.Y;

        glVertex3f(x, y, 0.0);

        mDimensions.X += 1;
        mDimensions.Y += 1;
    }
}
  • 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-05-28T03:08:54+00:00Added an answer on May 28, 2026 at 3:08 am

    The reason for the vtable linking error is that you are not defining the first virtual function in your class(which is Collide(Shape&p)). (vtables are usually stored along with the first virtual function definition)

    Add a void Square::Collide(Shape &p) function( just a blank void Square::Collide(Shape &p) {} should work) and that specific vtable error should go away.

    Note that you are probably should define all the functions in your header.

    Remember, arguments types differentiate functions just like names in C++, a Collide(Shape) is different from a Collide(Polygon).

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.