Should a nontype template argument have a scalar type error in C ++?

It:

Nontype template argument must be scalar type

- The error I get when I try to create this program using Turbo C ++ 4.5. I have some errors, for example:

non-type template argument refers to a function that does not have a binding

But this mistake is completely new to me. What is wrong with the code?

#include<iostream.h>
template<class T1=int,class T2=int>
class tempex
{
T1 a;
T2 b;
public:
    tempex(T1 x,T2 y)
    {
        a=x;
        b=y;
    }
    void show()
    {
        cout<<"A= \t"<<a<<"\tB=\t"<<b;
    }
};

int main()
{
    tempex <float,int> te1(1.23,123);
    te1.show();
    return 0;
}
+4
source share
2 answers

It seems you are using an ancient compiler . Try using one of the modern, free ones, for example, VC ++ 2013 Express Edition. A more appropriate error message will appear:

fatal error C1083: Cannot open include file: 'iostream.h' :
    No such file or directory

When you fix this by changing <iostream.h>to <iostream>, you will get:

error C2065: 'cout' : undeclared identifier

, cout std::cout, :

warning C4305: 'argument' : truncation from 'double' to 'float'

1.23 1.23f.

. , ++.

+9

Turbo ++ 4.5 1994 !!! ++ 1998 . , [] ++.

1994 ? , :

  • ;
  • Netscape Communications HTTP Secure - Netscape Navigator;
  • Sony Playstation;
  • U.S. ;
  • Apple Computer, Inc. Macintosh PowerPC ( );
  • ;
  • Sega Sonic 3 Mega Drive;
  • Mrs. Doubtfire (VHS).

- , , GCC 4.9 Microsoft Visual Studio 2013; "" , GCC 4.1 Visual Studio 2005, , , . ?

+8

All Articles