Doubles as a pattern?

I am trying to create a generic class that processes ints, doubles and string. However, when I try to instantiate the template class, I get the following error message:

error: 'double' is not a valid type for a template constant parameter

Contextual creation works completely with int types, as well as internal code, although I haven't finished it with string types yet. It seems like this should be good, as you can instantiate a vector, etc. Is there something I'm missing here?

// file forest.h

template<typename NODETYPE> class Forest
{
    template<NODETYPE>                                              // Line 15
    friend Forest<NODETYPE>& operator+(Forest<NODETYPE>& f1,
                                       Forest<NODETYPE>& f2);

    template<NODETYPE>                                              // Line 17
    friend ostream& operator<<(ostream& output,
                               const Forest<NODETYPE>& f1);

    template<NODETYPE>                                              // Line 19
    friend void outputHelper(ostream& output,
                             const ForestNode<NODETYPE>& currentNode,
                             int depth);
    /* ... */
};

The error occurs as follows:

\project 4\forest.h|341|instantiated from here|
\project 4\forest.h|15|error: 'double' is not a valid type for a template constant parameter|
\project 4\forest.h|17|error: 'double' is not a valid type for a template constant parameter|
\project 4\forest.h|19|error: 'double' is not a valid type for a template constant parameter|
+3
source share
4 answers
template<NODETYPE> friend Forest<NODETYPE>& operator+(Forest<NODETYPE>& f1, Forest<NODETYPE>& f2);

    template<NODETYPE> friend ostream& operator<<(ostream& output, const Forest<NODETYPE>& f1);

    template<NODETYPE> friend void outputHelper(ostream& output, const ForestNode<NODETYPE>& currentNode, int depth);

. , . , typename class NODETYPE.

+4

double ( float long double) , . , , -.

, , ctor / .

+3

, , - :

template_type<3.1415926d> blarg;  

-, -. . (float, long double) . , , :

template_type<"life, the universe and everything"> blarg;  

( - ) , , :

char* my_str="life, the universe and everything";
template_type<my_str> blarg;

shoule

: (iirc gcc 3, , )

+2

(, ) .

template <double x> struct A {};

double ( , ).

template <typename T> struct A {};
... 
A<double> a;

double,

template <typename T> struct A {};
template <> struct A<double> {...};
+1

Source: https://habr.com/ru/post/1772402/


All Articles