* sam:
Uhm, OK. Most probably the compiler issued /warnings/, but generated an
executable anyway. The C++ language itself doesn't differentiate between
warnings and errors, it just requires diagnostics for some things, but in
practice a compiler will classify the diagnostics as /warnings/ (not technically
wrong but likely to not yield the effect that you intended, or meaningless) and
/errors/.
A diagnostic required by the language is usually classified as /error/. In this
case the compiler will not generate an executable. At least if it's any good.
A diagnostic not required by the language is usually classified as /warning/. In
this case the compiler will usually generate an executable, i.e. the compilation
succeeds. One exception is when the compiler recognizes that it has issued a
zillion or more warnings, whence it may give up and give you an error.
---
About the code. Turbo C++ 3.0 is pretty old, but Borland did make some darned
good tools. However, if you want to learn modern standard C++ you will benefit
greatly from, at some point, upgrading to a more modern compiler. Turbo C++ 3.0
was shipped long before the language was standardized in 1998. The
standardization changed many things, and in particular, as I recall Turbo C++
3.0 did not have standard exceptions and dealt incorrectly with virtual calls
from constructors.
In modern standard C++:
> #include<iostream.h>
This is a non-standard header. It was used before standardization. A modern
compiler may not offer this header, but instead the standard <iostream> header
(note the lack of filename extension).
In standard C++ a rough equivalent of the above is
#include <iostream>
using namespace std;
> #include<conio.h>
This is non-standard header. It was common on the Windows platform.
> template <class t>
> t fun(t a, t b)
> {t s;
> s=a+b;
> return (s);
> }
OK.
> void main()
In standard C or C++ 'main' must always have result type 'int', not 'void'.
Some compilers still accept 'void'.
It's a mystery why they do since it's more to type and has never been standard,
neither for C nor C++, but people have used it so much that even C++'s creator
Bjarne Stroustrup managed to erroneously write 'void main' in the 2nd edition of
his "The C++ Programming Language" book -- so you're in Very Good Company, but
don't do it.
> {clrscr();
> int x,y,z=0;
> x=4;y=5;
> z=fun<int>(x,y);
> cout<<z;
> getch();
> }
OK.
It's difficult to see why the compiler should issue warnings about anything here.
Presumably it's a quirk of the compiler; even if Borland did make very good
tools it is a rather old, archaic compiler, and they had to design the compiler
for "No Speed Limit" on PCs that today aren't even in the class of cell phones.
Cheers & hth.,
- Alf- Hide quoted text -
- Show quoted text -