Having trouble creating a class in c++ - visual-c++

The problem I'm having seems to be that C++ doesn't like me inserting either or into my class. Part of the problem might be that I'm flipping back and forth between Visual Studio 2010 at my house and Visual Studio 2012 on the school computers (to clarify, this is just something I'm writing for fun, not as a school project). Even when I comment out the parts of the program that deal with the string, c++ still doesn't recognize "cout" or "endl", which is frustrating. Spellcheck seems to be wigging out on me, especially when it comes to #ifndef and #endif. Pastebin contains both the class itself and the error message I get when I try to build it.
Class/errors

Compiler does not recognize string so it throws a tantrum. There's std::string though. If this is just one .cpp file the simplest would be to place using namespace std; after the last include.
More proper solution (that you should use in big projects) is to put std:: everywhere it needs to be put (std::string, std::cout...).

Related

Cannot open include file 'rpcerr.h': No such file or directory

I was happily compiling and running source code today. Then I added a few lines to one of my modules, and suddenly Visual Studio 2012 refused to compile the code, with the error message:
error C1083: Cannot open include file: 'rpcerr.h': No such file or directory.
I'm not sure why the compiler suddenly needs to find rpcerr.h. I'm not doing anything I wasn't doing yesterday, but now I can't make the error go away.
I also have not been able to find rpcerr.h, myself. The reference is in rpc.h, which is part of the Visual Studio library. I'm guessing it got linked in because I included <windows.h>. But I don't know where I can find rpcerr.h, or what this file is supposed to do.
I would really like to go forward with this development. I'm guessing the code tried to compile rpcerr.h for a good reason, and that if I'm going to be using rpc.h for whatever reason this gets compiled into my source code, then I should get rpcerr.h as well. But trying to find it is sending me into a mobius loop.
Currently, the compiler is only complaining about rpcerr.h.
I'd better write this up, this is bound to happen again sooner or later. The <rpc.h> SDK file is stone cold old and dates back to the days that Microsoft supported writing code for an Apple Macintosh. It still supports it, there's an #include for rpcerr.h. But that file is no longer supplied, only rpcnterr.h is available.
You need to scan your source, or recently added #includes, for the a #define for MAC or _MAC, the one that Microsoft uses to select a Macintosh target. Using the editor's "Go To Definition" context menu command is the easiest way.
Or use this as a workaround:
#undef MAC
#undef _MAC
#include <rpc.h>
Or change the order of #includes. Beware that these workarounds might have side-effects, depending on how the other definition is used.

How to get XML comments to appear in Visual Studio Class Wizard decriptions

I have put XML comments in a C++ source file that IntelliSense appears to pick up and use. It creates a project xml file, and IntelliSense works when I edit the original source file (showing me comments when I'm selecting a member function or entering parameters).
But, when I go to the Class Wizard in Visual Studio 2012 Express, the entered descriptions don't appear anywhere (on the methods, for example, down at the bottom of the dialog, where description remains sadly empty). For that matter, IntelliSense only works in the original file(s), so when using a call in a separate file, none of my XML comments get picked up. Why does it only work in the original source file? What have I neglected to do?
I don't think you've neglected to do anything, unfortunately.
The Class Wizard was built long before Visual Studio supported XML doc comments, so it's more likely that no one remembered/cared to go back add support for them to the Class Wizard dialog.
In my experience, although it sounds like you've had slightly better luck, XML doc comments are not particularly well supported when using C++. For example, VS 2012 was the first version to support them in IntelliSense (and even that is incomplete). You get nothing in VS 2010 and earlier versions, despite the fact that they'll happily output a project XML file. That pathetic lack of support, combined with the angle bracket tax, drove me to switch to Doxygen when writing C++ code.

Visual C++ Form Designer is replacing all my "new" with "gcnew"

I have inherited a Visual C++ project with about four thousand lines of code in a single file. The code compiles great with /clr:oldSyntax but when I change anything in the designer, it updates it to the new syntax and then everything breaks.
How do I keep the designer from converting my code to the new syntax (gcnew et al)? If this isn't possible, what's the quickest way to convert the entire project at once to the new syntax?
Unfortunately, this is not possible. The Windows Forms designer stopped supporting the old managed C++ syntax back in version 2003. You'll have to either revert back to that version of Visual Studio for maintenance of this code base, or bite the bullet and convert the project to use the new C++/CLI syntax.
I don't know if you're going to find much in the way of an automated solution for converting from managed C++ to C++/CLI. You might start looking in the answers to this question.
In my personal experience/opinion, the designer is more trouble than it's worth when working in C++/CLI. I would strongly consider making the necessary modifications to your form classes by hand and not letting the designer bungle your code in the first place. "If it ain't broke, don't fix it."

Is there a way in Visual Studio to specify what a template class (new class) is going to look like?

I'm a long time Eclipse user trying to learn to Visual Studio. I know that Eclipse had Code Templates that would allow you to build classes with certain comments and formatting already added for a class.
For example:
Auto placing the copyright for the code at the top of the file
Who created the file
Predefined Comments,
etc...
Does Visual Studio 2005 have any functionality like this?
It depends. Visual Studio has a built-in code snippets manager that lets you do things like this to at least a degree (i.e., if you insert a code snippet, it'll be formatted as the snippet specifies, but if you write the same code manually, it won't). Also note that there are limitations on the languages with which you can use code snippets.
Outside of that, most of the major add-ins for VS (e.g., Visual Assist-X) provide their own ability to store and insert bits of code, formatted as you specify. Most of these provide at least some features missing from the built-in snippets manager such as working with other languages or being easier to access (along with quite a few other things -- IMO, VS borders on completely unusable without VA-X).
I would recommend looking at item and project templates in Visual Studio, which sound like what you're looking for. But, in your particular case (C++ development), it doesn't look like this is available to you.
The following MSDN article refers to VS templates, and mentions that for Visual C++ projects, that the template architecture isn't supported. Instead, there's information on creating custom wizards for your project and classes, which may give you the flexibility that you need. Sounds like it'll do what you want it to do, but it's much more work than it would be if you could use an item template for including basic comment structure for a default class file.
http://msdn.microsoft.com/en-us/library/6db0hwky%28VS.80%29.aspx

C++ ODBC problem with sqlucode.h header

I found a great C++/ODBC example here...
The project I downloaded builds great and everything works. However, when I copy the .cpp and .h files into another project, I seem to have a linking problem.
The SQLConnect function in sql.h is the one I want. When I right-click this function in the easyodbc.h file in the project I downloaded, it jumps to the declaration in sql.h. Life is good.
However, in the project I created, when I do this it jumps to a UNICODE definition in sqlucode.h. This seems to be causing problems and my test project crashes.
I don't have an #include for sqlucdode.h anywhere in my project, yet it still resolves the declaration to the one in sqlucode.h. How can I prevent this? Thanks.
Seems like you have a preprocessor problem rather than a linking problem.
You probably have a preprocessor definition for UNICODE (or _UNICODE) in your project file. In Visual C++ 2005 and 2008 you can fix this by going to your project properties and changing Character Set from Use Unicode Character Set to Use Multi-Byte Character Set. When you apply this setting, Visual Studio fixes up the right preprocessor and linker settings for you.
If you have an earlier version of Visual Studio you can still fix it by changing the preprocessor definitions for UNICODE and _UNICODE to _MBCS - it's just you'll have to find them yourself.
EDIT: I just downloaded that example code and tried it - good news, it's exactly as I guessed, change to a multibyte character set and you'll be fine.

Resources