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

Discussion in 'C++' started by Ravi, Nov 28, 2008.

  1. Ravi

    Ravi Guest

    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+
    +?
     
    Ravi, Nov 28, 2008
    #1
    1. Advertising

  2. Ravi

    anon Guest

    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.
     
    anon, Nov 28, 2008
    #2
    1. Advertising

  3. Ravi

    Kai-Uwe Bux Guest

    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
     
    Kai-Uwe Bux, Nov 28, 2008
    #3
  4. Ravi

    Guest

    On 28 Nov, 10:12, 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+
    > +?


    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.
     
    , Nov 28, 2008
    #4
  5. 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.
     
    Juha Nieminen, Nov 28, 2008
    #5
  6. Ravi

    James Kanze Guest

    On Nov 28, 11:14 am, anon <> 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:
    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
     
    James Kanze, Nov 28, 2008
    #6
  7. Ravi

    Lionel B Guest

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

    > On Nov 28, 11:14 am, anon <> 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
     
    Lionel B, Nov 28, 2008
    #7
  8. Ravi

    bodenstorfer

    Joined:
    Jul 30, 2011
    Messages:
    1
    This looks like you forgot to specify the return types. E.g. the int in:

    int get () { … }
     
    bodenstorfer, Jul 30, 2011
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ken
    Replies:
    3
    Views:
    2,508
    Rolf Magnus
    Nov 8, 2003
  2. Henrik S. Hansen
    Replies:
    2
    Views:
    51,480
    Alf P. Steinbach
    May 2, 2004
  3. danny van elsen
    Replies:
    6
    Views:
    3,715
    Pete Becker
    May 7, 2005
  4. Penn
    Replies:
    4
    Views:
    1,383
    =?ISO-8859-1?Q?Sch=FCle_Daniel?=
    Jan 9, 2006
  5. BarryKamp
    Replies:
    0
    Views:
    613
    BarryKamp
    Apr 25, 2007
Loading...

Share This Page