I don't get this

This is a discussion on I don't get this within the C++ Programming forums, part of the General Programming Boards category; Code: #include "Project1App.h" #include "Project1Frm.h" #include <string> string n; IMPLEMENT_APP(Project1FrmApp) bool Project1FrmApp::OnInit() { Project1Frm* frame = new Project1Frm(NULL); SetTopWindow(frame); frame->Show(); ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    85

    I don't get this

    Code:
    #include "Project1App.h"
    #include "Project1Frm.h"
    #include <string>
    string n;
    
    IMPLEMENT_APP(Project1FrmApp)
    
    
    bool Project1FrmApp::OnInit()
    {
        Project1Frm* frame = new Project1Frm(NULL);
        SetTopWindow(frame);
        frame->Show();
        return true;
    }
    
    int Project1FrmApp::OnExit()
    {
    	return 0;
    }
    Error: 15 C:\wxdevcpp\proiecte\1st\Project1App.cpp `string' does not name a type

    I'm trying to declare a vector visible outside the wx implementation, but that did not work, so i cam back to an int. It worked, char worked, but string and any other standard class, doesn't. This is so annoying. I almost thought I got the smallest hang of C++.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,681
    Maybe std::string?
    I used to be an adventurer like you... then I took an arrow to the knee.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    85
    oh. what's std, and what does :: do?

  4. #4
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Posts
    299
    std is a namespace, which is particular to C++ and not in the C language.

    Namespaces are essentially a way to group data and functions under a unique name. This gets rid of the problem of having name collisions which are a compiler error. the std namespace incorportates functions and data from the Standard Template Library (STL). The :: operator is called the scope-resolution operator and explicity tells the compiler what class or namespace you want to use.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,023
    Instead of writing out "std::string" everytime, consider adding a line "using std::string;" at the top. Some people use "using namespace std;" to import the whole namespace, but many others don't like that idea.

  6. #6
    Registered User
    Join Date
    Aug 2007
    Posts
    85
    Hmm, sounds like a pretty smart addition to the basic C. I'll have to experiment with it. Thanks!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21