I have these tree classes.
A ListTraits.h
, a List.h
and main.cpp
List.h
is a templated implementation of list, and it inherits from ListTraits.h
While I believe that my setup for the templated class is correct,
I get several syntax errors, that do not seem like they should be there:
Specifically, for the Listh.h
I get:
(line 8)
..
Node<typename>* head;
Error C2143 syntax error: missing ';' before '<' main
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int main
And then a series of other errors but these two make the least sense.
These are my files.
List.h
#pragma once
#include "ListTraits.h"
//------------ Declarations for List traits used in Test1 in main.cpp
template <typename> class List: public ListTraitsExtended<typename>,
public ListTraits<typename> {
private:
Node<typename>* head;
public:
List() {head = NULL;}
unsigned int size() {return 0;}
ListTraits& insert(const typename& item) {return null;}
void print() {}
//------------ Declarations for List traits used in Test2 in main.cpp
const typename* getCurrentElement() const {}
void advance() {}
void rewind() {}
};
ListTraits.h
#pragma once
//------------ Declarations for List traits used in Test1 in main.cpp
template <typename T> class ListTraits
{
public:
virtual unsigned int size() = 0;
virtual ListTraits& insert(const T& item) = 0;
virtual void print() = 0;
};
//------------ Declarations for List traits used in Test2 in main.cpp
template <typename T> class ListTraitsExtended
{
public:
virtual const T* getCurrentElement() const = 0;
virtual void advance() = 0;
virtual void rewind() = 0;
};
question from:
https://stackoverflow.com/questions/65937942/templated-class-syntax-errors 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…