1

if I create a class object like this

sf::RenderWindow window(sf::VideoMode(200, 200), "SFML Window");

it works fine, but if I create it like this

sf::RenderWindow window = sf::RenderWindow(sf::VideoMode(200, 200), "SFML Window");

I get an error

attempting to reference a deleted function.

Don't they mean the same thing? Why does one work and the other does not?

acraig5075
  • 10,588
  • 3
  • 31
  • 50
  • They mean the same thing in C++17. If you have an old compiler then you'll have to do it the first way – M.M Jun 07 '18 at 08:10
  • @M.M I use Visual Studio 2017 –  Jun 07 '18 at 08:16
  • Thy mean the same, but it is inefficient to do it so. The problem might lie in the copy constructor of that object. – AdityaG Jun 07 '18 at 08:33
  • The error message implies that there is a copy-constructor present but has been marked [`=delete`](http://en.cppreference.com/w/cpp/language/function#Deleted_functions) prohibiting it's use. But strangely enough inspecting the [github source for SFML RenderWindow](https://github.com/SFML/SFML/blob/master/include/SFML/Graphics/RenderWindow.hpp) doesn't show this to be so. For what it's worth I think this is a good question. – acraig5075 Jun 07 '18 at 08:33
  • 2
    @craig5075 Looking at the link you gave, `RenderWindow` derives from `RenderTarget`, which in turn derives from `NonCopyable`, which declares its copy constructor and `operator=` `private`. Confusing error message tho. – Paul Sanders Jun 07 '18 at 08:53
  • @Artem try to find out whether it supports `/std:c++17` – M.M Jun 07 '18 at 08:56
  • @MM It's not that - see my comment above. – Paul Sanders Jun 07 '18 at 09:04
  • @PaulSanders Good catch. I think the point MM is making is that C++17 does not have the same requirement that the copy constructor used during copy-initialization must still be callable (even if the copy-construction will be elided.) – acraig5075 Jun 07 '18 at 09:08
  • @acraig5075 Oh, OK. I was not familiar with that. – Paul Sanders Jun 07 '18 at 09:11

0 Answers0