Intellisense in header files

I just "moved" from C # to C ++ / CLR. At first it annoyed me that I had to write class declarations twice (in .h and .cpp). Then I realized that I can put the code in h files - it compiles at least. Well, I deleted all the cpp of my classes, and now I realized: VS will not give me Intellisense when I work on my h files.

I think I should not put my code in hfiles (the code will not be reused in other projects for sure), but I am terrified to configure all method declarations in two places ... Plus I need to switch back and forth to find out which modifier is my method etc., and it’s not very good in one place, like in C # (with it the pros and cons).

I'm sorry this is a newbie question, but I just wanted to make sure there was no way to enable intellisense for hfiles. Or at least find out that I'm completely wrong ...

Thanks David

+3
source share
2 answers

You blow intellisense out of the water because the code for each class is embedded in each implementation file, and that only more data than Intellisense can be analyzed reliably. It starts crashing due to timeouts.

I know you said this is annoying, but you need to put the class twice - how C ++ works. If you want it to behave like C #, use C #. In any case, this is the best language for the .NET platform.

0
source

.h . .cpp , .

:

b.h

#ifndef B_H    
#define B_H

    class B
    {
      public:
         int foo();
         void Set(int x);

      private
         int data_;
    };

#endif

b.cpp

#include <stream>
#include "b.h"

int B::foo()
{
   std::cout << "data value " << data_;
   return data_;
}

void B::Set(int x)
{
   data_ = x;
}

, B, #include b.h. b.cpp. , intellisense

+1

Source: https://habr.com/ru/post/1737191/


All Articles