| | |
Stack with Dynamic Array
![]() |
•
•
Join Date: Apr 2008
Posts: 27
Reputation:
Solved Threads: 0
Hi all...
I tried to maked Stack with Dynamic Array but ........
succed when main is empty
when i tried to write in main .......
3_synatx error apper to me
Error 1 error LNK2019: unresolved external symbol "public: __thiscall Stack::~Stack(void)" (??1Stack@@QAE@XZ) referenced in function _wmain Stack.obj
Error 2 error LNK2019: unresolved external symbol "public: __thiscall Stack:
tack(void)" (??0Stack@@QAE@XZ) referenced in function _wmain Stack.obj
Error 3 fatal error LNK1120: 2 unresolved externals E:\YOZOO\struct.prog\data structured\problems in c++\SecondYear\Stack\Debug\Stack.exe
I tried to maked Stack with Dynamic Array but ........
class Stack
{
private:
int *SS;
int size;
int t;
void Expand();
public:
//constractors
Stack();
~Stack();
Stack(const Stack & Original);
//operations
Stack &operator= (const Stack& RHS);
bool Empty();
void Display();
int Pop();
void Push(int Value);
int Top ();
};
using namespace std;
#include "stdafx.h"
#include"stack.h"
#include<iostream>
Stack ::Stack ()
{
size=20;
SS=new int [size];
t=-1;
}
Stack ::Stack(const Stack &Original)
{
size=Original.size;
t=Original.t;
SS=new int [Size];
if(SS!=NULL)
{
for(int i=0 ; i<t; i++)
{
SS[i] =Original.SS[i];
}
}
}
bool Stack ::Empty()
{
return (t==-1);
}
void Stack ::Expand()
{
size=size*2;
int * SS_1=new int [size];
for(int i=0; i<t ; i++)
{
SS_2[i]=SS[i];
}
delete[]SS;
SS_2=SS;
}
Stack& Stack ::operator=(const Stack & RHS)
{
if(this != RHS)
{
if(size !=RHS.size)
{
delete[]SS;
size=RHS.size;
int * SS_2 = new int [size];
}
t=RHS.t;
for(int i=0 ; i<t; i++)
{
SS_2[i] = RHS.SS[i];
}
}
return *this;
}
void Stack :: Push(int Value)
{
if(t==capacity-1)
Expand();
t++;
SS[t]= Value;
}
int Stack :: Pop()
{
int V ;
if(!Empty())
{
V=SS[t] ;
t--;
return V ;
}
}
int Stack :: Top ()
{
if(!Empty())
return (SS[t]);
}
void Stack ::Display()
{
for(int i=0; i<t; i++)
cout<<SS[i]<<" ";
}
Stack ::~Stack()
{
delete[]SS;
}#include "stdafx.h"
#include"stack.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}when i tried to write in main .......
#include "stdafx.h"
#include"stack.h"
int _tmain(int argc, _TCHAR* argv[])
{
Stack S;
return 0;
}Error 1 error LNK2019: unresolved external symbol "public: __thiscall Stack::~Stack(void)" (??1Stack@@QAE@XZ) referenced in function _wmain Stack.obj
Error 2 error LNK2019: unresolved external symbol "public: __thiscall Stack:
tack(void)" (??0Stack@@QAE@XZ) referenced in function _wmain Stack.objError 3 fatal error LNK1120: 2 unresolved externals E:\YOZOO\struct.prog\data structured\problems in c++\SecondYear\Stack\Debug\Stack.exe
•
•
Join Date: Nov 2008
Posts: 377
Reputation:
Solved Threads: 70
Sorry my mistake, I just read the error message and assumed.
Ok so I copied and compiled the code.
Here is what I had to fix.
(a) Size in the constructor needs to be size.
(b) Expand doesn't have an SS_2 variable and the last line
should be
it should be
(d) In the same function, SS_2 should read SS.
(e)
(f) That is it...
Don't think the code works but it does compile.... time for you to test....
Ok so I copied and compiled the code.
Here is what I had to fix.
(a) Size in the constructor needs to be size.
(b) Expand doesn't have an SS_2 variable and the last line
should be
SS=SS_2; (c) The guard in the assignment operator is mal formedit should be
if (this!=&RHS) (d) In the same function, SS_2 should read SS.
(e)
Stack::Push capacity is actually size(f) That is it...
Don't think the code works but it does compile.... time for you to test....
Last edited by StuXYZ; Nov 27th, 2008 at 7:24 am. Reason: Missed a couple of icode tags that made it look strange
![]() |
Similar Threads
- What am I doing wrong. (C++)
- Dynamic Stack Implementation - Templated Class (C++)
- malloc of a two-dimensional array (C)
- Malloc/Calloc Dynamic Memory Allocation. (C++)
- My solution to 2 beginner questions (C++)
- Simple string manipulation (C)
- Stack conversion (C++)
- maximum memory limit? (C)
- How to be Crash Free (C++)
Other Threads in the C++ Forum
- Previous Thread: Need Help asto 2-3 Trees
- Next Thread: Random selection
| Thread Tools | Search this Thread |
action api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node noob output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets





