C++ and header file problem.
I''m trying to learn C++ and at the moment I can''t get my head around Header files.
Here is my implemtation of "Stack.h" in file called Stack.cpp
#include "Stack.h"
#include
using namespace std;
void
Stack::Link::initialize(void* dat, Link* nxt) {
data = dat;
next = nxt;
}
void Stack::initialize() { head = 0; }
void Stack::push(void* dat) {
Link* newLink = new Link();
newLink->initialize(dat, head);
head = newLink;
}
void* Stack::peek() { return head->data; }
void* Stack::pop() {
if(head == 0) return 0;
void* result = head->data;
Link* oldHead = head;
head = head->next;
delete oldHead;
return result;
}
void Stack::cleanup() {
Link* cursor = head;
while(head) {
cursor = cursor->next;
delete head->data; // Assumes a ''new''!
delete head;
head = cursor;
}
head = 0; // Officially empty
}
Here is my Stack.h
#ifndef STACK_H
#define STACK_H
struct Stack {
struct Link {
void* data;
Link* next;
void initialize(void* dat, Link* nxt);
}* head;
void initialize();
void push(void* dat);
void* peek();
void* pop();
void cleanup();
};
#endif
I can''t seem to compile it with Borland''s free command line compiler using "bcc32 Stack.cpp". Can anyone explain what I''m doing wrong?
Thanks.
try including everything else before stack.h that may solve your problem
--------------------------
Whats a pretty girl like you doing in a dirty mind like mine?
--------------------------
Whats a pretty girl like you doing in a dirty mind like mine?
Those who dance are considered insane by those who cannot hear the music.
After I included everything before Stack.cpp I get,
Error: Unresolved external ''_main'' referenced from C:\BORLAND\BCC55\LIB\C0X32.OBJ
Error: Unresolved external ''_main'' referenced from C:\BORLAND\BCC55\LIB\C0X32.OBJ
I haven't tried using that specific compiler yet, but the problem might be that you aren't using the right command line option to create an object file instead of an executable. If it can't find the main() function, it'll call it an unresolved external. If you are going to add this into other programs, find the option to make it compile to an object file. Otherwise, add a main function.
Edited by - dragonskin on December 8, 2000 8:26:18 PM
Edited by - dragonskin on December 8, 2000 8:26:18 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement