Re: Getting Started w/ Standard C++ in Microsoft VC++ 6.0?
From: Daniel James (wastebasket_at_nospam.aaisp.org)
Date: 01/06/05
- Next message: Frank Hickman [MVP]: "Re: about toolbar and taskbar"
- Previous message: Frank Hickman [MVP]: "Re: CreateStatic and CreateView"
- In reply to: Bill Hoy: "Getting Started w/ Standard C++ in Microsoft VC++ 6.0?"
- Next in thread: Bill Hoy: "Re: Getting Started w/ Standard C++ in Microsoft VC++ 6.0?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 06 Jan 2005 11:25:39 GMT
In article news:<41DC0AB5.8923FF67@eaw.com>, Bill Hoy wrote:
> I have a few years of experience using MFC and Microsoft Visual C++
> 6.0. As my company gets further into the software business they now
> want to start moving away from MFC, and use pure Standard C++.
Standard C++ is good - especially for back-end program logic - but MFC
makes programming for the Windows API *much* easier than using the API
directly.
I would start by separating the program into "GUI" and "back end"
subsystems and rewrite the "back end" system in standard C++. I wouldn't
even think about translating the "GUI" component, it's just not worth the
bother.
If you want to rewrite the GUI -- and I do mean "rewrite" not "translate"
-- so that your application will be portable to non-Windows systems you
should look at cross-platform toolkits such as wxWidgets (free, open
source) or Qt (commercial, free for open source projects on open source
platforms but damned expensive on Windows). Once your "back end" subsystem
is in standard C++ you should be able to use it with such a GUI toolkit
without further change.
> I see that I will have to use: "using namespace std" ...
You don't have to write "using namespace std" anywhere. That's a notational
convenience which may save some typing and make some of your sourcecode
cleaner, but many autorities on C++ say you should prefer explicit
qualification to "using".
That is, you should write:
std::cout << "Hello world" << std::endl;
rather than:
using namespace std;
cout << "Hello world" << endl;
because that makes it explicit *which* cout and *which* endl (and which
operator<<, too) you mean, and removes any possibility of ambiguity if you
include files that define other objects with the same names.
Better than "using namespace ..." is to explicitly declare namespace
objects to be used, like this:
using std::cout;
using std::endl;
cout << "Hello world" << endl;
"using namespace ..." can sometimes be the neatest way to write code, but
even then you must be aware of the potential for ambiguity that this
pollution of the global namespace introduces, and you should try to contain
its effects as much as possible (for example, by placing the "using"
declaration inside a specific function where you want its effects, rather
than at file scope). Above all never, ever, place a "using namespace ..."
directive in a header file.
For more discussion of this point see the last couple of sections of Herb
Sutter's "More Exceptional C++" (Addison Welsey).
> But I am not sure what else I have to set up in the Microsoft Developer
> Studio. Perhaps I have to start a new project/workspace that is just a
> W32 Application? What do I need to link to in the Project Settings >
> Link tab? What else do I need to do to so that it recognizes the
> namespace "std" ?
The only thing you have to do to get the compiler to recognize the std
namespace is include a header that declares something in that namespace.
The namespace keyword is part of the C++ language. You don't need to have a
special kind of project or a special kind of sourcefile - I use the
standard library in MFC projects all the time. It Just Works.
If you want to create a project that doesn't use MFC at all you can just
create a new project for either a "Win32 application" or a "Win32 comsole
application" (in VC6) and the standard library will be available.
You should be aware, though, that the VC6 compiler is now quite old, and
that it was released before the C++ standard was finalized. There are
things in the standard language that VC6 doesn't support and things in the
standard library that VC6 can't support correctly. If these things start to
become a problem then you should consider using VC7.1 (VS2003) which is a
*much* more standard-compliant compiler.
Cheers,
Daniel.
- Next message: Frank Hickman [MVP]: "Re: about toolbar and taskbar"
- Previous message: Frank Hickman [MVP]: "Re: CreateStatic and CreateView"
- In reply to: Bill Hoy: "Getting Started w/ Standard C++ in Microsoft VC++ 6.0?"
- Next in thread: Bill Hoy: "Re: Getting Started w/ Standard C++ in Microsoft VC++ 6.0?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|