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

Author Topic: unique_ptr help  (Read 2898 times)

0 Members and 1 Guest are viewing this topic.

supermoneylife

  • Newbie
  • *
  • Posts: 4
    • View Profile
unique_ptr help
« on: January 18, 2015, 02:14:45 am »
Ive been trying to teach myself programming in C++. I have some experience of making a few full games in XNA but as you probably know, XNA makes everything fairly simple where you can just start adding objects immediately.

Anyway, I am following the tutorial book: SFML Game Development SFML 2.0 (However I am using SFML2.2 and VS2013 - hope this will be ok!)

I am stuck on the 2nd Chapter (I must admit I'm finding this book the most helpful Ive seen but much of it is left to me knowing where to put things like variables etc. and they don't really explain properly about adding classes to the project - together with headers etc - so I have been fairly confused the whole time and currently have the whole 'game' running from 'main.cpp' without any other classes or files.

The start of the 2nd chapter describes how I must use std::unique_ptr to create a class designed to handle loading of textures. (I realise the std library is not part of SFML, but Im hoping someone here can/will help me). When I try to implement this I get error: "std has no member 'unique_ptr' "

There is "unique_copy" but this looks like its something completely different.

I'm gutted as I was just feeling like I was starting to build a good understanding of how the game fitted together within c++ and was very much enjoying working through that book :/

Is the code in the book correct for my IDE and version of SFML? Is it just me being an idiot? I'm lost now :(
« Last Edit: January 18, 2015, 02:24:43 am by supermoneylife »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: unique_ptr help
« Reply #1 on: January 18, 2015, 02:28:19 am »
SFML, that book, and pretty much every other C++ library assumes that you are proficient in the C++ language already.  It sounds like you're having trouble simply because you aren't proficient yet.

I would read a book about C++ itself first before diving into a library written in that language.

Also, if you had simply googled the error message, you would get many helpful answers like this one: https://stackoverflow.com/questions/18078153/error-unique-ptr-is-not-a-member-of-std

lordseanington

  • Jr. Member
  • **
  • Posts: 86
  • Coffee is the blood of a coder.
    • View Profile
Re: unique_ptr help
« Reply #2 on: January 18, 2015, 02:29:07 am »
I suggest that you, instead, learn C++ another way. SFML is not a good way to start learning c++. I suggest starting with http://www.cplusplus.com/doc/tutorial/ to learn about c++. I sugest then moving into game design using c++ and sfml.

supermoneylife

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: unique_ptr help
« Reply #3 on: January 18, 2015, 02:34:43 am »
thanks for the replies guys and I fully get what you are saying. However I have spent several hours( like, hundreds of hours over several years) reading cplusplus and many other references on C++ but as they do not show direct examples of how each feature is applied to creating a program it seems difficult to learn and I thought maybe learning by finding out what causes the errors may help (which did work for me on XNA which I even struggled with at first).

For example cplusplus does a create job of explaining exactly what a pointer is, but I still don't see why you need them, that bit wasnt explained. I realise you have to allocate memory for any asset etc but it just isnt explained as to how,why and when, on any of the sites you mention (or that I have read myself after extensive google and book-reading).

I guess I will go back to square one and read all those references again but still seem to have no 'real-world applications' for the factual knowledge learned from said references.

supermoneylife

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: unique_ptr help
« Reply #4 on: January 18, 2015, 02:37:49 am »
SFML, that book, and pretty much every other C++ library assumes that you are proficient in the C++ language already.  It sounds like you're having trouble simply because you aren't proficient yet.

I would read a book about C++ itself first before diving into a library written in that language.

Also, if you had simply googled the error message, you would get many helpful answers like this one: https://stackoverflow.com/questions/18078153/error-unique-ptr-is-not-a-member-of-std


AND THANK YOU FOR THE LINK HERE AS I SIMPLY NEEDED TO INCLUDE <memory>

.... ahhh bliss..... until 5secs later when next problem arises :)

supermoneylife

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: unique_ptr help
« Reply #5 on: January 18, 2015, 02:43:55 am »
SFML, that book, and pretty much every other C++ library assumes that you are proficient in the C++ language already.  It sounds like you're having trouble simply because you aren't proficient yet.

I think "that book" fails big-time by not mentioning that you need to #include <memory>


Along with many many other similar issues in Chapter One which I managed to overcome myself. Still a great book Im enjoying it. Sorry to not know everything like you guys and maybe I should of googled instead of asking human beings, but I guess Im just old fashioned. I spose it does add to the amount of answers on this very site and has increased traffic at very least by 1 person so it cant be all bad :D Peace!!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: unique_ptr help
« Reply #6 on: January 18, 2015, 10:38:30 am »
The SFML Game Development book comes with complete, compilable and runnable codes, that you can find here:
https://github.com/SFML/SFML-Game-Development-Book

Obviously the book itself cannot show every single line of code, otherwise it would need thousands of pages ;)

And no, I don't think it fails by not mentionning that you need to include <memory>, it explicitly states that knowing the language is mandatory before starting to read, so that it can focus on SFML stuff and not teaching C++, thing that other books already do very well.
Laurent Gomila - SFML developer

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: unique_ptr help
« Reply #7 on: January 18, 2015, 07:01:46 pm »
My C++ teacher found a rather good book to use.  "C++ How To Program 9th Edition"

Most likely outdated by a newer version but it should help.  Not sure if there's a PDF version of it but it might help. :)
I have many ideas but need the help of others to find way to make use of them.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: unique_ptr help
« Reply #8 on: January 18, 2015, 07:32:36 pm »
And your teacher is someone to fully rely on because?

I can only suggest to picka book from this list. It's been reviewed and edited by thousands of people and not some "random" teacher. ;)
http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/