Reputation: 3
i'm studing templates in c++ and according to this tutorial: http://www.cprogramming.com/tutorial/templates.html
i made the class CalcTempl.h
#ifndef CALC_TEMPL_H
#define CALC_TEMPL_H
template <class A_Type> class CalcTempl
{
public:
A_Type multiply(A_Type x, A_Type y);
A_Type add(A_Type x, A_Type y);
};
template <class A_Type> A_Type calc<A_Type>::multiply(A_Type x,A_Type y)
{
return x*y;
}
template <class A_Type> A_Type calc<A_Type>::add(A_Type x, A_Type y)
{
return x+y;
}
#endif
and main.cpp
#include <iostream>
#include "CalcTempl.h"
using namespace std;
int main(){
CalcTempl<double> c2;
double d1 = 5;
double d2 = 4;
double c2r1 = c2.add(d1, d2);
cout << " C2 Result: " << c2r1 << "\n";
return 0;
}
on compile (g++ main.cpp -o ttest) i got this error:
CalcTempl.h:11: error: expected init-declarator before '<' token
CalcTempl.h:11: error: expected `;' before '<' token
CalcTempl.h:15: error: expected init-declarator before '<' token
CalcTempl.h:15: error: expected `;' before '<' token
I can't found what is wrong
Upvotes: 0
Views: 2133
Reputation: 72044
Your class is called CalcTempl
, but at the point where you implement its members, you try to refer to it as calc
. That can't work.
Upvotes: 2