Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nontype template argument must be of scalar type error in C++? [closed]

This:

Nontype template argument must be of scalar type

is the error that I get when I try to build this program using Turbo C++ 4.5. I have got some errors like:

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

But this error is entirely new for me. What is wrong in 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;
}
like image 493
user3414734 Avatar asked Dec 01 '22 18:12

user3414734


1 Answers

Turbo C++ 4.5 is from 1994!!! C++ wasn't even standardised until 1998. It is little surprise, then, that your antiquated software cannot parse this [almost] valid C++ program.

What else happened in 1994? Hmm, let's see:

  • The Western Hemisphere is declared free of polio;
  • Netscape Communications creates HTTP Secure for its Netscape Navigator web browser;
  • Sony releases the first Playstation;
  • U.S. President Bill Clinton delivers his first State of the Union address;
  • Apple Computer, Inc. releases the first Macintosh computers to use the new PowerPC Microprocessors (this is considered to be a major leap in personal computing);
  • Nelson Mandela is inaugurated as South Africa's first black president;
  • Sega releases Sonic 3 for the Mega Drive;
  • Mrs. Doubtfire available on home video (VHS).

You really ought to use something from this century, like GCC 4.9, or Microsoft Visual Studio 2013; you could have used an "old" compiler like GCC 4.1 or Visual Studio 2005, and it would still be a decade younger than the dinosaur you've dredged up. Where did you even find it?!

like image 200
Lightness Races in Orbit Avatar answered Dec 04 '22 14:12

Lightness Races in Orbit