Simple stack code


We’ve got a code sample today, of a simple integer stack implemented using Whidbey
C++.  I’ll implement it using three pieces of code:

  • stack.h – definition of the stack
  • stack.cpp – implementation of the stack
  • main.cpp – driver program that makes use of the stack

I compile the stack class into a DLL (stack.dll), which I then import into the main
program with #using.  The beauty of stack.dll is that it should be consumable
by any .NET-targeted language: C#, VB.NET, even ASP.NET.  In fact, to prove this,
I’ve also included drv.cs, a C# source file which consumes stack.dll.

Another benefit of using DLLs: during development, I found a bug in my stack program. 
I edited stack.cpp, recompiled the DLL, and ran main.exe again.  I didn’t need
to recompile main! 🙂

To compile:

  • stack.cpp as a DLL: cl /clr:newSyntax /LD stack.cpp
  • main.cpp: cl /clr:newSyntax main.cpp
  • drv.cs: csc drv.cs /r:stack.dll

Get the files!  The code is available as a zip file: stack.zip.

Comments (12)

  1. Anonymous says:

    I am a MVP in vc++ and I am interested in this sample.but I felt very sorry that I cannot download it,can you change the download location so that I can get the whole source

  2. Anonymous says:

    Sorry! I’ve updated the link so it points to a location that should stay valid longer. Thanks for letting me know.

  3. Anonymous says:

    thanks for your great job.

  4. Anonymous says:

    i want simple stack for posfix

  5. Anonymous says:

    i want simple code of stack please send me

  6. Anonymous says:

    i want simple code of stack please send me

  7. Anonymous says:

    i want stack array and linked lis stack thank you …

  8. Anonymous says:

    i want stack array and linked lis stack thank you …

  9. Anonymous says:

    We’ve got a code sample today, of a simple integer stack implemented using Whidbey C++.  I’ll implement it using three pieces of code: stack.h – definition of the stack stack.cpp – implementation of the stack main.cpp – driver program that make