Reputation: 4971
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.
Upvotes: 2
Views: 1472
Reputation: 67090
Is that a good design choice or am I misunderstanding what my teacher told us?
I think you'll get a lot of different opinions about this. In my point of view it's not a really good choice (with some exceptions). I try to explain why.
typedef
for each type in the library).vector3
from real type (Eigen::Matrix3f
) you do not get a true independence because (with the exception of math operators) you'll use functions with prototypes defined in that library (think, for example, how the identity matrix is defined in Eigen and in Boost).typedef
. What next step will be? Wrap all classes to allow dependency injection? If it's what you need maybe you should start with a library designed in that way (but I don't think it's common or even a good idea for a mathematical library).typedef
shouldn't be used (but it's my opinion) to abstract your code or to hide implementation details. I think it should be used only as shortcut for a long type definition or to switch between two or more equivalent definitions. float
and double
aren't equivalent (and you have to always think what you're doing with them). To switch between them can change application results then it's good you can't do it with a small change in your typedef
.What am I doing wrong here?
C4430 error comes when you do not specify the return type of a function (prior to VS2k5 the default was int
as in C). You can get that error if you declare a variable of an unknown type. In your case you included your header file but maybe it doesn't include the Global matrix typedefs from Eigen library (it's in the Core
header file of the library).
Edited: you include RigidBody.h
in your PhysicsEngine.h
and vice-versa, fix it (extract your typedef
, if you want to use them) to another header file and avoid this round-trips.
Upvotes: 1
Reputation: 67157
Is that a good design choice or am I misunderstanding what my teacher told us?
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.
I get a lot of errors C4430.
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::Vector2f
is.
Try to add #include <Eigen/Core>
to PhysicsEngine.h
.
From your updated code: You have circular dependencies. PhysicsEngine.h
includes RigidBody.h
and vice versa. This is not good.
I suspect that while compiling RigidBody.cpp
, the compiler will end up parsing the class definition in RigidBody.h
before the typedefs in PhysicsEngine.h
, so that your custom typedefs are not available at that point.
You should probably remove the RigidBody.h
include from PhysicsEngine.h
, or move your typedefs to a separate header file.
Upvotes: 1