0

I have the header file and member functions definition stored in two separate file already. I don't know how to finish this part in the main file.

In the main()

(i) Ask the user to enter a sentence.

(ii) Use cin.get(ch) to read each character, ch, of the sentence, and then insert ch to a stack (push()).

(iii) After reading the whole sentence and inserting all characters to the stack, print out the sentence backwards by using the member functions of the stack (top() & pop()).

output example

Please enter a sentence: This is an example!

!elpmaxe a si sihT

This is what I have so far in my main file. It doesn't run, I don't know how to store user str input and also linkedStackType is giving me problem: 'undefined reference to 'linkedStackType

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

int main()
{
    linkedStackType<char> myStack;
    const int SIZE = 100;
    char ch[SIZE];

    cout << "Please enter a sentence: ";
    cin.get(ch, SIZE);

    return 0;
}
Sleepy
  • 41
  • 5
  • [Undefined reference](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix). For the other part of your question, try something, then come back with the issue you are having. – ChrisMM Apr 14 '20 at 17:01
  • Potential dupe: [Why can templates only be implemented in the header file?](https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) – molbdnilo Apr 14 '20 at 17:17

1 Answers1

0

the error you get is due to the fact that the linker does not know how to find the binary related to linkedStackType entity (class or struct I suppose) you're using in function main:

if linkedStackType is defined by a simple cpp file you wrote, than be sure to add it into the project you're compiling, if you already added the file be sure that the entity linkedStackType is not defined inside a namespace (otherwise you have to specify the name space when referring to linkedStackType for example lst::linkedStackType myStack).

SeventhSon84
  • 364
  • 1
  • 4