By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 896 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

Stack error

P: 6
hello I am getting this strange error

Linking...
Cpp2.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Stack::push(char const &)" (?push@Stack@@QAE_NABD@Z)
Debug/Cpp2.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.


I am not really sure why


My stack.ccp is this

/************************************************** ************************
#include "Stack.h"
#include <iostream>
using namespace std;

bool Stack::top( EType& Item ) const
{
bool Result = false;

if (Num > 0)
{
Item = Mem[Num-1];
Result = true;
}
return Result;
}

bool Stack::pop( EType& Item )
{
bool Result = false;

if (Num > 0)
{
Item = Mem[Num-1];
Num--;
Result = true;
}
return Result;
}

bool Stack::push( const EType& Item )
{
bool Result = false;

if (Num < STACK_MAX)
{
Mem[Num] = Item;
Num++;
Result = true;
}
return Result;
}

****************************************/

my stack.h is this
/******************************************
#ifndef STACK_
#define STACK_

const int STACK_MAX = 100;

typedef char EType;

class Stack
{
public:
Stack() { Num = 0; }
void reset() { Num = 0; }
bool is_empty() const { return Num == 0; }
bool is_full() const { return Num == STACK_MAX; }
bool top( EType& Item ) const;
bool pop( EType& Item );
bool push( const EType& Item );

private:

int Num;
EType Mem[STACK_MAX];
};
#endif

***************************************/

and when I try


#include <iostream>
#include "stack.h"
using namespace std;


void main()
{
Stack A;


A.push('a');
A.push('g');
}

I get that error, any ideas why?



}
Sep 17 '06 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
You have not linked the object file created from stack.cpp into you exectuable?
Sep 17 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.