MFC and standard C++ - Programmer

This is a discussion on MFC and standard C++ - Programmer ; I've got two programms. One was wrote entirely using MFC and second using only standard c++. I was trying to connect those two codes, but I find it imposiible to do. Im including headers file written in C++, but I ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: MFC and standard C++

  1. MFC and standard C++

    I've got two programms. One was wrote entirely using MFC and second
    using only standard c++. I was trying to connect those two codes, but
    I find it imposiible to do. Im including headers file written in C++,
    but I can't use classes defined in those files. In example: error
    C2065: 'string' : undeclared identifier.
    I'm getting this error even if I do #include or

    Does anybody know how to solve this problem?

  2. Re: MFC and standard C++

    Xelah wrote:
    > I've got two programms. One was wrote entirely using MFC and second
    > using only standard c++. I was trying to connect those two codes, but
    > I find it imposiible to do. Im including headers file written in C++,
    > but I can't use classes defined in those files. In example: error
    > C2065: 'string' : undeclared identifier.
    > I'm getting this error even if I do #include or
    >
    > Does anybody know how to solve this problem?


    Put this in stdafx.h: #include "string"

    Then you should get no error compiling std::string members.
    To compile string declarations without the std:: you need to add:

    using namespace std;


    --
    Scott McPhillips [VC++ MVP]


  3. Re: MFC and standard C++

    "Scott McPhillips [MVP]" wrote in message news:<1-qdnYjKX8Ie9weiRVn-gQ@comcast.com>...

    >
    > Put this in stdafx.h: #include "string"
    >
    > Then you should get no error compiling std::string members.
    > To compile string declarations without the std:: you need to add:
    >
    > using namespace std;


    Thank you very much! It helped Now it works fine and I don't have
    to rewrite whole code

  4. Re: MFC and standard C++

    In article <1-qdnYjKX8Ie9weiRVn-gQ@comcast.com>,
    "Scott McPhillips [MVP]" wrote:

    > Xelah wrote:
    > > I've got two programms. One was wrote entirely using MFC and second
    > > using only standard c++. I was trying to connect those two codes, but
    > > I find it imposiible to do. Im including headers file written in C++,
    > > but I can't use classes defined in those files. In example: error
    > > C2065: 'string' : undeclared identifier.
    > > I'm getting this error even if I do #include or
    > >
    > > Does anybody know how to solve this problem?

    >
    > Put this in stdafx.h: #include "string"
    >
    > Then you should get no error compiling std::string members.
    > To compile string declarations without the std:: you need to add:
    >
    > using namespace std;


    http://www.janko.at/Humor/Computerwe...pace%20std.htm
    writes:

    Do you remember the scene in Star Trek Old Generation where they
    could not get the hatch to a grain silo open, and when Kirk finally
    opened it thousands of tribbles rained down all over him?

    Kirk represents your source file.

    The grain silo represents all the header files your source file
    includes.

    The tribbles each represents an identifier declared inside 'namespace
    std' in those headers.

    Raining down all over Kirk represents all those identifiers polluting
    your local namespace.

    'using namespace std' represents sliding the hatch open.

    The purpose of the 'namespace' keyword is to prevent this pollution. You
    must keep all the tribbles in the grain silo, and only take down the one
    or two that you need:

    using std::string;
    using std::endl;

    Folks use 'using namespace std' in this newsgroup because trivial
    example code often uses it; the code is not large enough to have
    enough of its own identifiers to potentially conflict with the 'std'
    ones. But nobody should use 'using namespace std', and those who post
    sample code to this newsgroup should set a good example.

  5. Re: MFC and standard C++

    In article ,
    oster@ieee.org says...

    [ ... ]

    > The purpose of the 'namespace' keyword is to prevent this pollution. You
    > must keep all the tribbles in the grain silo, and only take down the one
    > or two that you need:
    >
    > using std::string;
    > using std::endl;
    >
    > Folks use 'using namespace std' in this newsgroup because trivial
    > example code often uses it; the code is not large enough to have
    > enough of its own identifiers to potentially conflict with the 'std'
    > ones. But nobody should use 'using namespace std', and those who post
    > sample code to this newsgroup should set a good example.


    Strangely enough, there IS no potential conflict. Just for example, if
    you have code like this:

    namespace X {

    int i;
    };

    using namespace X;

    int i;

    There's NO CONFLICT between the two identifiers name i. When your code
    has 'using namespace X', it produces roughly the same effect as if all
    the identifiers in namespace X were introduced in the block level
    outside the one in which you're currently working (and more or less
    creates a special super-level if you're outside any blocks, like the
    code above).

    This means that if there's an identifier in the current scope that has
    the same name as one in a namespace that's being used, that the
    unqualified identifier will refer to the identifier in the current scope
    rather than the one from the namespace.

    Now, that does not mean that I particularly advocate littering your code
    with "using namespace std;" on a regular basis -- only that if you
    decide to do so, the potential for problems or conflicts is really a LOT
    smaller than many people think -- in fact, it's nearly nonexistent. IMO,
    a much better reason for avoiding it is simply that qualifying names
    tends to improve understandability. In particular, you can hijack (so
    to speak) people's existing understanding, by reusing similar names in
    your own namespaces, so in many cases they can understand your code much
    more easily than if it had to invent all new names for everything.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.

  6. Re: MFC and standard C++

    > namespace X {
    >
    > int i;
    > };
    >
    > using namespace X;
    >
    > int i;
    >


    In your example there can I still get access to the i in namespace X?

    Ali R.

    "Jerry Coffin" wrote in message
    news:MPG.1a0501a55949b389989bab@news.clspco.adelph ia.net...
    > In article ,
    > oster@ieee.org says...
    >
    > [ ... ]
    >
    > > The purpose of the 'namespace' keyword is to prevent this pollution. You
    > > must keep all the tribbles in the grain silo, and only take down the one
    > > or two that you need:
    > >
    > > using std::string;
    > > using std::endl;
    > >
    > > Folks use 'using namespace std' in this newsgroup because trivial
    > > example code often uses it; the code is not large enough to have
    > > enough of its own identifiers to potentially conflict with the 'std'
    > > ones. But nobody should use 'using namespace std', and those who post
    > > sample code to this newsgroup should set a good example.

    >
    > Strangely enough, there IS no potential conflict. Just for example, if
    > you have code like this:
    >
    > namespace X {
    >
    > int i;
    > };
    >
    > using namespace X;
    >
    > int i;
    >
    > There's NO CONFLICT between the two identifiers name i. When your code
    > has 'using namespace X', it produces roughly the same effect as if all
    > the identifiers in namespace X were introduced in the block level
    > outside the one in which you're currently working (and more or less
    > creates a special super-level if you're outside any blocks, like the
    > code above).
    >
    > This means that if there's an identifier in the current scope that has
    > the same name as one in a namespace that's being used, that the
    > unqualified identifier will refer to the identifier in the current scope
    > rather than the one from the namespace.
    >
    > Now, that does not mean that I particularly advocate littering your code
    > with "using namespace std;" on a regular basis -- only that if you
    > decide to do so, the potential for problems or conflicts is really a LOT
    > smaller than many people think -- in fact, it's nearly nonexistent. IMO,
    > a much better reason for avoiding it is simply that qualifying names
    > tends to improve understandability. In particular, you can hijack (so
    > to speak) people's existing understanding, by reusing similar names in
    > your own namespaces, so in many cases they can understand your code much
    > more easily than if it had to invent all new names for everything.
    >
    > --
    > Later,
    > Jerry.
    >
    > The universe is a figment of its own imagination.




  7. Re: MFC and standard C++

    In article ,
    nospam@mail.com says...
    > > namespace X {
    > >
    > > int i;
    > > };
    > >
    > > using namespace X;
    > >
    > > int i;
    > >

    >
    > In your example there can I still get access to the i in namespace X?


    Yes -- X::i refers to the i in namespace X, but i by itself refers to
    the one that's not in the namespace.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.

  8. Re: MFC and standard C++

    > But nobody should use 'using namespace std', and those who post
    > sample code to this newsgroup should set a good example.
    >


    Is there some reason behind this dogma other than analogies to Star Trek?

    I routinely rip out std:: in code I'm maintaining and replace with "using
    namespace std". Reduces visual pollution. I wouldn't do this if there were
    some valid articulated reason, but Google searches always turn up circular
    arguments.

    --
    Jim Johnson

  9. Re: MFC and standard C++

    On Mon, 17 Nov 2003 09:02:13 -0800, jamos@technotoys.com (Jim Johnson)
    wrote:

    >Is there some reason behind this dogma other than analogies to Star Trek?
    >
    >I routinely rip out std:: in code I'm maintaining and replace with "using
    >namespace std". Reduces visual pollution. I wouldn't do this if there were
    >some valid articulated reason, but Google searches always turn up circular
    >arguments.


    There's nothing wrong with "using namespace std" in your .cpp files
    *after* you've included all your headers. Using the directive in header
    files *is* a very bad idea and should be avoided, since it has the
    potential to break other unrelated header files. See this link:

    http://cpptips.hyperformix.com/cpptips/migrate_using

    Jon


+ Reply to Thread