Intellisense does not work with VS2012 final C ++ templates

Intellisense works really bad with my VS ...

When I code in C ++, it works 100% fine until I start using templates, and then it just stops working completely, stops detecting errors, and won't automatically fill in all cases.

I am inclined to believe that this is due to what I did with my code that broke it.

So, I started by creating a class with a structure in it:

template<typename T> class List<T> { private: struct Node { T value; Node* next; Node* previous; }; Node* First; Node* Last; ... }; 

later, I will declare some additional functions:

 template<typename T> inline T List::First() { return First; } 

So far, so good, intellisense works 100% perfectly, but if I try to do it first → it will not work, VS will not say give me any options (ctrl + space does not work).

also, if I type some kind of stupidity, he will not tell me this wrong:

 sdkjgisjdga->vsrsiib = 123jgi; 

I really don't know what to do to fix this.

Thanks for your time and effort.

PS: I already tried resetting the configuration.

EDIT: Forgot to say that if I do not use templates in my .h file, then intellisense works correctly.

+6
source share
2 answers

Templates must be created before you can finally say what they contain. For example, your First-> snippet points to List<T>::Node , and this obviously depends on the exact T

Of course, Intellisense in this simple case can list members unambiguously by simply substituting T==int for a moment. But think even worse: Intellisense does not know the members (for example, now) or does Intellisense correctly guess in hard cases when you need it the most?

+8
source

I'm a bit late with this answer, and maybe the OP is no longer working on this code, but I think this might help those looking for templates and IntelliSense.

One thing you can try is if you want to see your typos and errors as you type, but if you want your code to be accessible for templates, use # if- # else- # endif:

 #if MY_USE_TEMPLATES template <typename T> #else typedef [**your-test-type-here**] T; #endif class List { ... your code here ... } 

In Visual Studio 2015, this works. You can set MY_USE_TEMPLATES to 0 (using #define), develop code with IntelliSense and automatically exit, etc. (So ​​that you make fewer mistakes) and then change MY_USE_TEMPLATES to 1 when you are ready to test or compile using the actual template code.

As long as you include MY_USE_TEMPLATES, the code referencing your list will result in an error (for example, code like “myList List”), and you can resolve this with the optional “layout” layout inside the #else statement. However, it’s a good idea to leave the #else clause without an additional “template”: the error you get when linking to your list can serve as a reminder to enable MY_USE_TEMPLATES before testing the code, reducing the likelihood of an error. (Experience shows that it is easy to forget it when working with many things and large projects ...)

However, be careful using several of these type definitions: "typedef ... T" can only be used safely once for this name "T"; while you can use "typedef ... TYPE1" for one class and "typedef ... TYPE2" for another, you cannot safely use the same type name for different types unless you put different type names in separate namespaces. (I tried this in Visual Studio 2015).

+6
source

All Articles