what am i doing wrong?

what am i doing wrong?

this program needs to output what ever the number is bigger and depends on the data type

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
  
#include <iostream>

using namespace std;

template <class T>
class Cal{
    T first, second;
    public:
        Cal(T a, T b){
            first = a;
            second = b;
        }
};
template <class T>

T Cal<T>::bigger(){
    return(first>second?first:second);
}

int main() {
    
  
    //   int < specified!
    Cal <int> Cl(54,94);
    
    cout<<Cl.bigger()<<endl;

    return 0;
}

Hey there. Don't kick yourself in the bum or anything, but you forgot to write

T bigger();

as part of your class :P
yep of cause i did.. and yes i am kicking my arse wile rubbing my tummy..

thanks nickeeromo..

by the way any tips on looking at a code trying to find a error without skipping over it right under my nose?
Lol, it comes with experience.

But in Visual Studio 2010, there is a red line that was under bigger() where you tried to use it. When you mouseover it, it gives you that brief description of what's going on. I have been dealing with classes a lot lately, so it didn't take me long to figure it out - the definition of the function was the first thing I looked for!

Good learning to you!
It is beneficial to provide all the relevant information, when asking on the Forum.
Actually, one could spot the error while gathering the information for the Forum post.

There are at least four ways for program to be "wrong":
1. Compiler sees a syntax error.
2. One does not provide all necessary object code to the linker.
3. The runtime crashes.
4. The runtime produces unexpected results.

Your code made an online compiler say:
17:18: error: no 'T Cal<T>::bigger()' member function declared in class 'Cal<T>'
 In function 'int main()':
27:14: error: 'class Cal<int>' has no member named 'bigger'

Two error messages.
Line 17 has T Cal<T>::bigger()
Line 27 has cout<<Cl.bigger()<<endl;

Both messages are due to the same syntax error. In my opinion these messages are clear, but your compiler might use different descriptions. Some syntax errors on some compilers can produce much more cryptic messages.


Therefore, a "tip" is to read what your compiler tells you. If the message is too cryptic, then post it with the code.
thanks keskiverto, i will try my best to understand what the compiler says..
i use NetBeans regardless to say its next to impossible understand. i did not know abut the online compiler. and i think i am going to use it more often as its much more useful.
(English is not my first language)
Topic archived. No new replies allowed.