Witam, przychodzę z pytaniem jak poprawnie użyć referencji, aby przekazać argument typu należącego do jakiejś klasy.
Mam przykładowo:
(Plik nagłówkowy)
bool MoveIsArea(sf::RenderWindow ,float, float, int, int, int, int);
(Plik źródłowy)
bool MoveIsArea( sf::RenderWindow & win, float obiekta_x, float obiekta_y, int obiektb_x, int obiektb_y, int obiektbs_x, int obiektbs_y)
{
if( obiekta_x > obiektb_x && obiekta_x < obiektb_x + obiektbs_x && obiekta_y > obiektb_y && obiekta_y < obiektb_y + obiektbs_y)
{
Litghten_p( win, obiektb_x, obiektb_y, obiektb_x + obiektbs_x, obiektb_y + obiektbs_y);
return true;
}
return false;
}
Gdy używam referencji otrzymuje błędy:
c:\sfml\include\sfml\window\window.hpp(477): error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
1> c:\sfml\include\sfml\system\noncopyable.hpp(67) : see declaration of 'sf::NonCopyable::NonCopyable'
1> c:\sfml\include\sfml\system\noncopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1> This diagnostic occurred in the compiler generated function 'sf::Window::Window(const sf::Window &)'
1>c:\sfml\include\sfml\graphics\rendertarget.hpp(419): error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
1> c:\sfml\include\sfml\system\noncopyable.hpp(67) : see declaration of 'sf::NonCopyable::NonCopyable'
1> c:\sfml\include\sfml\system\noncopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1> This diagnostic occurred in the compiler generated function 'sf::RenderTarget::RenderTarget(const sf::RenderTarget &)'
c:\users\robert\documents\visual studio 2010\projekts\chickenalchemist\chickenalchemist\main.cpp(17): could be 'bool MoveIsArea(sf::RenderWindow &,float,float,int,int,int,int)'
1> c:\users\robert\documents\visual studio 2010\projekts\chickenalchemist\chickenalchemist\declaration.h(6): or 'bool MoveIsArea(sf::RenderWindow,float,float,int,int,int,int)'
1> while trying to match the argument list '(sf::RenderWindow, float, float, int, int, int, int)'
c:\users\robert\documents\visual studio 2010\projekts\chickenalchemist\chickenalchemist\declaration.h(6): error C2653: 'sf' : is not a class or namespace name
1>c:\users\robert\documents\visual studio 2010\projekts\chickenalchemist\chickenalchemist\declaration.h(6): error C2065: 'RenderWindow' : undeclared identifier
1>c:\users\robert\documents\visual studio 2010\projekts\chickenalchemist\chickenalchemist\declaration.h(6): error C2062: type 'float' unexpected
1>c:\users\robert\documents\visual studio 2010\projekts\chickenalchemist\chickenalchemist\declaration.h(8): error C2653: 'sf' : is not a class or namespace name
1>c:\users\robert\documents\visual studio 2010\projekts\chickenalchemist\chickenalchemist\declaration.h(8): error C2065: 'RenderWindow' : undeclared identifier
1>c:\users\robert\documents\visual studio 2010\projekts\chickenalchemist\chickenalchemist\declaration.h(8): error C2062: type 'int' unexpected