CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Nov 2007
    Posts
    1

    Private data member problems

    I was working on a class for the first time the other day and could not get anything but built in data types to work as private data members. I tried creating a test program with the bare minimum code and still could not get it to work. my error is:

    'string' does not name a type

    I'm sure there is something simple that I'm missing, but what is it?

    here's what i tried:
    //---------------------------------------
    specification file "Problem.h"
    //---------------------------------------
    class SimpleClass
    {

    public:
    SimpleClass();
    private:
    string test; //this line is where i get the mentioned error

    };

    //-----------------------------------------
    implementation file "Problem.cpp"
    //-----------------------------------------
    #include <cstdlib>
    #include <iostream>
    #include <string>
    #include "Problem.h"

    using namespace std;

    SimpleClass::SimpleClass()
    {
    test="bob";
    cout<<test;
    }

    //---------------------------------------
    main file "main.cpp"
    //---------------------------------------

    #include <cstdlib>
    #include <iostream>
    #include <string>
    #include "Problem.h" //compiler highlights this line

    using namespace std;

    int main()
    {
    SimpleClass ();

    system("PAUSE");
    return 0;
    }
    Last edited by jrw10293; November 20th, 2007 at 07:37 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured