Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - steli2

Pages: [1]
1
General / Re: Having trouble with sf::Drawable inheritance
« on: April 04, 2019, 10:39:10 pm »
No I don't have, I've copy pasted all of the code (yeah I know it ain't much so far)

2
General / Re: Having trouble with sf::Drawable inheritance
« on: April 04, 2019, 09:16:16 pm »
I didn't specify the problem I am so dumb.
So it gives undefined references to the constructors when I have the public sf::Drawable, and it doesn't when it isn't present

Log
||=== Build: Debug in GameEngine (compiler: GNU GCC Compiler) ===|
obj\Debug\src\main.o||In function `ZN2GT14NormalParticleD1Ev':|
src\ParticleSystem.h|19|undefined reference to `vtable for GT::NormalParticle'|
obj\Debug\src\ParticleSystem.o||In function `ZN2GT14NormalParticleC2Ev':|
src\ParticleSystem.cpp|8|undefined reference to `vtable for GT::NormalParticle'|
||error: ld returned 1 exit status|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
 

3
General / Having trouble with sf::Drawable inheritance
« on: April 04, 2019, 05:31:00 pm »
I've been trying to create a particle system that relies on a main class "Particle" that is then inherited by other classes such as "NormalParticle". I want to have the "Particle" class have sf::Drawable and then have the draw() function declared in the child classes, so that I can have a vector of *Particle from which I can use directly window.draw( particle );

ParticleSystem.h
#ifndef PARTICLESYSTEM_H
#define PARTICLESYSTEM_H

#include<queue>

#include<SFML/Graphics.hpp>

namespace GT
{

    class Particle
    {
    public:
        sf::Vector2f position;

        Particle();
    };

    class NormalParticle : public GT::Particle, public sf::Drawable
    {
    public:

       NormalParticle();
    private:
        void draw(sf::RenderTarget& target, sf::RenderStates states) const;
    };

}

#endif // PARTICLESYSTEM_H

 
ParticleSystem.cpp
#include "ParticleSystem.h"

GT::Particle::Particle()
{

}

GT::NormalParticle::NormalParticle()
{

}

 

main.cpp
#include<iostream>
#include<SFML/Graphics.hpp>

#include"ParticleSystem.h"

using namespace std;

int main()
{
    sf::RenderWindow window(sf::VideoMode(1000, 800), "");

    GT::NormalParticle p;

    sf::Clock c;
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
        }

        window.clear();

        if (c.getElapsedTime().asMilliseconds() >= 16)
        {
            c.restart();
        }

        window.display();
    }

    return 0;
}

 

When I compile the code I get "undefined reference to `vtable for GT::NormalParticle"

I am new to the whole idea of inheritances so I am probably missing something
(also first time posting to the forum)

Pages: [1]