CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2010
    Posts
    7

    Post string not included error

    Code:
    #ifndef LINES_H_INCLUDED
    #define LINES_H_INCLUDED
    #include <string>
    
    
    /** @file Lines.h */
    
    typedef string ListItemType;
    /** class Lines*/
    
    class Lines
    {
         private:
    
        /** A node in the list*/
        struct Node
        {
            ListItemType item;
    
            Node *next;
    
            int lines;
        };
        Node *head;
    
        public:
    
        /** Default Constructor*/
        Lines();
    
        /** Copy Constructor*
         * @param line = The list to copy*/
        Lines(const Lines& line);
    
        /** Destructor */
        ~Lines();
    
        //List operations
        void insert(int index, const ListItemType& newItem);
        void remove(int index);
        void copy(int index, ListItemType& dataItem) const;
        void cut(int index,ListItemType& dataItem);
    
    
    
    
    };
    
    
    
    
    
    
    #endif // LINES_H_INCLUDED
    This is the header file for a link list, when i try to compile this, it produces an error stating "string is not included"
    when i change the string to => typedef char ListItemType
    there's no problem...

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: string not included error

    In an h file, you need to fully quality it as std::string.

  3. #3
    Join Date
    Jan 2009
    Posts
    1,689

    Re: string not included error

    or specify namespace std, but Lindley's way is prefered

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: string not included error

    Quote Originally Posted by ninja9578 View Post
    or specify namespace std, but Lindley's way is prefered
    It's not a good idea to specify a "using" statement in a header file (at least, in an unrestricted scope) because that defeats the purpose of namespaces.

  5. #5
    Join Date
    Jan 2009
    Posts
    1,689

    Re: string not included error

    Hense why I said your way is preferred, but you can.

  6. #6
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: string not included error

    I figured that, but I wanted the reason for it on the record.

Tags for this Thread

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