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

R

Ravi

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+
+?
 
A

anon

Ravi said:
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.
 
K

Kai-Uwe Bux

Ravi said:
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
 
G

gw7rib

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.
 
J

Juha Nieminen

Ravi said:
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.
 
J

James Kanze

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.
 
L

Lionel B

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...
 
Joined
Jul 30, 2011
Messages
1
Reaction score
0
"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++?

This looks like you forgot to specify the return types. E.g. the int in:

int get () { … }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top