J
Joe Carner via .NET 247
First time posting, thanks in advance for any help you can give me.
Basically I am trying to a class that i want to be able to access the private data members of another class, both of which i created.
But, I can't get the friend class to work. For example (this is not actually my code):
template <typename Key, typename Value> class MyMap;
template <typename Key, typename Value> struct MyMapNode;
class MyIterator {
friend class MyMap<Key, Value>;
public:
?
?
?
private:
pair<Key, Value> * pointee;
MyMapNode<Key, Value> * nodee;
MyIterator(pair<Key, Value> *pointee = NULL, MyMapNode<Key, Value> *nodee = NULL) : pointee(pointee), nodee(nodee) {}
};
template <typename Key, typename Value>
class MyMap {
public:
typedef MyIterator<Key, Value> iterator;
typedef MyIterator<Key, Value> const_iterator;
?
};
Given that, the following line doesn?t work in a test file:
#include "TheHeaderFileWithTheStuffIPutAbove.h"
...
MyMap<string, int>::iterator iter;
which is to say, i can't create any instance of iterator because the constructor is private (though it is supposed to be a friend)
i get an error about how the constructor can not be accessed because it is private.
This problem has been plaguing me for a long time. Any help would be appreciated.
Basically I am trying to a class that i want to be able to access the private data members of another class, both of which i created.
But, I can't get the friend class to work. For example (this is not actually my code):
template <typename Key, typename Value> class MyMap;
template <typename Key, typename Value> struct MyMapNode;
class MyIterator {
friend class MyMap<Key, Value>;
public:
?
?
?
private:
pair<Key, Value> * pointee;
MyMapNode<Key, Value> * nodee;
MyIterator(pair<Key, Value> *pointee = NULL, MyMapNode<Key, Value> *nodee = NULL) : pointee(pointee), nodee(nodee) {}
};
template <typename Key, typename Value>
class MyMap {
public:
typedef MyIterator<Key, Value> iterator;
typedef MyIterator<Key, Value> const_iterator;
?
};
Given that, the following line doesn?t work in a test file:
#include "TheHeaderFileWithTheStuffIPutAbove.h"
...
MyMap<string, int>::iterator iter;
which is to say, i can't create any instance of iterator because the constructor is private (though it is supposed to be a friend)
i get an error about how the constructor can not be accessed because it is private.
This problem has been plaguing me for a long time. Any help would be appreciated.