I’m writing a small game engine project and I’m having trouble with this constructor. For some weird reason g++ says I need to add a ‘)’ in a spot where there’s no reason to add one. Neither I nor Visual Studio Code see anything wrong with it and I’ve been looking at this for 20 minutes trying to see if something is wrong. The error is occurring in the PhysicsObject and Renderable constructors.
GameObject does not need to be fully qualified. I have written GameObject on its own everywhere else in the program and it is not a part of its own namespace or anything. In fact I have made constructors that look almost identical to this one with no error.
(including the full code just in case there’s a stupid typo or something)
PhysicsObject.h
#pragma once
#include <string>
#include "Node.h"
#include "Transform.h"
#include "GameObject.h"
class PhysicsObject : public Node {
protected:
Transform * transform;
void move(double dt);
void accelerate(double dt);
public:
PhysicsObject(GameObject * obj, std::string name) : Node(name) {
transform = obj->transform;
obj->nodes[name] = this;
}
void update(double dt);
void destroy() { delete this; }
Vector2 velocity = Vector2D::zero;
Vector2 acceleration = Vector2D::zero;
};
Renderable.h
#pragma once
#include <vector>
#include <string>
#include "Node.h"
#include "SDL2/SDL.h"
#include "Vector2.h"
#include "GameObject.h"
#include "Transform.h"
class Renderable : public Node {
public:
static inline std::vector<Renderable *> allRenderables;
protected:
//0-255
int r = 255;
int g = 255;
int b = 255;
int a = 255;
Transform * transform;
Renderable(GameObject * obj, std::string name) : Node(name) {
transform = obj->transform;
allRenderables.push_back(this);
}
public:
virtual void update(double dt);
virtual void render() {};
void destroy() {
delete this;
}
};
Here’s the error message:
In file included from include/GameObject.h:3,
from GameObject.cpp:3:
include/Renderable.h:26:26: error: expected ‘)’ before ‘*’ token
26 | Renderable(GameObject * obj, std::string name) : Node(name) {
| ~ ^~
| )
In file included from include/GameObject.h:3,
from include/PhysicsObject.h:7,
from PhysicsObject.cpp:1:
include/Renderable.h:26:26: error: expected ‘)’ before ‘*’ token
26 | Renderable(GameObject * obj, std::string name) : Node(name) {
| ~ ^~
| )
In file included from include/GameObject.h:3,
from test.cpp:6:
include/Renderable.h:26:26: error: expected ‘)’ before ‘*’ token
26 | Renderable(GameObject * obj, std::string name) : Node(name) {
| ~ ^~
| )
In file included from test.cpp:9:
include/Rectangle.h: In constructor ‘Rectangle::Rectangle(float, float, bool, GameObject*, std::string)’:
include/Rectangle.h:19:27: error: no matching function for call to ‘Renderable::Renderable(GameObject*&, std::string&)’
19 | : Renderable(obj, name) {
| ^
In file included from include/GameObject.h:3,
from test.cpp:6:
include/Renderable.h:12:7: note: candidate: ‘Renderable::Renderable(const Renderable&)’
12 | class Renderable : public Node {
| ^~~~~~~~~~
include/Renderable.h:12:7: note: candidate expects 1 argument, 2 provided
include/Renderable.h:12:7: note: candidate: ‘Renderable::Renderable(Renderable&&)’
include/Renderable.h:12:7: note: candidate expects 1 argument, 2 provided
I didn’t really know what to try. Looked at the error and looked at my code looking for some kind of typo but I can’t find anything.
Did some searching for the error online but everyone either had a typo, didn’t fully qualify std::string, or something like that.
Also restarted VSC but to no one’s surprise it didn’t change anything.
I do not see what could possibly be wrong. If you need to see the code for the Rectangle class I can send it but I really don’t know how it would be relevant so I am omitting it unless someone asks. I’d really appreciate any help y’all can offer. Thanks!