Thread: Pair as a member of a class

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    3

    Pair as a member of a class

    Hey there,
    I am using Eclipse CDT on Linux (Ubuntu) and encountering a strange error.

    This is my C++ header file:
    Code:
    class A {
    public:
        A(int x, int y, bool direction);
        virtual ~A();
    
    private:
        pair <int, int> m_pair_int;
        bool m_direction;
    };
    The implementation of the ctor and dtor is done at the cpp file and irrelevant in this post.

    When compiling this code, I get the following error messages:
    expected `;` before `<` token
    ISO C++ forbids declaration of `pair` with no type
    all these errors are pointing to the line where `pair <int, int> m_pair_int;` is.

    Thanks in advance

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Did you include the proper include file that defines pair?

    Did you properly scope this standard class?

    Jim

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Also, given that putting using namespace std; inside a header file is a big no-no (bad practice), you'd better qualify pair with std::
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Jan 2013
    Posts
    3
    Thank you both!!! I did miss these details (including utility and adding `std::` at the beginning of `pair`).


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-18-2012, 11:17 AM
  2. Can Nested class access parent class's private member?
    By meili100 in forum C++ Programming
    Replies: 4
    Last Post: 06-05-2009, 08:42 AM
  3. Replies: 25
    Last Post: 10-29-2007, 04:08 PM
  4. derived class can not access base class protected member?
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2007, 06:32 PM
  5. Class member variables only readable by member functions?
    By _Elixia_ in forum C++ Programming
    Replies: 4
    Last Post: 10-10-2003, 03:52 PM