Dev-C++ can't compile program multiple definitions

Jul 18, 2008 at 7:40am
Dear fellows,
here's what i have.

//Stack.h
#ifndef STACK_H
#define STACK_H

class Stack {
Stack();
Stack(int sz);
....
};
#endif

//Stack.cpp
#include "Stack.h"

Stack :: Stack () {...}

Stack :: Stack(int sz) {...}

...

//StackMain.cpp
#include <iostream>
#include "Stack.cpp"

using namespace std;

int main()
{
Stack s;
system("PAUSE");
return 1;
}

Compilation Errors : multiple definition of `Stack::Stack()'
first defined here
multiple definition of `Stack::Stack()'
first defined here
multiple definition of `Stack::Stack(int)'
first defined here

What gives?
Help will be much appreciated.
Last edited on Jul 18, 2008 at 7:41am
Jul 18, 2008 at 10:34am
#include "Stack.h" not .cpp
Jul 20, 2008 at 8:38am
It worked. Thanks a lot.
But I don't understand the logic. Then definition (stack.cpp) is not
included anywhere?
Jul 22, 2008 at 11:11am
You should include it in the list of input files for the compiler. The compiler will generate the object file for the linker to... link.
If you don't do so and use some function defined in stack.cpp, you'll get an undefined reference error from the linker.
Topic archived. No new replies allowed.