Error about header file

Hello, i have create the below program to find the smaller number.
The program include a header file (min.h) but when i run it show me the error:

D:\C++ peiramata\proc++6.58.cpp||In function 'int main()':|
D:\C++ peiramata\proc++6.58.cpp|21|error: expected primary-expression before 'int'|
D:\C++ peiramata\proc++6.58.cpp|21|error: expected primary-expression before 'int'|
D:\C++ peiramata\proc++6.58.cpp|32|error: expected primary-expression before 'double'|
D:\C++ peiramata\proc++6.58.cpp|32|error: expected primary-expression before 'double'|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|


why is this happening?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include "min.h"

int main()
{
    int a_int=0;
    int b_int=0;
    double a_double=0;
    double b_double=0;

    cout<<"input 2 integers "<< endl;
    cout<<"a: ";
    cin>>a_int;
    cout<< endl;
    cout<<"b: ";
    cin>>b_int;
    cout<<"the smaller number is: "<<minimum(int a_int, int b_int)<< endl;

    cout<< endl;
    cout<< endl;

    cout<<"input 2 decimals "<< endl;
    cout<<"a: ";
    cin>>a_double;
    cout<< endl;
    cout<<"b: ";
    cin>>b_double;
    cout<<"the smallest number is: "<<minimum(double a_double, double b_double)<< endl;

}



and this is the header file (save as min.h) in the same folder with the above program:


template <class X>
X minimum (X a, X b)
{
X min=a;

if (b<a)
min=b;
cout<<min<< endl;
}
When you call the function, only pass the variable name as argument without the type name.
Not too many issues:

Lines 22 and 33 you don't need the int or double declarations in the cout statements, and in your header file the function X minimum (X a, X b) has to return a value for X (the return type).
Last edited on
Yes, i change the code and there isn' t error!! Thanks!
Topic archived. No new replies allowed.