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

Author Topic: Cant create a class object with inherited sf::drawable....  (Read 2977 times)

0 Members and 1 Guest are viewing this topic.

electruxck

  • Newbie
  • *
  • Posts: 6
    • View Profile
Cant create a class object with inherited sf::drawable....
« on: April 20, 2015, 01:53:05 pm »
Hello everyone :)
i am new to forums and i am posting this thread because i have a problem...
the problem is that visual c++ 2010 express says i cant create an abstract object... i created a class (below) which inherits sf::drawable and uses virtual void draw()... function...
heres the source code of the class:
basically i am trying to create a game map...
class Tile:public sf::Drawable
{
        sf::Texture t;
        sf::Sprite s;
        int __walkable,__gate;
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
        {
                target.draw(s,states);
        }
        public:
                void LoadTex(std::string __str)
                {
                        t.loadFromFile(__str);
                        s.setTexture(t);
                }
                void SetPos(sf::Vector2f __v)
                {
                        s.setPosition(__v);
                }
                void SetPos(float x,float y)
                {
                        s.setPosition(x,y);
                }
                void SetWalkable(int __w)
                {
                        __walkable = __w;
                }
                int GetWalkable()
                {
                        return __walkable;
                }
                void SetGate(int __g)
                {
                        __gate = __g;
                }
                int GetGate()
                {
                        return __gate;
                }
                sf::FloatRect GetRectBounds()
                {
                        return s.getGlobalBounds();
                }
};


class WorldMap:public sf::Drawable
{
        std::list<Tile> _map;
        std::string MapDB,mapfiles[3];
        void Draw(sf::RenderTarget& target, sf::RenderStates states) const
        {
                for(std::list<Tile>::const_iterator it = _map.begin();it != _map.end();it++)
                {
                        target.draw(*it,states);
                }
        }
        public:
                WorldMap()
                {
                        MapDB = "Assets/Maps/_map.db";
                }
                int LoadMap(int id)
                {
                        _map.clear();
                        Strings str;
                        sqlite3_stmt *stmt;
                        sqlite3 *db;
                        sqlite3_open(MapDB.c_str(),&db);
                        int i = 1,type,grid;
                        sf::Vector2f pos(35,35);
                        SetMapFiles(id);
                        while(true)
                        {
                                str = "SELECT * FROM Map";
                                str += id;
                                str += " WHERE id = ";
                                str += i;
                                res = sqlite3_prepare_v2(db,str.GetChar(),strlen(str.GetChar()),&stmt,NULL);
                                if(res != SQLITE_OK) break;
                                sqlite3_step(stmt);
                                type = sqlite3_column_int(stmt,0);
                                grid = sqlite3_column_int(stmt,1);
                                if(type == MAP_TYPE_WALKABLE)
                                {
                                        Tile tile;
                                        tile.SetPos(pos);
                                        tile.LoadTex(mapfiles[0]);
                                        tile.SetGate(0);
                                        tile.SetWalkable(1);
                                        tile.SetPos(pos.x*i,pos.y*grid);
                                        _map.push_back(tile);
                                }
                                if(type == MAP_TYPE_NON_WALKABLE)
                                {
                                        Tile tile;
                                        tile.SetPos(pos);
                                        tile.LoadTex(mapfiles[1]);
                                        tile.SetGate(0);
                                        tile.SetWalkable(0);
                                        tile.SetPos(pos.x*i,pos.y*grid);
                                        _map.push_back(tile);
                                }
                                if(type == MAP_TYPE_GATE)
                                {
                                        Tile tile;
                                        tile.SetPos(pos);
                                        tile.LoadTex(mapfiles[2]);
                                        tile.SetGate(1);
                                        tile.SetWalkable(1);
                                        tile.SetPos(pos.x*i,pos.y*grid);
                                        _map.push_back(tile);
                                }
                                i++;
                        }
                        return 1;
                }
                void SetMapFiles(int id)
                {
                        if(id == 1)
                        {
                                mapfiles[0] = "Assets/Maps/1-1.png";
                                mapfiles[1] = "Assets/Maps/1-2.png";
                                mapfiles[2] = "Assets/Maps/1-3.png";
                        }
                }
};
 

please help me... if u need complete source code i can email you or something... but i would like to not give out my source just yet :) thanks :D
regards, elec

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Cant create a class object with inherited sf::drawable....
« Reply #1 on: April 20, 2015, 01:58:25 pm »
You have a typo, single letter. Find it and fix it.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

electruxck

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Cant create a class object with inherited sf::drawable....
« Reply #2 on: April 20, 2015, 02:02:26 pm »
ok.... in the source code or rest? and what is it?...

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Cant create a class object with inherited sf::drawable....
« Reply #3 on: April 20, 2015, 02:10:29 pm »
Do you seriously expect me to do your work for you? If you understand the error message that your compiler is outputting, you would know where it is. If you want to program, then... program yourself. This includes solving compiler errors on your own.

Maybe you should spend a bit more time looking at that code snippet you posted than writing in this thread. Unless you are a really slow reader, it shouldn't take you that long. Just don't be lazy and expect others to solve such trivial problems for you.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

electruxck

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Cant create a class object with inherited sf::drawable....
« Reply #4 on: April 20, 2015, 02:27:28 pm »
wait... wat do u mean by typo? a grammatical error or a coding error? if coding, ik that according to c++ i cant create an object of a class which has virtual function... and i definitely dont expect to get codes from anyone... all i want to know if there is some sort of a get around outta this situation? plz dont b mad at me :(

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
AW: Cant create a class object with inherited sf::drawable....
« Reply #5 on: April 20, 2015, 02:30:43 pm »
Draw vs draw

Read your error messages carefully!
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

electruxck

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Cant create a class object with inherited sf::drawable....
« Reply #6 on: April 20, 2015, 05:40:11 pm »
ok yes i forgot the virtual keyword... i added it and got this error:
1>d:\visual studio 2010\projects\game_client\game_client\main.cpp(112): error C2259: 'WorldMap' : cannot instantiate abstract class
1>          due to following members:
1>          'void sf::Drawable::draw(sf::RenderTarget &,sf::RenderStates) const' : is abstract
1>          d:\c++ libraries\sfml-2.1\include\sfml\graphics\drawable.hpp(69) : see declaration of 'sf::Drawable::draw'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

i still cant understand you :/ i have a similar function (almost same lol) for another project which dont have any problem with this function :/ guys please help me....

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Cant create a class object with inherited sf::drawable....
« Reply #7 on: April 20, 2015, 06:01:56 pm »
READ THE ERROR MESSAGE. You can not initialize a class with an unsatisfied abstract member.

You have a typo, single letter. Find it and fix it.

Draw vs draw
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

electruxck

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Cant create a class object with inherited sf::drawable....
« Reply #8 on: April 20, 2015, 06:12:12 pm »
omg lol now i get it >_< the caps 'D' was causing the issue... dammmmm lol THANKS GUYS :D sorry i coudnt understand.... but THANKS A LOTTTTT :D
All hail C++ & SFML and its awesome community :D

 

anything