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

Author Topic: [C++] sf::RenderWindow  (Read 5450 times)

0 Members and 1 Guest are viewing this topic.

Ninjasturm

  • Newbie
  • *
  • Posts: 16
    • View Profile
[C++] sf::RenderWindow
« on: September 24, 2010, 09:15:28 pm »
Hello Community

(I'm really sorry about my English).
I have a problem.
Here is some source code (I think then you now what i mean, i hope).
[CPP]
void Class::SetRenderWindow(sf::RenderWindow &App)
{
this->App = App;
}
// Now i call the Method
Class.SetRenderWindow(App);
[CPP]

Compiler output:

||=== **** Test, Debug ===|
||Info: resolving vtable for sf::Spriteby linking to __imp___ZTVN2sf6SpriteE |
||warning: auto-importing has been activated without --enable-auto-import specified on the command line.|
C:\Projekte\C++\********\.objs\main.o||In function `ZSt38__copy_backward_output_normal_iteratorIPPN2sf5EventES3_ET0_T_S5_S4_12__false_type':|
)]+0x26)||undefined reference to `sf::NonCopyable::operator=(sf::NonCopyable const&)'|
)]+0x26)||undefined reference to `sf::NonCopyable::operator=(sf::NonCopyable const&)'|
||=== Build finished: 2 errors, 1 warnings ===|

I use Code::Blocks and my Compilier is MinGW but i think the error is the overloaded operator =

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
[C++] sf::RenderWindow
« Reply #1 on: September 24, 2010, 09:36:01 pm »
The operator= is not provided, because sf::RenderWindow is uncopyable. You should instead store references or (maybe smart) pointers to it.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Finn

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
[C++] sf::RenderWindow
« Reply #2 on: September 24, 2010, 09:43:51 pm »
Or use sf::RenderTarget as a parameter instead of sf::Window

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
[C++] sf::RenderWindow
« Reply #3 on: September 24, 2010, 10:18:42 pm »
Quote from: "Finn"
Or use sf::RenderTarget as a parameter instead of sf::Window
As sf::RenderTarget is also noncopyable, this approach isn't really an alternative.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ninjasturm

  • Newbie
  • *
  • Posts: 16
    • View Profile
[C++] sf::RenderWindow
« Reply #4 on: September 25, 2010, 01:57:37 pm »
Can i edit the = operator of the NonCopyAble Struct.?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[C++] sf::RenderWindow
« Reply #5 on: September 25, 2010, 02:17:19 pm »
Technically yes BUT :
-> you have to create your own version of SFML (but I'm not sure if it will even work...)
-> and more importantly : that a very bad idea!

If this class doesn't allow to be copied it's not for nothing.

Nexus gave you a good solution :
Quote from: "Nexus"
You should instead store references or (maybe smart) pointers to it
SFML / OS X developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
[C++] sf::RenderWindow
« Reply #6 on: September 25, 2010, 02:18:30 pm »
No (of course you could, but not without changing SFML, which would be pretty stupid in this case).

There is a semantic reason why sf::RenderWindows cannot be copied. You don't need to copy it anyway, I already proposed alternative solutions.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Spellbreaker

  • Newbie
  • *
  • Posts: 33
    • ICQ Messenger - 287156171
    • MSN Messenger - spellbreaker@live.de
    • Yahoo Instant Messenger - Spellbreaker1979
    • View Profile
    • http://www.apeironstudios.com
[C++] sf::RenderWindow
« Reply #7 on: September 27, 2010, 07:13:06 pm »
You can only use init lists in the classes constructor, like this example:

Code: [Select]

class myClass {
    sf::RenderWindow &app;
    myClass(sf::RenderWindow &app);
}

myClass::myClass ( sf::RenderWindow &app) : app(app) {
   <foo>
}



int main() {

sf::RenderWindow App(...);

myClass foo(App);
}

 

anything