Internal class and access to external members.

Posted by Knowing me knowing you on Stack Overflow See other posts from Stack Overflow or by Knowing me knowing you
Published on 2010-04-17T18:12:38Z Indexed on 2010/04/17 18:23 UTC
Read the original article Hit count: 304

Filed under:
|

I always thought that internal class has access to all data in its external class but having code:

template<class T>
class Vector
{
 template<class T>
 friend
std::ostream& operator<<(std::ostream& out, const Vector<T>& obj);
private:
 T** myData_;
 std::size_t myIndex_;
 std::size_t mySize_;
public: 
 Vector():myData_(nullptr),
  myIndex_(0),
  mySize_(0)
 { }
 Vector(const Vector<T>& pattern);
 void insert(const T&);
 Vector<T> makeUnion(const Vector<T>&)const;
 Vector<T> makeIntersection(const Vector<T>&)const;
 class Iterator : public std::iterator<std::bidirectional_iterator_tag,T>
 {
 private:
  T** itData_;
 public:
  Iterator()//<<<<<<<<<<<<<------------COMMENT
  { /*HERE I'M TRYING TO USE ANY MEMBER FROM Vector<T> AND I'M GETTING ERR SAYING:
   ILLEGAL CALL OF NON-STATIC MEMBER FUNCTION*/}

  Iterator(T** ty)
  { 
   itData_ = ty;
  }

  Iterator operator++()
  {
   return ++itData_;
  }

  T operator*()
  {
   return *itData_[0];
  }

  bool operator==(const Iterator& obj)
  {
   return *itData_ == *obj.itData_;
  }

  bool operator!=(const Iterator& obj)
  {
   return *itData_ != *obj.itData_;
  }

  bool operator<(const Iterator& obj)
  {
   return *itData_ < *obj.itData_;
  }
 };

 typedef Iterator iterator;

 iterator begin()const
 {
  assert(mySize_ > 0);
  return myData_;
 }

 iterator end()const
 {
  return myData_ + myIndex_;
 }
};

See line marked as COMMENT.
So can I or I can't use members from external class while in internal class?
Don't bother about naming, it's not a Vector it's a Set.
Thank you.

© Stack Overflow or respective owner

Related posts about c++

Related posts about internal-class