The problem is that I don't know exactly what to add a forward decleration
for.
The type that is giving the error is "std.iterator", which I assume is some
instantion of the std::iterator template, which serves as the base class for
the map classes iterator.
I tried placing a typedef in the stdafx.h file to instantiate the map
template with the paramters I use in my program like this
typedef System::Object * key_type;
typedef System::Object * data_type;
typedef ComparerPredicate< key_type > predicate_type;
typedef std::map<gcroot<key_type>, gcroot<key_type>, predicate_type>
container_type;
typedef container_type::iterator iterator_type;
however, the program still throws a TypeLoadException every time its run.
I have a class that looks like this in another file (with details removed
for clarity)....
public __gc class TreeDictionary : IDictionary_ {
public:
TreeDictionary() : pMap_(new container_type(predicate_type())){
}
//...
IDictionaryEnumerator * IDictionary::GetEnumerator() {
return new Enumerator(this);
}
private:
__gc class Enumerator_ : IDictionaryEnumerator_ {
public:
Enumerator_(TreeDictionary * dictionary) :
pDict_(dictionary),
pCur_(new iterator_type(dictionary->pMap_->begin()))
{
}
//...
private:
//..
iterator_type * pCur_;
TreeDictionary * pDict_;
};
//...
map_type * pMap_;
};
and comparer predicate defined as thus
class ComparerPredicate : public std::binary_function<T, T, bool> {
public:
ComparerPredicate() {
pComp_ = Comparer:
efault;
}
ComparerPredicate(IComparer * pComp) : pComp_(pComp) {
}
bool operator()(const T& first, const T& second) const {
return pComp_->Compare(first, second) < 0;
}
private:
gcroot<IComparer *> pComp_;
};
Running new TreeDictionary() from a C# test driver works without any
problems.
However, when I try to do
TreeDictionary t = new TreeDictionary();
foreach (DictionaryEntry de in t) {
//blaaa...
}
I receive a TypeLoadException saying that std.iterator can't be loaded.
Why does the loader have a program with TreeDictionary::Enumerator_, but not
with TreeDictionary? Both have pointers to unmanged types, so I would think
that both would either or work, or not work.
Shouldn't instantiating map in the std.afx also instantiate map::iterator,
which should inturn instantiate std::iterator?
Why don't those template instantiatons create the necessary meta data?