gardian06
gardian06

Reputation: 1546

resolving a typedef, and namespaces VS2010

I am working on making a physics engine (with the help of a book), and the book suggests that I create a namespace for the engine to exist in, and for the first part I declare a 'typedef' for variables like so

typedef float real;

and I can understand the explanation that the author gives being that "if precision needs change then you can just go to this one line, and change it, and then maybe have to change at most 10 helper functions, and clarity of representation, but I think it coincides with the other two things, so I hope this is follow-able.

the book asks that I define the typedef, and helper functions in one file (to minimize file hopping if change is needed), and then include that before the other files are compiled, and to do all of this in a namespace (I named Physics), then in another file create classes to be used in the engine. though the direct problem is with intellisense, and resolving

genFunction.h
namespace Physics{
typedef float real;
}


Classes.h
#include "genFunction.h"
namespace Physics{
class Vector3{
public :
    real x;   // visual studio is throwing that Physics::real is not a type name
    real y;
    real z;
    // VS is not offering collapsing, or any form of 
    // auto/assistance with lines.
    // almost like it does not want me to have classes
    // in my own namespaces
    Vector3(){ // uncolapsable 
        x = 0;
        y = 0;
        z = 0;
    }
};
}

am I doing anything wrong considering that the compiler is ignoring that I have done a typedef, and it is upscope of where the issue is occurring, and then the fact that VS isn't even showing suggestions while I am inside a class in a self made namespace troubles me slightly.

Edit: primary solution found to resolution of type. apparently instead of a { I put a ( on one of the methods, and that caused it to act like the entire namespace didn't exist. though VS will still not give me any kind of assistance (function/class/namespace collapsing, or completion suggestions even with ctrl+spacebar) also I have some helper functions that I use (self made pow(), sqrt() ) that I use that cause linker errors if not in a class, but this goes away when I put inline on them. is this a bad thing to resolve a linker?

Upvotes: 0

Views: 988

Answers (1)

Stack Overflow is garbage
Stack Overflow is garbage

Reputation: 247969

First of all, the compiler isn't throwing anything. Since you haven't said otherwise, I'm assuming your code compiles fine. The problem is with Intellisense then, and nothing more.

Intellisense in C++ is notoriously shaky. Sometimes it works, sometimes it doens't. It may depend on the phases of the moon.

Sometimes you can "encourage" it a bit by being more explicit. If you type ::, it should suggest all the members of the global namespace. ::Physics:: and it should suggest members of the Physics namespace.

It might just be a matter of waiting (or restarting VS or rebuilding?) until it decides to reparse your code.

Upvotes: 2

Related Questions