[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

ISO C++ forbids "set" and "get" as method names?

Ravi

11/28/2008 10:13:00 AM

I created a class in C++ with method names "set" and "get" and got the
following error messages (with a few others which related to same
problem I think):

"error: ISO C++ forbids declaration of 'set' with no type"
"error: ISO C++ forbids declaration of 'get' with no type"

Why this is so and what should be naming conventions for methods in C+
+?
7 Answers

anon

11/28/2008 10:14:00 AM

0

Ravi wrote:
> I created a class in C++ with method names "set" and "get" and got the
> following error messages (with a few others which related to same
> problem I think):
>
> "error: ISO C++ forbids declaration of 'set' with no type"
> "error: ISO C++ forbids declaration of 'get' with no type"
>
> Why this is so and what should be naming conventions for methods in C+
> +?

I just tried your example, and my compiler didn't complain.

Kai-Uwe Bux

11/28/2008 10:34:00 AM

0

Ravi wrote:

> I created a class in C++ with method names "set" and "get" and got the
> following error messages (with a few others which related to same
> problem I think):
>
> "error: ISO C++ forbids declaration of 'set' with no type"
> "error: ISO C++ forbids declaration of 'get' with no type"
>
> Why this is so

because you made a mistake. Post code, and we can find out which one.


> and what should be naming conventions for methods in C++?

The problem would persist if you renamed set and get since it is unrelated
to naming conventions: set and get are neither keywords nor reserved names.

The "with no type" could indicate a missing return type (just a guess).


Best

Kai-Uwe Bux

gw7rib

11/28/2008 12:42:00 PM

0

On 28 Nov, 10:12, Ravi <ra.ravi....@gmail.com> wrote:
> I created a class in C++ with method names "set" and "get" and got the
> following error messages (with a few others which related to same
> problem I think):
>
> "error: ISO C++ forbids declaration of 'set' with no type"
> "error: ISO C++ forbids declaration of 'get' with no type"
>
> Why this is so and what should be naming conventions for methods in C+
> +?

Without seeing the code, we can't be sure, but my wild guess is that
you have the wrong number of brackets or braces somewhere. This often
means that what the compiler is expecting is very different from what
you think you're telling it.

Hope that helps.
Paul.

Juha Nieminen

11/28/2008 2:38:00 PM

0

Ravi wrote:
> I created a class in C++ with method names "set" and "get" and got the
> following error messages (with a few others which related to same
> problem I think):
>
> "error: ISO C++ forbids declaration of 'set' with no type"
> "error: ISO C++ forbids declaration of 'get' with no type"
>
> Why this is so and what should be naming conventions for methods in C+
> +?

You should read more carefully. The compiler is *not* saying "ISO C++
forbids declaration of 'set'". What the compiler is saying is "ISO C++
forbids declaration of 'whatever the name may be' *with no type*".

The compiler is not complaining about the name. It's complaining about
the declaration not having a type specified.

James Kanze

11/28/2008 2:46:00 PM

0

On Nov 28, 11:14 am, anon <a...@no.invalid> wrote:
> Ravi wrote:
> > I created a class in C++ with method names "set" and "get"
> > and got the following error messages (with a few others
> > which related to same problem I think):

> > "error: ISO C++ forbids declaration of 'set' with no type"
> > "error: ISO C++ forbids declaration of 'get' with no type"

> > Why this is so and what should be naming conventions for
> > methods in C++?

> I just tried your example, and my compiler didn't complain.

He didn't give an example, so how could you try it. He didn't
give any information, so there's really no way we can help him.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

jt

11/28/2008 3:09:00 PM

0

On Fri, 28 Nov 2008 06:46:20 -0800, James Kanze wrote:

> On Nov 28, 11:14 am, anon <a...@no.invalid> wrote:
>> Ravi wrote:
>> > I created a class in C++ with method names "set" and "get" and got
>> > the following error messages (with a few others which related to same
>> > problem I think):
>
>> > "error: ISO C++ forbids declaration of 'set' with no type" "error:
>> > ISO C++ forbids declaration of 'get' with no type"
>
>> > Why this is so and what should be naming conventions for methods in
>> > C++?
>
>> I just tried your example, and my compiler didn't complain.
>
> He didn't give an example, so how could you try it. He didn't give any
> information, so there's really no way we can help him.

And there was me thinking "anon" was being ironic...

--
Lionel B

Daniel T.

11/28/2008 5:34:00 PM

0

Lionel B <me@privacy.net> wrote:
> On Fri, 28 Nov 2008 06:46:20 -0800, James Kanze wrote:
> > On Nov 28, 11:14 am, anon <a...@no.invalid> wrote:
> > > Ravi wrote:

> > > > I created a class in C++ with method names "set" and "get" and
> > > > got the following error messages (with a few others which
> > > > related to same problem I think):
> > > >
> > > > "error: ISO C++ forbids declaration of 'set' with no type"
> > > > "error: ISO C++ forbids declaration of 'get' with no type"
> > > >
> > > > Why this is so and what should be naming conventions for
> > > > methods in C++?
> > >
> > > I just tried your example, and my compiler didn't complain.
> >
> > He didn't give an example, so how could you try it. He didn't
> > give any information, so there's really no way we can help him.
>
> And there was me thinking "anon" was being ironic...

When I compile the OP's example, it compiles fine, but it crashes at
runtime. (missing main function.) The OP's example code also compiles
fine on the Comeau on-line compiler. Once again, his example code in its
entirety: