In an academic project I’m trying to setup a simple physics engine.
I am using Eigen library for vector/matrixes calculation.
I’d like to stay as much independent as I can from library/design choices I’m making, to ease future changes, so I’m using typedefs for the Eigen types.
File PhysicsEngine.h
#pragma once
#include <Eigen/Core>
#include <Eigen/Geometry>
#include "RigidBody.h"
... other inclusions ...
namespace PhysicsEngine
{
typedef float real;
typedef Eigen::Vector3f vector3;
typedef Eigen::Quaternionf quaternion;
typedef Eigen::Matrix4f matrix4;
typedef Eigen::Matrix3f matrix3;
...
1) Is that a good design choice or am I misunderstanding what my teacher told us?
Including the file above, in RigidBody.h, and trying to use those typedefs:
#pragma once
#include "PhysicsEngine.h"
namespace PhysicsEngine
{
class RigidBody
{
public:
vector3 position; // <- error C4430
real inverseMass; // <- error C4430
vector3 velocity; // <- error C4430
vector3 netForce; // <- error C4430
quaternion orientation; // <- error C4430
matrix3 inverseInertiaTensor; // <- error C4430
vector3 rotation; // <- error C4430
vector3 netTorque; // <- error C4430
matrix4 transformationMatrix; // <- error C4430
...
I get:
error C4430: missing type specifier – int assumed. Note: C++ does not support default-int.
2) What am I doing wrong here?
Thanks in advance.
It might be a poor design choice since you hide the fact that you are using Eigen types, nevertheless you will need to know this fact in order to use your typedefs.
Descriptions like that really annoy me. Your compiler won’t just die with “error C4430”, it gives you detailed error information that is crucial for finding the cause of the problem. You are making it hard for anyone to help you by not sharing this information. Can you please post the first complete message, along with the code line that is causing the error?
The number of errors is irrelevant, since it is probable that most of the errors originate from the same problem.
Since Microsofts warning C4430 reads “missing type specifier – int assumed”, I suspect that you are forgetting to include Eigen header files, so that the compiler does not know what an
Eigen::Vector2fis.Try to add
#include <Eigen/Core>toPhysicsEngine.h.From your updated code: You have circular dependencies.
PhysicsEngine.hincludesRigidBody.hand vice versa. This is not good.I suspect that while compiling
RigidBody.cpp, the compiler will end up parsing the class definition inRigidBody.hbefore the typedefs inPhysicsEngine.h, so that your custom typedefs are not available at that point.You should probably remove the
RigidBody.hinclude fromPhysicsEngine.h, or move your typedefs to a separate header file.