I could not get this const before a function declaration

Discussion in 'C++' started by parag_paul@hotmail.com, Jun 16, 2008.

  1. Guest

    I understand that a const qualifier after the function declaration
    makes it a const function for the class.

    Like

    int func1 const ( double, long int );

    Now what is the purpose of the following
    const int func1 const ( double, long int );


    What is the purpose of the const before the declaration

    -Parag
    , Jun 16, 2008
    #1
    1. Advertising

  2. Jim Langston Guest

    <> wrote in message
    news:...
    >I understand that a const qualifier after the function declaration
    > makes it a const function for the class.
    >
    > Like
    >
    > int func1 const ( double, long int );


    Actualy, it's like this:

    int func1 ( double, long int ) const;

    > Now what is the purpose of the following
    > const int func1 const ( double, long int );


    const int func1 ( double, long int ) const;

    would be a constant function that returns a constant integer. Really not
    making much sense, usually a const returned value is a reference or pointer
    such as:

    const int & func1 ( double, long int ) const;
    or
    const int* func1 ( double, long int ) const;

    > What is the purpose of the const before the declaration
    Jim Langston, Jun 16, 2008
    #2
    1. Advertising

  3. James Kanze Guest

    On Jun 16, 7:44 am, "Jim Langston" <> wrote:
    > <> wrote in message


    > news:...


    > >I understand that a const qualifier after the function
    > >declaration makes it a const function for the class.


    > > Like


    > > int func1 const ( double, long int );


    > Actualy, it's like this:


    > int func1 ( double, long int ) const;


    > > Now what is the purpose of the following
    > > const int func1 const ( double, long int );


    > const int func1 ( double, long int ) const;


    > would be a constant function that returns a constant integer.
    > Really not making much sense,


    Not much sense, since const-ness doesn't apply to rvalues of
    non-class type. It is reasonable for a class type.

    --
    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, Jun 16, 2008
    #3
    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. Alexander Farber
    Replies:
    0
    Views:
    444
    Alexander Farber
    Jun 21, 2005
  2. Replies:
    11
    Views:
    1,085
  3. Javier
    Replies:
    2
    Views:
    541
    James Kanze
    Sep 4, 2007
  4. 0m
    Replies:
    26
    Views:
    1,087
    Tim Rentsch
    Nov 10, 2008
  5. fungus
    Replies:
    13
    Views:
    870
    fungus
    Oct 31, 2008
Loading...

Share This Page