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

Author Topic: Header issues?  (Read 2102 times)

0 Members and 1 Guest are viewing this topic.

UglyIgloo

  • Newbie
  • *
  • Posts: 21
    • View Profile
Header issues?
« on: August 18, 2014, 02:14:32 pm »
Right now, I'm having errors coming from the official SFML files, and I can only assume it's because of the way my headers are arranged. I've looked through them and I cannot find any possible infinite loops going through them.


Cwindow.h

#include <SFML/Graphics.hpp>

#pragma once

class Cwindow
{
private:
        sf::RenderWindow window;
public:
        Cwindow();
        ~Cwindow(void);
        void ShowImage(sf::Sprite theImage);
        void Init(float iFrameCount, float iSwitchFrame, float iFrameSpeed, sf::Clock iclock);
};


CEntity.h

#include "Cwindow.h"
#include <string.h>

#pragma once
class CEntity
{
protected:
        enum Direction {Down, Left, Right, Up};

        sf::Vector2i source;
        std::string spritePath;
        sf::Texture pTexture;
        sf::Sprite myImage;
        Cwindow MyWindow;

public:
        CEntity(Cwindow SetWindow);
        ~CEntity(void);
        void Render(float iFrameCount, float iSwitchFrame, float iFrameSpeed, sf::Clock iclock);
};

 





Errors(VC++ 2010 Express):


Quote
1>------ Build started: Project: SFML_Project, Configuration: Release Win32 ------
1>  Entity.cpp
1>C:\SFML-2.1\include\SFML/Window/Window.hpp(477): error C2248: 'sf::NonCopyable::operator =' : cannot access private member declared in class 'sf::NonCopyable'
1>          C:\SFML-2.1\include\SFML/System/NonCopyable.hpp(79) : see declaration of 'sf::NonCopyable::operator ='
1>          C:\SFML-2.1\include\SFML/System/NonCopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1>          This diagnostic occurred in the compiler generated function 'sf::Window &sf::Window::operator =(const sf::Window &)'
1>C:\SFML-2.1\include\SFML/Graphics/RenderTarget.hpp(419): error C2248: 'sf::NonCopyable::operator =' : cannot access private member declared in class 'sf::NonCopyable'
1>          C:\SFML-2.1\include\SFML/System/NonCopyable.hpp(79) : see declaration of 'sf::NonCopyable::operator ='
1>          C:\SFML-2.1\include\SFML/System/NonCopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1>          This diagnostic occurred in the compiler generated function 'sf::RenderTarget &sf::RenderTarget::operator =(const sf::RenderTarget &)'
1>  Cwindow.cpp
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========





Additional Notes:

The errors stop when I remove the header from Cwindow.h (but then I get errors regarding identifiers)
« Last Edit: August 18, 2014, 02:18:11 pm by UglyIgloo »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Header issues?
« Reply #1 on: August 18, 2014, 02:27:47 pm »
sf::RenderWindow is a non-copyable type, you must pass it to functions by reference or by address.

class CEntity
{
protected:
    Cwindow& MyWindow;

public:
    CEntity(Cwindow& SetWindow);
};

CEntity::CEntity(Cwindow& SetWindow) : MyWindow(SetWindow)
{
}
 
« Last Edit: August 18, 2014, 03:19:55 pm by Laurent »
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Header issues?
« Reply #2 on: August 18, 2014, 02:30:47 pm »
The problem is with this line:

CEntity(Cwindow SetWindow);

You're trying to pass your Cwindow by value, which means a copy gets made, but since your Cwindow contains an sf::RenderWindow, it will try to make a copy of that as well, however sf::RenderWindow is non copyable, meaning you can't copy around sf::RenderWindow instances.
The solution is to pass your Cwindow by reference.

Also you're mixing quite a few naming schemes, which makes your code look rather chaotic. In general the hungarian notation is not recommended, so at best you simply drop all the "i/p/C/whatever" prefixes. If you however for some strange reason don't want to change, make sure to actually follow it, e.g. i = integer so don't declare it as float.
I specially recommend to drop the C prefix for classes. It won't help you in anyway and just adds noise. Besides when it comes down to struct/classes/templates/etc. the "C" which stood for "Class" doesn't really make sense anymore. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

UglyIgloo

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Header issues?
« Reply #3 on: August 18, 2014, 02:37:49 pm »
The solution is to pass your Cwindow by reference.

Isn't that what I'm doing, anyway?

Quote
I specially recommend to drop the C prefix for classes. It won't help you in anyway and just adds noise. Besides when it comes down to struct/classes/templates/etc. the "C" which stood for "Class" doesn't really make sense anymore. ;)

Thanks for the suggestion. :P Although, I feel more comfortable defining classes with "C" as a prefix. It's nothing logical, just a preference.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Header issues?
« Reply #4 on: August 18, 2014, 03:01:41 pm »
Isn't that what I'm doing, anyway?
Not in C++, see Laurent's answer.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

UglyIgloo

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Header issues?
« Reply #5 on: August 18, 2014, 03:15:42 pm »
Thanks for your response. Now I just have one more issue that needs to be resolved.


CEntity::CEntity(Cwindow& SetWin)
{
        MyWindow = SetWin; // this line
        pTexture.loadFromFile(spritePath);
        source.x = 1;
        source.y = Down;
        myImage.setTexture(pTexture);
        myImage.setTextureRect(sf::IntRect(source.x * 32, source.y * 32, 32, 32));
        MyWindow.ShowImage(myImage);
}

 



The commented line yields these errors:

Quote
1>------ Build started: Project: SFML_Project, Configuration: Release Win32 ------
1>  Entity.cpp
1>Entity.cpp(6): error C2758: 'CEntity::MyWindow' : must be initialized in constructor base/member initializer list
1>          c:\documents and settings\****\my documents\sfml_project\sfml_project\sfml_project\Entity.h(14) : see declaration of 'CEntity::MyWindow'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Header issues?
« Reply #6 on: August 18, 2014, 03:19:40 pm »
That's why I added the constructor definition in my answer... Have a look again ;)
Laurent Gomila - SFML developer

UglyIgloo

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Header issues?
« Reply #7 on: August 18, 2014, 03:23:54 pm »
Perfect!


Thanks, Laurent!

 

anything