I am just learning templates in C++ and I came across the idea of using static variables in templates. I created a simple class containing a three dimensional vector. I decided to keep the 'unit caps'(i, j and k) as static so to make it a class property instead of it being an object property:
#include <iostream>
using namespace std;
template <class T = int>
class vector
{
int *arr;
static string caps;
public:
vector() {}
vector(int arr[]) : arr(arr) {}
void setVector(int arr[])
{
this->arr = arr;
}
void displayVector()
{
cout << "The vector is : " << arr[0] << caps[0] << " + " << arr[1] << caps[1] << " + " << arr[2] << caps[2] << endl;
}
};
string vector::caps = "ijk";
And it's throwing an error enter image description here
Then I tried something:
template <class T>
string vector::caps = "ijk";
Still giving error.