I want to preface this by saying that I am making the transition from C to C++, and from vim to Visual C++ 2010, so if this could be better answered by me learning a concept that I'm missing feel free to just say "go learn ___ and come back." I hope I'm not too verbose with this post... With that said, onto the issue:
#pragma once
#include "stdafx.h"
class ShapeWrapper: public sf::RectangleShape
{
public:
//Checks that the click was inside of the shape
bool checkShape(sf::RenderWindow *window)
{
if (sf::Mouse::getPosition(*window).x >= getPosition().x && sf::Mouse::getPosition(*window).x <= (getPosition().x + 100))
if (sf::Mouse::getPosition(*window).y >= getPosition().y && sf::Mouse::getPosition(*window).y <= (getPosition().y + 100))
return true;
return false;
}
};
This is a new class that I am trying to make. This member function that I've written is supposed to check that the mouse position is within the bounds of the box drawn on the screen. It worked in an earlier version of the code where it was a regular function, not inside of a class. I would pass in the RenderWindow and the RectangleShape that I was checking instead of doing it from inside of a member function.
Since I've put it into the class I've lost access to all of the other member functions. For example, "getPosition" is underlined in red saying that "identifier 'getPosition' is undefined". But by my novice C++ understanding, it shouldn't be because ShapeWrapper should have inherited it from RectangleShape, correct?
This is the Output when I try to build it in debugging mode (this is the only file in my 6-file project that gives me any errors):
1>------ Build started: Project: circleClicker, Configuration: Debug Win32 ------
1> smallFunctions.cpp
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(4): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(5): error C2504: 'RectangleShape' : base class undefined
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(8): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(8): error C2061: syntax error : identifier 'RenderWindow'
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1> game.cpp
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(4): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(5): error C2504: 'RectangleShape' : base class undefined
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(8): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(8): error C2061: syntax error : identifier 'RenderWindow'
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(11): error C2065: 'RectangleShapeWrapper' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(11): error C2146: syntax error : missing ';' before identifier 'circle'
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(11): error C2065: 'circle' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(12): error C2065: 'circle' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(12): error C2228: left of '.setSize' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(13): error C2065: 'circle' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(13): error C2228: left of '.setOrigin' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(14): error C2065: 'circle' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(14): error C2228: left of '.setPosition' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(34): error C2065: 'circle' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(34): error C3861: 'checkShape': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(36): error C2065: 'circle' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(36): error C2228: left of '.setPosition' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\game.cpp(65): error C2065: 'circle' : undeclared identifier
1> endOfGame.cpp
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(4): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(5): error C2504: 'RectangleShape' : base class undefined
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(8): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(8): error C2061: syntax error : identifier 'RenderWindow'
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1> circleClicker.cpp
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(4): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(5): error C2504: 'RectangleShape' : base class undefined
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(8): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(8): error C2061: syntax error : identifier 'RenderWindow'
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(10): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2653: 'sf' : is not a class or namespace name
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2065: 'window' : undeclared identifier
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\wrappers.h(11): error C3861: 'getPosition': identifier not found
1>c:\users\joe\documents\visual studio 2010\projects\circleclicker\circleclicker\circleclicker.cpp(9): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I've tried using
this->getPosition()
as well, but I'm getting the same issue. I have a feeling it is an issue with how I've included my headers, because it doesn't even recognize
sf
as a namespace. Can someone point me in the right direction here? It would be greatly appreciated.