Visual Studio 2015 Go To Definition going to wrong class - c++

I just started having a problem with Visual Studio 2015 in C++ code. When I hit F12 to go do definition, I get taken to the wrong class. Inside of the solution, there are multiple projects with different classes that have the same method name. Here's a simple diagram of the project/class structure.
Project1
Class1
Initialize();
Project2
Class2
Initialize();
Class2 uses Class1 from Project1. If I'm working within Class2 and hit F12 on Class1.Initialize(), I get taken to the Class2.Initialize function.
It's almost like Visual Studio is only looking at the function name and starts searching within the current project.
I've tried restarting Visual Studio and deleting the .suo files.

This happens to me as well a lot of times, especially when classes with same name but different namespace are involved, or just with different class names but same method name.
Unfortunately I see the same problem in Visual Studio 2017.
I suppose the cause may be some deficiency in the Intellisense parsing part of the IDE.

Related

Visual Studio Code IntelliSense removed classes

I've been used to Visual Studio Code semi-broken IntelliSense, where it only shows relevant methods in certain circumstances, but that one is driving me crazy. Every time I create a class, Visual Studio Code is able to find it. But once this class is deleted, it is STILL able to find it, even days after it's been deleted.
How do I fix that?
vscode stores intellisense informations in .BROWSE.VC.DB files. For some reasons I was able to find them in .vscode folder for some projects but not in others, even with default configuration. The location might have changed with recent versions. I found all .BROWSE.VC.DB in AppData\Roaming\Code\User\workspaceStorage. Deleted it and it worked.

Cannot "Go To Definition" in Visual C++ 2013

In Visual C++ 2013 Professional, when I right-click CWinApp::Run(), an MFC function, in the afxwin.h header file and choose "Go To Definition" in the context menu, nothing comes up. The definition is also unavailable on this function's MSDN article. How can I fix the problem and find the definition? What would cause definitions to be unavailable?
You can't go to a definition of a function that exists in the MFC, you don't have access to the debugging information. Generally, you're only going to be able to access the definition of functions you have the source for. You can access the declarations, that's what you see in the header file.
As far as some problem you have, I'd lean toward your own code having a problem, not something in the MFC.
You can put a break point on any MFC function then debug it, and step in to the function (F11 key or "Step in" command). This will take you directly to source code, most of the time.
In this case, you may be redirected to this file for VC 2013:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\src\mfc\appcore.cpp
What Error is shown in the console?
All i can say to help is that you are suposed to call that function in a while loop, like this:
while(CWinApp::Run()){
//application code goes here...
}

Does Visual Studio support C++ code indexing?

Does Visual Studio have a source code indexing feature for C++? That is, it statically parses your project, storing symbols in an index, such that you can easily and quickly jump to a definition of a symbol or see uses of it (i.e. call hierarchy)?
From what I can tell, in Visual Studio 2010, it has "Go to Definition" and "View Call Hierarchy" functions (if you right-click a symbol), but it takes a long time (a minute on my project) to find the info and do the action. It seems to be doing a crude text search in some cases.
I'm used to using Eclipse, which has an indexer, so those actions are almost instantaneous (after the indexing has completed).
Yes, Visual Studio Intellisense does just this. If your "go to definition" is taking a long time, it indicates that the project is not set up properly inside Visual Studio. You should be able to hover the mouse over a symbol (function name, variable name, etc.) and Intellisense should pop up instantly.
One cause of slow or incorrect Intellisense is creating a new project from a folder structure. If you have a bunch of .cpp and .h files in a complicated folder hierarchy, sometimes the project does not get created in a way that Intellisense can easily do symbol indexing. Also, if your project uses a lot of third party libraries, you need to make sure the header files are included in your project or else Intellisense will not be able to do anything with those symbols.

Extending a class between two Visual Studio C++ projects

Please have a look at the following diagram
This is socket programming. Server is one VS Project. Client is another VS project. But, they both extend one class!!! How can I extend a class between 2 VS applications???? Please help!
Put the base class in a header file which is visible and accessible to both projects. #include that file from those projects and extend the base class.
In Visual Studio, you can make a solution which contains projects.

Automatic generation of function stubs

Is there any Visual Studio add-on (or windows/unix stand-alone program) that creates stub implementations in the cpp file for the functions (including class member functions) that are defined in the header file?
I have the same problem before and now I am using trial version of Visual Assist X. The task mentioned can be done by right clicking on the method name -> Refactor -> Create Implementation and then Refactor -> Move Implementation to CPP file.
I am no Visual Assist X's affiliate or what, but this really increases my coding speed with Visual C++ dramatically.
Refactor! for C++ works with Dev Studio 2005 and 2008. The free version "kind-of" let's you do this; if you type your stub method in your header file (by typing something like void Foo(int bar){} instead of void Foo(int bar);) you can then "Move method to source file."
The full version has many more features but I'm not familiar with their usage.