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.iterat or", 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 ComparerPredica te< 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 TypeLoadExcepti on 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( ))){
}
//...
IDictionaryEnum erator * IDictionary::Ge tEnumerator() {
return new Enumerator(this );
}
private:
__gc class Enumerator_ : IDictionaryEnum erator_ {
public:
Enumerator_(Tre eDictionary * dictionary) :
pDict_(dictiona ry),
pCur_(new iterator_type(d ictionary->pMap_->begin()))
{
}
//...
private:
//..
iterator_type * pCur_;
TreeDictionary * pDict_;
};
//...
map_type * pMap_;
};
and comparer predicate defined as thus
class ComparerPredica te : public std::binary_fun ction<T, T, bool> {
public:
ComparerPredica te() {
pComp_ = Comparer::Defau lt;
}
ComparerPredica te(IComparer * pComp) : pComp_(pComp) {
}
bool operator()(cons t T& first, const T& second) const {
return pComp_->Compare(firs t, second) < 0;
}
private:
gcroot<ICompare r *> pComp_;
};
Running new TreeDictionary( ) from a C# test driver works without any
problems.
However, when I try to do
TreeDictionary t = new TreeDictionary( );
foreach (DictionaryEntr y de in t) {
//blaaa...
}
I receive a TypeLoadExcepti on 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?
"Donna Gresh" <gr***@us.ibm.c om> wrote in message
news:aa******** *************** ***@posting.goo gle.com...
"Scott Wisniewski" <sc******@uwm.e du> wrote in message
news:<eO******* *******@TK2MSFT NGP10.phx.gbl>. ..
I am attempting to write a class to expose the STL map class to .NET
languages as an IDictionary. As part of the implementation I created an
implementation of IEnumerator that contains a pointer to an iterator.
However any calls to the enumerators constructor result in a
TypeLoadExcepti on being thrown, stating that the type "std.iterat or"
can't be found in the assembly.
Does anyone know:
1) What is causing this exception to be thrown?
2) Is there any way to get around it?
Thanks
Scott Wisniewski
I don't know if you have the same problem I did, but yesterday I
solved mine using the information given here regarding forward
declarations:
http://www.winterdom.com/mcppfaq/archives/000262.html