Errors during multiple compilation

May 30, 2010 at 3:14pm
I was studying modular programming, and tried to compile two files: "stack.h" and "a.cpp" together.

STACK.H FILE:

namespace Stack
{
void push(char);
char pop();
}

A.CPP:

#include"iostream"
#include"Stack.h"

using namespace std;

void f()
{
Stack::push('c');
if(Stack::pop()!='c') cout<<"Impossible";
}

--------------------------------------------
This is a direct example taken from Bjarne's book. I compile them using g++ compiler in UNIX. And get the error:
a.cpp:(.text+0xe): undefined reference to `Stack::push(char)'
a.cpp:(.text+0x13): undefined reference to `Stack::pop()'

Later I compiled them using Dev C++ and got the same error listed as "linker error".

Please help.
Thanks in advance.
May 30, 2010 at 3:53pm
You need to actually define the functions you're calling.
May 30, 2010 at 3:57pm
As hamsterman wrote, you need to define your Stack.h functions in a Stack.cpp file. In a *.h file you just declare functions defined in a *.cxx file with the same name as *.h file.
Topic archived. No new replies allowed.