I want to declare template inside a class

.h file

# include<stdio.h>
# include<iostream>
using namespace std;
#pragma once

template <typename T>
class LeafNode
{
	T records;
	LeafNode* next;
	int size;
public:
	LeafNode(void);
	~LeafNode(void);
	
};

.cpp file

#include "LeafNode.h"
template <typename T>
LeafNode::LeafNode(void)
{
}
template <typename T>
LeafNode::~LeafNode(void)
{
}

I need any help, people.

Recommended Answers

All 2 Replies

templates cannot be in separate files. You have to declare and define a template in the same file.

my problem solved when I put my code in one file (.h file)

Hope that will help the others

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.