[KLUG Members] ISO C++ forbids
Matt Scott
members@kalamazoolinux.org
07 Aug 2002 22:22:54 -0400
On Mon, 2002-08-05 at 10:29, Peter Buxton wrote:
> On Mon, Aug 05, 2002 at 06:38:40AM -0400, Adam Williams wrote:
>
> > I'm getting the following error:
> > extint.cpp:8: ISO C++ forbids defining types within return type
> > extint.cpp:8: return type specification for constructor invalid
>
> You might be getting a spurious error message triggered by real
> problems but obscured by trivial ones.
>
> > using namespace std;
> > class extint {
> > public:
> > extint();
> > extint(int v);
>
> Why not add 'void' returns to these functions?
The two functions are constructors and the last time I checked
constructors have no return type by definition in C++, not even void.
Anyway in case you haven't figured it out yet it looks like you have
fallen victim to something that I do ALL the time. You forgot the
semicolon following the last } in your class definition, i.e. it should
like like this.
using namespace std;
class extint {
public:
extint();
extint(int v);
void operator=(int &v);
void print(ostream *os);
void set(int v);
int get();
string str();
private:
int value;
}; // Don't forget the ; here
It doesn't show up until later because it isn't until that point that
you do something that is illegal to have inside a class definition. The
compiler thinks the class def keeps going after the final }.
Have fun!
Matt