Thread: Class error/query

  1. #1
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118

    Class error/query

    I thought I was starting to understand classes, but this error has been bugging me and I can't figure out what the problem is. Obvisouly I don't understand them as well as I thought I did ^_^. Here's a simple class attempt which returns the same error when I try to compile it

    Code:
    #ifndef MYCLASS_H
    #define MYCLASS_H
    
    class MyClass
    {
          private:
                  std::string a;
           public:
                  MyClass();
                  MyClass( std::string a_ );      
    };
    
    #endif
    Code:
    #include "myclass.h"
    
    MyClass::MyClass()
    {
             a = "Hello";        
    }
    
    MyClass::MyClass( std::string a_ )
    {
                      a = a_;                  
    }
    Code:
    #include "myclass.h"
    
    int main()
    {
        return 0;    
    }
    Here is the first error msg I get, I'm pretty sure I only need to fix one thing to get rid of the other messages

    7 C:\Dev-Cpp\Projects\myclass.h using-declaration for non-member at class scope
    My guess is that it's got something to do with "std::string", but that's just a guess, the truth is I don't really know

    Kind Regards

    Stonehambey

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, myclass.h should include <string> - that way, you can use std::string there.

    Edit: I must say that the error-message isn't exactly the most obvious ones for this type of error.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118
    Quote Originally Posted by matsp View Post
    Yes, myclass.h should include <string> - that way, you can use std::string there.
    lol, of course *facepalm*

    Thanks dude

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  3. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM