Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / July 2006

Tip: Looking for answers? Try searching our database.

C++, unmanaged code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill S. - 06 Jul 2006 20:20 GMT
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;
   }
};
Debasish Bose, Oracle Corp - 07 Jul 2006 11:08 GMT
Use gcroot<> instead.

> Dear programmers, I'm experimenting with a simple unmanaged template class.
> The problem is that it won't except managed types. Any suggestions?
[quoted text clipped - 72 lines]
>     }
> };

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.