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 - fiberglass22

Pages: [1]
1
System / Re: sf :: Thread inside a class
« on: May 13, 2012, 10:10:27 pm »
...
Hah, thanks. I'll use this.

EDIT: No luck, unfortunately. Here's the updated code:
#ifndef SHAPECONTAINER_H
#define SHAPECONTAINER_H
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
class shapeContainer {
    public:
        shapeContainer ( ) : runthread ( & shapeContainer :: threadFunction , this ) { }
        shapeContainer ( );
        void setType ( int input );
        int getType ( );
        void setLocation ( int x1 , int y1 , int x2 , int y2 );
        sf :: RenderWindow * drawShape ( sf :: RenderWindow * window , sf :: Color color );
    private:
        void threadFunction ( ) { }
        int type , xl1 , xl2 , yl1 , yl2;
        sf::Thread runthread;
};
#endif
and the output:
Code: [Select]
In file included from ./main.cpp:1:
./shapecontainer.h:8: error: ‘shapeContainer::shapeContainer()’ cannot be overloaded
./shapecontainer.h:7: error: with ‘shapeContainer::shapeContainer()’
./shapecontainer.h: In constructor ‘shapeContainer::shapeContainer()’:
./shapecontainer.h:7: error: no matching function for call to ‘sf::Thread::Thread(void (shapeContainer::*)(), shapeContainer* const)’
/usr/include/SFML/System/Unix/Thread.hpp:92: note: candidates are: sf::Thread::Thread()
/usr/include/SFML/System/Unix/Thread.hpp:57: note:                 sf::Thread::Thread(void (*)(void*), void*)
/usr/include/SFML/System/Unix/Thread.hpp:45: note:                 sf::Thread::Thread(const sf::Thread&)
In file included from ./gamewindow.cpp:1:
./shapecontainer.h:8: error: ‘shapeContainer::shapeContainer()’ cannot be overloaded
./shapecontainer.h:7: error: with ‘shapeContainer::shapeContainer()’
./shapecontainer.h: In constructor ‘shapeContainer::shapeContainer()’:
./shapecontainer.h:7: error: no matching function for call to ‘sf::Thread::Thread(void (shapeContainer::*)(), shapeContainer* const)’
/usr/include/SFML/System/Unix/Thread.hpp:92: note: candidates are: sf::Thread::Thread()
/usr/include/SFML/System/Unix/Thread.hpp:57: note:                 sf::Thread::Thread(void (*)(void*), void*)
/usr/include/SFML/System/Unix/Thread.hpp:45: note:                 sf::Thread::Thread(const sf::Thread&)
In file included from /usr/include/SFML/System/Thread.hpp:40,
                 from /usr/include/SFML/System.hpp:38,
                 from /usr/include/SFML/Window.hpp:32,
                 from /usr/include/SFML/Graphics.hpp:32,
                 from ./shapecontainer.h:3,
                 from ./gamewindow.cpp:1:
/usr/include/SFML/System/NonCopyable.hpp: In member function ‘sf::Thread& sf::Thread::operator=(const sf::Thread&)’:
/usr/include/SFML/System/NonCopyable.hpp:64: error: ‘sf::NonCopyable& sf::NonCopyable::operator=(const sf::NonCopyable&)’ is private
/usr/include/SFML/System/Unix/Thread.hpp:45: error: within this context
In file included from ./gamewindow.cpp:1:
./shapecontainer.h: In member function ‘shapeContainer& shapeContainer::operator=(const shapeContainer&)’:
./shapecontainer.h:5: note: synthesized method ‘sf::Thread& sf::Thread::operator=(const sf::Thread&)’ first required here
./gamewindow.cpp: In member function ‘void GameWindow::drawGameWindow(sf::RenderWindow*, sf::Color, int, int, int)’:
./gamewindow.cpp:13: note: synthesized method ‘shapeContainer& shapeContainer::operator=(const shapeContainer&)’ first required here
In file included from /usr/include/SFML/System/Thread.hpp:40,
                 from /usr/include/SFML/System.hpp:38,
                 from /usr/include/SFML/Window.hpp:32,
                 from /usr/include/SFML/Graphics.hpp:32,
                 from ./shapecontainer.h:3,
                 from ./gamewindow.cpp:1:
/usr/include/SFML/System/NonCopyable.hpp: In copy constructor ‘sf::Thread::Thread(const sf::Thread&)’:
/usr/include/SFML/System/NonCopyable.hpp:57: error: ‘sf::NonCopyable::NonCopyable(const sf::NonCopyable&)’ is private
/usr/include/SFML/System/Unix/Thread.hpp:45: error: within this context
In file included from ./gamewindow.cpp:1:
./shapecontainer.h: In copy constructor ‘shapeContainer::shapeContainer(const shapeContainer&)’:
./shapecontainer.h:5: note: synthesized method ‘sf::Thread::Thread(const sf::Thread&)’ first required here
./gamewindow.cpp: In member function ‘shapeContainer GameWindow::shapeAt(int, int)’:
./gamewindow.cpp:40: note: synthesized method ‘shapeContainer::shapeContainer(const shapeContainer&)’ first required here
In file included from ./shapecontainer.cpp:2:
./shapecontainer.h:8: error: ‘shapeContainer::shapeContainer()’ cannot be overloaded
./shapecontainer.h:7: error: with ‘shapeContainer::shapeContainer()’
./shapecontainer.h: In constructor ‘shapeContainer::shapeContainer()’:
./shapecontainer.h:7: error: no matching function for call to ‘sf::Thread::Thread(void (shapeContainer::*)(), shapeContainer* const)’
/usr/include/SFML/System/Unix/Thread.hpp:92: note: candidates are: sf::Thread::Thread()
/usr/include/SFML/System/Unix/Thread.hpp:57: note:                 sf::Thread::Thread(void (*)(void*), void*)
/usr/include/SFML/System/Unix/Thread.hpp:45: note:                 sf::Thread::Thread(const sf::Thread&)
./shapecontainer.cpp: At global scope:
./shapecontainer.cpp:4: error: redefinition of ‘shapeContainer::shapeContainer()’
./shapecontainer.h:7: error: ‘shapeContainer::shapeContainer()’ previously defined here

2
System / Re: sf :: Thread inside a class
« on: May 13, 2012, 09:49:06 pm »
EDIT: It looked like a function to me, but I guess runThread is just an object.
In this case the mistake is that you can't call its constructor from inside the class.
Oh, alright. What would be a good way to integrate a sf::Thread into a class then? I have a class for animated shapes, and each shape requires a thread to loop it's animation.

3
System / Re: sf :: Thread inside a class
« on: May 13, 2012, 09:46:32 pm »
The & symbol there doesn't make sense in a function declaration (at least not when putting it front).

Did you want the runThread function to take a pointer?
In this case it should be: "sf :: Thread runThread  ( shapeContainer :: threadFunction * ) "

If you wanted it to take a reference then the & should be where the * is in the above line.
I tried this:
#ifndef SHAPECONTAINER_H
#define SHAPECONTAINER_H
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
class shapeContainer {
    void threadFunction ( void * UserData );
    sf :: Thread runThread ( shapeContainer :: threadFunction * );
 
which resulted in this:
Code: [Select]
In file included from ./main.cpp:1:
./shapecontainer.h:7: error: ‘shapeContainer::threadFunction’ is not a type
In file included from ./gamewindow.cpp:1:
./shapecontainer.h:7: error: ‘shapeContainer::threadFunction’ is not a type
In file included from ./shapecontainer.cpp:2:
./shapecontainer.h:7: error: ‘shapeContainer::threadFunction’ is not a type

4
System / sf :: Thread inside a class
« on: May 13, 2012, 09:28:29 pm »
Hi everyone. I'm new to SFML and self-taught so be nice :). Anyways, I'm having some difficulties putting a sf::Thread inside of a class. This is my code:
//file: shapecontainer.h
#ifndef SHAPECONTAINER_H
#define SHAPECONTAINER_H
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
class shapeContainer {
    void threadFunction ( void * UserData );
    sf :: Thread runThread ( & shapeContainer :: threadFunction );
    private:
        int type , xl1 , xl2 , yl1 , yl2;
    public:
        shapeContainer ( );
        void setType ( int input );
        int getType ( );
        void setLocation ( int x1 , int y1 , int x2 , int y2 );
        sf :: RenderWindow * drawShape ( sf :: RenderWindow * window , sf :: Color color );
};
#endif
//file: shapecontainer.cpp (trimmed)
#include <iostream>
#include "shapecontainer.h"
#include "gamewindow.h"
shapeContainer :: shapeContainer ( ) {
}
void shapeContainer :: threadFunction ( void * UserData ) {
    std :: cout << "test\n";
}
 
And the compiler error:
Code: [Select]
In file included from ./main.cpp:2:
./shapecontainer.h:7: error: expected identifier before ‘&’ token
./shapecontainer.h:7: error: expected ‘,’ or ‘...’
In file included from ./gamewindow.cpp:2:
./shapecontainer.h:7: error: expected identifier before ‘&’ token
./shapecontainer.h:7: error: expected ‘,’ or ‘...’
In file included from ./shapecontainer.cpp:2:
./shapecontainer.h:7: error: expected identifier before ‘&’ token
./shapecontainer.h:7: error: expected ‘,’ or ‘...’
Thanks in advance.

Pages: [1]