Answer the question
In order to leave comments, you need to log in
When inheriting a class template, I get error C2143, what is the reason?
I inherit the Typeinfo class from TypeSize.
TypeSize.h
using namespace std;
template <class T1>
class TypeSize
{
public:
TypeSize(T1 value);
void DataTypeSize();
protected:
T1 value;
};
using namespace std;
template <class T1>
class TypeInfo : public TypeSize<T1> // Здесь получаю C2143 синтаксическая ошибка: отсутствие "," перед "<"
{
public:
TypeInfo(T1 value);
void ShowTypeName();
};
#pragma once
#include "targetver.h"
#include <tchar.h>
#include <iostream>
#include "TypeInfo.h"
#include "TypeSize.h"
Answer the question
In order to leave comments, you need to log in
I don’t know why you need this, without understanding the syntax and other basic things, climb into templates. You are all wrong there.
#pragma once
#include <iostream>
template<typename T>
class TypeSize
{
public:
TypeSize(T v) : value{ v } {};
~TypeSize() {};
void dataTypeSize();
protected:
T value;
};
template<typename T>
void TypeSize<T>::dataTypeSize()
{
std::cout << "size: " << sizeof(value) << std::endl;
}
#pragma once
#include <typeinfo> // std::typeid()
#include "TypeSize.h"
template<typename T>
class TypeInfo : public TypeSize<T>
{
public:
TypeInfo(T v) : TypeSize<T>(v) {};
~TypeInfo() {};
void showTypeInfo();
};
template<typename T>
void TypeInfo<T>::showTypeInfo()
{
std::cout << "type: " << typeid(this->value).name() << std::endl;
}
#include "TypeInfo.h"
int main()
{
int a{ 5 };
TypeInfo<int> infInt(a);
infInt.dataTypeSize();
infInt.showTypeInfo();
std::getchar();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question