Hi, I'm currently doing an assignment using eclipse, when I build the files there is nothing wrong with any file in particular, but the project has an error, here are the files:
int main(){
HPStack stack;
string line;
while (getline(cin, line)) {
stringstream ss(line);
string token;
while(ss >> token) {
if (isdigit(token[0])) {
stack.push(atof(token.data()));
}
// a lot of boring else if's here
}
}
cout << stack.peek();
}
Anyways, I'm getting the error message :
/cygdrive/c/Users/Rhys/workspace/Calculator/Debug/../HPStack.cpp:27: multiple definition of `HPStack::peek()'
./Calculator.o:/cygdrive/c/Users/Rhys/workspace/Calculator/Debug/../HPStack.cpp:27: first defined here
the same message is repeated twice more for HPStack::push(double) and HPStack::pop()
I have been trying to get this program to work for days and have come to a point that I can not solve this issue. The program will run but when it gets to the aa_after function the function does not add the word after the word specified it adds it to the first word. The program uses pointers to create a linked list. Any help would be much apreciated. Here is the code:
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
const int MAX_WORD_LENGTH = 80;
/* definition of a node */
struct Node;
typedef Node *Node_ptr;
/* Function to assign a linked list to "a_node" */
void assign_list(Node_ptr &a_list);
/* Function to assign a new dynamic node variable to "a_node" */
void assign_new_node(Node_ptr &a_node);
/* Function to print the strings in the list "a_node" */
void print_list(Node_ptr a_node);
void add_after(Node_ptr &list, char a_word[], char word_after[]);
//This function inserts a node containing "word_after" in the linked list "list", after the first occurrence of a node containing "a_word". If "list" does not contain such a node, the function leaves it unchanged.
char word_a[MAX_WORD_LENGTH];
char aword[MAX_WORD_LENGTH];
Node_ptr my_list = NULL;
assign_list(my_list);
cout << "\nTHE LIST IS NOW:\n";
print_list(my_list);
cout << "After which word would you like to add a word?:";
cin >> word_a;
cout << "What word would you like to add after that word?:";
cin >> aword;
add_after(my_list,aword, word_a);
/* DEFINITION OF FUNCTION "assign_list" */
void assign_list(Node_ptr &a_list)
{
Node_ptr current_node, last_node;
assign_new_node(a_list);
cout << "Enter first word (or '.' to end list): ";
cin >> a_list->word;
if (!strcmp(".",a_list->word))
{
delete a_list;
a_list = NULL;
}
current_node = a_list;
while (current_node != NULL)
{
assign_new_node(last_node);
cout << "Enter next word (or '.' to end list): ";
cin >> last_node->word;
if (!strcmp(".",last_node->word))
{
delete last_node;
last_node = NULL;
}
current_node->ptr_to_next_node = last_node;
current_node = last_node;
}
}
/* END OF FUNCTION DEFINITION */
/* DEFINITION OF FUNCTION "assign_new_node" */
void assign_new_node(Node_ptr &a_node)
{
a_node = new Node;
if (a_node == NULL)
{
cout << "sorry - no more memory\n";
exit(1);
}
}
//*****************************************************
/* DEFINITION OF FUNCTION "print_list" */
void print_list(Node_ptr a_node)
{
while (a_node != NULL)
{
cout << a_node->word << " ";
a_node = a_node->ptr_to_next_node;
}
}
//*****************************************************