RE: C++, unmanaged code
- From: Debasish Bose, Oracle Corp <DebasishBoseOracleCorp@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 7 Jul 2006 03:08:01 -0700
Use gcroot<> instead.
"Bill S." wrote:
Dear programmers, I'm experimenting with a simple unmanaged template class..
The problem is that it won't except managed types. Any suggestions?
void MyFunc()
{
//This works fine.
XStack<int>* uc = new XStack<int>();
//This doesn't work!
XStack<ManagedClass*>* uc = new XStack<ManagedClass*>();
}
//Unmanaged Class ////////////////////
template<class Type> class XStack
{
private:
typedef struct StackNode{
Type Data;
StackNode *Next;
}mNode;
bool mEmpty;
int mSize;
mNode *mHeader;
public:
XStack()
{
mEmpty = true;
mSize = 0;
mHeader = new mNode;
mHeader->Data = 0;
mHeader->Next = 0;
}
~XStack()
{
while( !mEmpty ){
Pop();
}
//delete mHeader; //?
}
bool empty() const
{
return mEmpty;
}
int size() const
{
return mSize;
}
Type Pop()
{
if( !mEmpty ){
mNode *tmp = mHeader->Next;
mHeader->Next = tmp->Next;
mEmpty = (mHeader->Next == 0);
mSize--;
Type data = tmp->Data;
//delete tmp; //?
return data;
}
}
void Push( Type data )
{
mEmpty = false;
mSize++;
mNode *tmp = new mNode;
tmp->Data = data;
tmp->Next = mHeader->Next;
mHeader->Next = tmp;
}
};
- References:
- C++, unmanaged code
- From: Bill S.
- C++, unmanaged code
- Prev by Date: RE: OptionalFieldAttribute not needed with BinaryFormatter in .net v2.
- Next by Date: RE: OptionalFieldAttribute not needed with BinaryFormatter in .net v2.
- Previous by thread: C++, unmanaged code
- Next by thread: RE: OptionalFieldAttribute not needed with BinaryFormatter in .net v2.
- Index(es):