0

I am attempting to create a templated vector class, but upon compilation I am receiving an error of

def.hpp:3:1: error: 'TempVector' does not name a type

I keep referring to reference material and my syntax and handling of the header file declaration and definition (.h and .hpp) seem right to me, but I can not figure out what I am overlooking.

Below is the three files I am working with, thank you.

driver.cpp:

#include <iostream>
#include <string>
#include "dec.h"

using namespace std;

int main() {
  TempVector <int> v1;
  cout<<"ran successfully"<<endl;
}

dec.h:

#ifndef DEC_H
#define DEC_H
#include <iostream>
#include <utility>

// Declaration of class Vector

template <typename T>
class TempVector {

public:
   TempVector ();

private:
   T* array;
   static const unsigned int spare = 10;
};

#include "def.hpp"
#endif

def.hpp:

template <typename T>
  TempVector<T>::TempVector () {
  std::cout<<"ran successfully";
}
  • I'm not seeing anything obvious after a quick glance - how are you compiling these files? – 0x5453 May 27 '21 at 16:08
  • Looks like `def.hpp` file is compiled as a separate translation unit, which would suggest an issue with project configuration or compilation process. – Yksisarvinen May 27 '21 at 16:08
  • I am using the command ```g++ -o run driver.cpp dec.h def.hpp```, I have also tried using g++6 and rearranging the order of the files on the command line. –  May 27 '21 at 16:09
  • 1
    Never include header files in your compilation command. You should just need `g++ -o run driver.cpp`. `include` will make sure the header files are imported into `driver.cpp` – NathanOliver May 27 '21 at 16:10

0 Answers0