Thread: I don't get this

  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,817
    Maybe std::string?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  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
    Location
    CA, USA
    Posts
    466
    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,229
    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