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

Author Topic: Problems with a Class Inheriting from sf::Thread  (Read 4609 times)

0 Members and 1 Guest are viewing this topic.

spacechase0

  • Newbie
  • *
  • Posts: 39
    • AOL Instant Messenger - thespacechase0
    • View Profile
    • http://spacechase0.com/
Problems with a Class Inheriting from sf::Thread
« on: March 29, 2010, 03:50:24 am »
I'm using SFML 1.5 linked dynamically, on Microsoft Windows XP Professional (Version 2002, Service Pack 3).

Compiler Errors:
Quote
C:\Documents and Settings\Chase\Desktop\C++\Puzzle Game\source\main.cpp|24|error: no matching function for call to `LoadingThread::LoadingThread()'|
C:\Documents and Settings\Chase\Desktop\C++\Puzzle Game\source\Thread_Class.h|10|note: candidates are: LoadingThread::LoadingThread(const LoadingThread&)|


I have a pretty good feeling that I'm not supposed to define anything of my own that's public (when inheriting public sf::Thread), because commenting that out makes it compile fine (except for the 'LoadingThread has no member X ' errors).

Relevant Part of main.cpp
Code: [Select]
   LoadingThread loading;
    loading.images = gameImages;
    loading.images = gameFonts;
    loading.Launch();



Thread_Class.h:
Code: [Select]
#ifndef THREAD_CLASS_H
#define THREAD_CLASS_H

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <string>
#include <map>

class LoadingThread : public sf::Thread
{
    private:
        int loadedSoFar;
        virtual void Run();

    public:
        int GetLoadedSoFar();
        std::map<std::string, sf::Image>& images;
        std::map<std::string, sf::Font>& fonts;
};

#endif

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problems with a Class Inheriting from sf::Thread
« Reply #1 on: March 29, 2010, 08:18:57 am »
A reference can only be initialized (ie. bound to an existing object) when it is constructed. Your class has reference members, so it has to initialize them in its constructor; that's why the compiler complains about a missing default constructor (it cannot be generated by the compiler).

Code: [Select]
class LoadingThread : public sf::Thread
{
    private:
        int loadedSoFar;
        virtual void Run();

    public:
        LoadingThread(std::map<std::string, sf::Image>& img, std::map<std::string, sf::Font>& fnt) : images(img), fonts(fnt)
        {
        }

        int GetLoadedSoFar();
        std::map<std::string, sf::Image>& images;
        std::map<std::string, sf::Font>& fonts;
};

LoadingThread loading(gameImages, gameFonts);
loading.Launch();


If you want ot be able to change the images and fonts after constructing the instance, use pointers instead.
Laurent Gomila - SFML developer

spacechase0

  • Newbie
  • *
  • Posts: 39
    • AOL Instant Messenger - thespacechase0
    • View Profile
    • http://spacechase0.com/
Problems with a Class Inheriting from sf::Thread
« Reply #2 on: March 29, 2010, 09:19:36 pm »
I never knew that. I guess you (or me, in this case.) learn something new every day. :)

I wish the problems I asked about weren't silly mistakes. Next time, I'll ask somewhere else (if it's something like that) so that you can help people who's problem has to do with SFML and not C++ in general. :)

Thanks! But now that it works, there's apparently a problem with a font a chose (judging by the error). That belongs in the Graphics section though, so I'll post that in there, instead (if I can't find anything in search).