Automatic generation of function stubs - c++

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.

Related

How to view library functions of c++ in visual studio?

Without downloading or accessing the internet, is there a way to view all library functions in visual studio? Let's say i forgot what the sort() function is named as, but i know it is in "algorithm.h"; Without opening the header file itself, does visual studio offer a cleaner way of viewing those functions?

How to see the implement of standard library of C/C++ by VisualStudio?

I want to see the implement details of some functions like "strcmp strcpy atoi" by VisualStudio
I press F12 or jump to definition
But I just can see the code below can not see the implement details
_Check_return_ int __cdecl strcmp(_In_z_ const char * _Str1, _In_z_ const char * _Str2);
How to see the implement of standard library of C/C++ by VisualStudio?
Express edition users don't have access to the source code. But the Community edition includes it, if you don't want to spend money.
You can find it after the installation in: %VCINSTALLDIR%\crt\src. If you don't want to navigate to the folder manually, open the Developer Command Prompt and then execute explorer %VCINSTALLDIR%\crt\src.
Debugging your program and stepping into such functions should also work as Visual Studio then opens the source file with the implementation. That's mostly why VS ships with it.
But this isn't all the source code. Mathematical functions (what's known as libm in the *nix world) are not included. You also can't just build it.

MS Studio 2012 - How to make it behave more like Netbeans/Java?

I started yesterday on learning C++ with Microsoft Visual Studio 2012. I have a background of 1-2 years with Netbeans and Java, and I use the code completion features a lot.
So I got a few questions here for MS Studio 2012:
In Netbeans you can alt+I to fix imports, what is Studio counterpart?
In Netbeans/Java if you type File file = new File(); and then press alt+I, it will automatically add import java.io.File;
I am really stunned by the following thing though in MS Studio 2012, which I would like to solve:
In the first "Hello World!"-tutorial I have to write to the console using cout << "Hello World!", so I typed that... But it did not give me any option to automatically do using namespace std; and/or #include <iostream>.
Is there a way to make whole MS Studio 2012 behave as closely as possibly to what I have been used in Netbeans/Java?
First of all, C++ is not Java, and #includes are not imports. The IDE can not know in which headers the classes and functions you want to use are declared/defined. To do that, it would have to parse any header inside the include path. And since per sé any file can be used as a header, i.e. can be included, it would have to (try to) parse any file in the whole include path.
Again, C++ is not Java, so compared to Java C++ has some strengths and weaknesses. One of the latter is the need to manage your includes manually.
Update: As has been noted by Martin Ba, there are tools that can give you assistance on a set of classes, e.g. classes from common libraries like the standard library and the classes defined inside your VS project, but those are third party tools and have to rely on manually managed databases that would need to be extended in order for the feature to work properly in the presence of other libraries.
tl;dr you can't get the automatic import for everything in C++
The refactoring support of VS cannot do this.
However, there is 3rd party Software - Visual Assist X - that has the ability to try to include the right header file for a certain symbol. See: Auto Using and Add Include Directives
The problem for your context would be that it is commercial software that you also can only use with a pay-for non-express version of VS.

Ensuring VS 2008 is treating my project as C++ rather than C++/CLI

I'm working in Visual Studio 2008 with native C++.
A colleague wrote a library, and he named one of his classes interface. Here's a constructor:
template <typename DtedInterface>
interface<DtedInterface>::interface (
std::string const& tleFile,
std::string const& dtedDir,
dted::DtedLevel const& dtedLevel,
double sw_latitude,
double sw_longitude,
unsigned int rows,
unsigned int columns )
: m_impl ( new interface_impl<DtedInterface> ( theFile, dtedDir, dtedLevel, sw_latitude, sw_longitude, rows, columns ) )
{}
What concerns me is that Visual Studio 2008 is highlighting the word interface as a keyword; interface is a keyword within C++/CLI but not C++. This doesn't look like it would be valid C++/CLI, but it's fine for native C++.
Things look like they compile fine, but how do I make sure that Visual Studio is interpreting this as C++ rather than C++/CLI? At some level, it appears that VS views this as C++/CLI. Is it just a keyword highlighting setting?
The Visual Studio IDE and the Visual C++ compiler are two separate entities. Specifically, they are two separate executables (devenv.exe for the IDE and cl.exe for the compiler) that run as separate processes. The IDE simply spawns the cl.exe process to perform the actual compilation.
The IDE has a list of keywords somewhere that simply tells the text editor which words to highlight. It isn't super sophisticated; it doesn't have to be. The compiler has the final say, not the syntax highlighter (or Intellisense for that matter).
As long as the /clr switch is not being passed to the cl.exe process, the compiler will compile the code as native C++ (which is the default setting). The IDE simply feeds in the file paths of your source code and the compiler switches as command-line arguments to the cl.exe process. The syntax highlighting has no bearing on how the compiler interprets the code.
The code will refuse to compile if you're in C++/CLI, so as long as you push "build" and it works, then you know you're in native. There are also pre-defined macros for CLR builds.
If you're really need to verify it's not compiling managed C++, look at the project properties and check the "Common Language Runtime support" setting under the Configuration Properties->General. As well for each file's properties under Configuration Properties->C/C++->General check the "Compile with Common Language Runtime support" setting. If all of those are set to "No Common Language Runtime support", the project is not managed C++.

creating a DLL in Visual Studio 2005

I am developing a C++ library that I want to pass on to my team. The library has just one class with a bunch of methods.
So, I have developed the class definition file (X.cpp) and a corresponding class declaration file (X.h).
Here are my questions --
In Visual Studio 2005, whats is the most straight forward way to build this library as a DLL, such that I get the following files:
X.lib : which I can pass to my team so they can link against my library
X.dll : which I can pass to my team for run-time
Instead of a DLL, should I rather be going the static library way ?? If so, how do I go about doing this in Visual Studio 2005 & will this give me a X.lib file that I can pass on to my team ?
Any explanations or references are very welcome.
Thank you very much.
The easiest way to build a DLL, is New->Project->Win32 Console Application. Then on the dialog select DLL and select "Exports Symbols". This will synthesize a dll with a .h, and .cpp file which demonstrate how to export your classes. You can get rid of this .h/.cpp but first import your class add the appropriate #ifndef statements. Now as far as DLL versus Static library if its a single small class, that doesn't change particularly often you might be better off with a static library, its simple, its concise, it doesn't add another dependency which needs to be shipped with your product. A DLL is nice if the code in the .cpp file changes often (ie. the function implementations) because you can just swap in the new DLL.
From your description, it looks like you already have a Visual C++ project (correct me if I'm wrong). If so, when you go into project properties, under "General" you can find "Configuration Type" - switch it to "Static library" or "Dynamic library" as needed.
If you choose "Static library", then you will just get a .lib file that can be immediately used.
If you choose "Dynamic library", and you export any functions from your DLL (e.g. by marking them with __declspec(dllexport)), an export .lib will be generated automatically.
It's hard to tell which option is preferable without knowing the specifics of what you're doing. In general, I'd recommend defaulting to static libraries, because it's usually good enough, and there are more traps when dealing with DLLs (especially ones that export C++ symbols).
I think that, in most cases, a dll is a better choice than a static lib because your team will not have to recompile their code when you distribute a new version of your library.
I struggle with this too sometimes.. because I can't find where the elusive setting is within C++ Project Properties.. So I decided to jot it down for my own sanity as a blog post.
HTH