I am learning C++ class templates. Below is my code. When I run it, I get the error "required from here". It would be great help if someone can point out the issue. The error line number corresponds to instantiation of frank object.
#include <iostream>
#include <string>
template <typename T>
class Data
{
private:
std::string name;
T value;
public:
Data(std::string n, T v) : value {v}, name {n}
{
}
~Data() = default;
T getValue()
{
return value;
}
std::string getName()
{
return name;
}
};
int main()
{
Data<int> frank {"frank", 35};
std::cout << std::endl;
}
Adding Build log:
C:\WINDOWS\system32\cmd.exe /C mingw32-make.exe -j 8 -e -f Makefile
"----------Building project:[ TestArea - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Users/LPC/Documents/C_Plus_Plus/TestArea'
mingw32-make.exe[1]: Leaving directory 'C:/Users/LPC/Documents/C_Plus_Plus/TestArea'
mingw32-make.exe[1]: Entering directory 'C:/Users/LPC/Documents/C_Plus_Plus/TestArea'
g++ -c "C:/Users/LPC/Documents/C_Plus_Plus/TestArea/main.cpp" -g -O0 -std=c++14 -Wall -o ./Debug/main.cpp.o -I. -I.
C:/Users/LPC/Documents/C_Plus_Plus/TestArea/main.cpp: In instantiation of 'Data<T>::Data(std::__cxx11::string, T) [with T = int; std::__cxx11::string = std::__cxx11::basic_string<char>]':
C:/Users/LPC/Documents/C_Plus_Plus/TestArea/main.cpp:30:33: required from here
C:/Users/LPC/Documents/C_Plus_Plus/TestArea/main.cpp:10:7: warning: 'Data<int>::value' will be initialized after [-Wreorder]
T value;
^
C:/Users/LPC/Documents/C_Plus_Plus/TestArea/main.cpp:9:17: warning: 'std::__cxx11::string Data<int>::name' [-Wreorder]
std::string name;
^
C:/Users/LPC/Documents/C_Plus_Plus/TestArea/main.cpp:12:5: warning: when initialized here [-Wreorder]
Data(std::string n, T v) : value {v}, name {n}
^
g++ -o ./Debug/TestArea @"TestArea.txt" -L.
mingw32-make.exe[1]: Leaving directory 'C:/Users/LPC/Documents/C_Plus_Plus/TestArea'
====1 errors, 3 warnings====