SFML community forums

Help => General => Topic started by: hyperworker on April 13, 2018, 10:20:08 pm

Title: .cpp syntax for reference initialization
Post by: hyperworker on April 13, 2018, 10:20:08 pm
I am following a guide on SFML and have met a pitfall. From what I understand, the writer was using psuedocode since his original code was:

class World : private sf::NonCopyable
{
public:
explicit World(sf::RenderWindow& window);


private:
sf::RenderWindow& mWindow;

};

I believe this is psuedocode because you have to initialize a reference first.

So I consulted my Stroustrup book and found that I can do it like this.

    #pragma once
    #include <SFML/Graphics/RenderWindow.hpp>


        class Renderer : private sf::NonCopyable
        {

        public:

                Renderer();  

                Renderer(sf::RenderWindow &newWindow) :renderWindow(newWindow) {}

                ~Renderer();


        private:


                sf::RenderWindow& renderWindow;

        };


But I am missing the syntax for the cpp file, I get errors for these.

        Renderer::Renderer() {}


        Renderer::~Renderer()
        {
        }
 
Quote
'Renderer::renderWindow;' references must be initialized

I've searched for a few hours for the answer, but either I am god awful at using keywords or it's just not an easy topic to find. Any help, suggestions or criticisms are greatly appreciated.
Title: Re: .cpp syntax for reference initialization
Post by: fallahn on April 13, 2018, 11:33:02 pm
You're looking for member initialisation lists: http://en.cppreference.com/w/cpp/language/initializer_list