Results 1 to 5 of 5
Hi All,
I am getting this error while compiling a c++ code.
The error is: " ISO C++ forbids declaration of disp1 with no type ".
Inside the code I ...
- 04-02-2008 #1Just Joined!
- Join Date
- Apr 2008
- Posts
- 1
ISO C++ forbids declaration of disp1 with no type
Hi All,
I am getting this error while compiling a c++ code.
The error is: "ISO C++ forbids declaration of disp1 with no type".
Inside the code I wrote a simple template. The code is like:
Code:#include<iostream> using namespace std; template<class T> class Data{ public: T t1, t2; disp1(T v1, T v2) { t1=v1; t2=v2; cout<<t1<<'\t'<<t2<<endl; } Data(){} ~Data(){} }; int main() { Data<int> d_int; d_int.disp1(11,12); return 0; }Last edited by devils casper; 04-02-2008 at 07:40 PM. Reason: Added [code]...[/code] tag.
- 04-02-2008 #2
you need to either declare a return type for the function or make it void
Code:void disp1 { }
- 04-02-2008 #3
For that particular function, I'd vote for void, because the function as posted doesn't seem to want to return anything useful.
--
Bill
Old age and treachery will overcome youth and skill.
- 04-03-2008 #4
This is true of every function in C++, with two exceptions: constructors and destructors. These functions (recognizable because they have the name of the class) do not have a return type. Every other function must.
In C (before C99 at least), you are allowed to omit the return type of a function, and it assumed to be int. However, C++ does not allow this.DISTRO=Arch
Registered Linux User #388732
- 04-04-2008 #5Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513


Reply With Quote
