2

Rectangle.h

#pragma once

#ifndef RECTANGLE_H
#define RECTANGLE_H

#include "Input.h” //Necessary to prevent errors (defines)

class Rectangle {

public:

    Rectangle();
    ~Rectangle();

    static bool rectIsColliding(Rectangle r1, Rectangle r2); 

    float getX();
    float getY();
    float getWidth();
    float getHeight();

    void setX(float);
    void setY(float);
    void setWidth(float);
    void setHeight(float);

    void setPos(float, float);
    void setSize(float, float);

    void translate(float, float);
    void scale(float, float);

    void flip();

private:

    float x;
    float y;

    float width;
    float height;

};

#endif

Player.h:

#pragma once

#ifndef PLAYER_H
#define PLAYER_H

#include "Input.h” //Necessary to prevent errors (defines)

#include "Rectangle.h"

class Player {

public:

    Player();
    ~Player();

    void update(); //Run on every tick (physics, motion, etc.)
    void render(); //Run on every render (graphics, image, etc.)

private:

    Rectangle hitbox; //C3646: "hitbox" unknown ovveride specifier
                      //C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    float xPos = 0, yPos = 0; //Position
    float vX = 0, vY = 0; //Velocity

    Direction direction; //Direction for graphics

    unsigned char *image; //Image pointer

    int width, height, comp; //Image dimentions

    unsigned int texture, VBO, VAO, EBO; //Buffers

    int vertexShader; //Vertex shader pointer
    int fragmentShader; //Fragment shader pointer

    unsigned int shaderProgram; //Dual shader program pointer

};

#endif

From what I understand, this is caused by the compiler not being able to find the Rectangle class, despite the IDE being able to (hence why there were no other errors).

Things I have tried:

  • Moving around the Rectangle include in Player.h
  • Putting the Rectangle include in stdafx.h
  • Copying the Rectangle code (Rectangle.h & Rectangle.cpp) into Player.h
  • Changing the C++ version
Alexis Harper
  • 31
  • 1
  • 8
  • 2
    What is the exact error? – NathanOliver Apr 19 '18 at 18:01
  • 3
    `#include "stdafx.h"` should never be in a header file. Use it only in the first (non comment) line of source files. Remember that Visual Studio ignores all lines before that include. – drescherjm Apr 19 '18 at 18:02
  • Make sure you are building your code as C++11 (or later) or else `override` won't be valid. – Jesper Juhl Apr 19 '18 at 18:06
  • 2
    [Worth your time to read up on what stdafx.h is and what it does](https://stackoverflow.com/questions/4726155/whats-the-use-for-stdafx-h-in-visual-studio), and then deciding whether you are going to make use of it at all. It being turned on by default has lead to a lot of cargo cult behaviour. – user4581301 Apr 19 '18 at 18:15
  • The exact error code is put in a comment in the code. Also, I have updated the code to no longer include stdafx.h in any headers. I will update the code on the top. – Alexis Harper Apr 21 '18 at 14:50
  • `#include "Input.h”` is a syntax error. – melpomene Apr 21 '18 at 14:57
  • Does the error message really say `ovveride`? – melpomene Apr 21 '18 at 14:59
  • The problem had to do with linking errors for objects with errors that never got displayed. I reordered some headers, and found a few warnings that never got displayed previously, and after fixing those, two errors popped up, and when those were fixed, then the code compiled fine. – Alexis Harper Sep 20 '18 at 15:18

0 Answers0