-1
driver.cc
#include <iostream>
#include "dynStack.h"

using namespace std;

// class definition
int main()
{
  dynstack<int> c1;


  c1.push(1);

  cout<<"hello";

  return 0;
}


dynStack.h
#include <iostream>

using namespace std;

template <class T>
class dynstack
{
    public:
        dynstack();
        void push(T data);


};


dynStack.cc

#include "dynStack.h"

template <class T>
dynstack<T>::dynstack()
{

}

template <class T>
void dynstack<T>::push(T data)
{


    return data;
}

I'm new to C++. When I run the code, it keeps giving me "undefined reference to 'dynstack::dynstack()' error. I checked include and prototype and couldn't spot the error. Could anyone help me find where I did wrong? Thank you.

An Overflowed Stack
  • 334
  • 1
  • 5
  • 20

1 Answers1

4

Your templated class methods, unless called from within the same .cpp, need to have their implementations in the header, or an inline file included from the header.

Aesthete
  • 18,622
  • 6
  • 36
  • 45