warning question (C4114)

Discussion in 'C++' started by michael.goossens@gmail.com, May 31, 2008.

  1. Guest

    1>e:\development\root\root\vector3.h(24) : warning C4114: same type
    qualifier used more than once
    1>e:\development\root\root\vector3.h(24) : warning C4114: same type
    qualifier used more than once
    1>e:\development\root\root\vector3.h(82) : warning C4114: same type
    qualifier used more than once

    line 24: Vector3( const Vector3 const * v );
    line 82: inline Vector3::Vector3( const Vector3 const * v )

    Ok I get that it is because I use const twice.
    But I learned that it has to be done like that =s.

    The first const is for making sure the object cannot be changed and
    the second one so the pointer cannot be changed. So is this a
    misinterpretation of mine? Or is there something else.
    , May 31, 2008
    #1
    1. Advertising

  2. Eric Pruneau Guest

    <> a écrit dans le message de news:
    ...
    >1>e:\development\root\root\vector3.h(24) : warning C4114: same type
    > qualifier used more than once
    > 1>e:\development\root\root\vector3.h(24) : warning C4114: same type
    > qualifier used more than once
    > 1>e:\development\root\root\vector3.h(82) : warning C4114: same type
    > qualifier used more than once
    >
    > line 24: Vector3( const Vector3 const * v );
    > line 82: inline Vector3::Vector3( const Vector3 const * v )
    >
    > Ok I get that it is because I use const twice.
    > But I learned that it has to be done like that =s.
    >
    > The first const is for making sure the object cannot be changed and
    > the second one so the pointer cannot be changed. So is this a
    > misinterpretation of mine? Or is there something else.



    try

    Vector3( const Vector3 * const v );

    const can be used on either side of Vector3 so

    Vector3( const Vector3 v );
    is the same as
    Vector3(Vector3 const v );

    so
    Vector3( const Vector3 *v );
    is the same as
    Vector3( Vector3 const * v );
    so writting
    Vector3( const Vector3 const * v );
    is redundant
    Eric Pruneau, May 31, 2008
    #2
    1. Advertising

  3. Guest

    aaah thanks

    so i should have done

    Vector3(Vector3 cosnt * const v) or Vector3(const Vector3 * const v)

    yeah sounds logical if you think about it :).
    , May 31, 2008
    #3
  4. On 2008-05-31 15:41, wrote:
    > aaah thanks
    >
    > so i should have done
    >
    > Vector3(Vector3 cosnt * const v) or Vector3(const Vector3 * const v)
    >
    > yeah sounds logical if you think about it :).


    You should read declarations backwards:

    int const * ptr

    ptr is a pointer to a constant int

    and

    int * const ptr

    ptr is a constant pointer to an int

    and finally

    int const * const ptr

    ptr is a constant pointer to a constant int

    --
    Erik Wikström
    Erik Wikström, May 31, 2008
    #4
  5. James Kanze Guest

    On May 31, 3:07 pm, ""
    <> wrote:
    > 1>e:\development\root\root\vector3.h(24) : warning C4114: same type
    > qualifier used more than once
    > 1>e:\development\root\root\vector3.h(24) : warning C4114: same type
    > qualifier used more than once
    > 1>e:\development\root\root\vector3.h(82) : warning C4114: same type
    > qualifier used more than once


    > line 24: Vector3( const Vector3 const * v );
    > line 82: inline Vector3::Vector3( const Vector3 const * v )


    > Ok I get that it is because I use const twice.
    > But I learned that it has to be done like that =s.


    > The first const is for making sure the object cannot be
    > changed and the second one so the pointer cannot be changed.
    > So is this a misinterpretation of mine? Or is there something
    > else.


    It's a misinterpretation of yours. Generally speaking, const
    modifies what precedes it, so Vector3 const* is a non-const
    pointer to a const Vector3, Vector3 *const is a const pointer to
    a non-const Vector3, and Vector3 const *const is a const pointer
    to a const Vector3.

    For historical reasons, if nothing precedes the const, then it
    applies to whatever follows, so const Vector3 * is the same as
    Vector3 const*. It's probably best to always put the const
    after, however, and avoid confusion.

    --
    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 1, 2008
    #5
  6. LR Guest

    Erik Wikström wrote:

    > You should read declarations backwards:


    Wouldn't it be better to use the right left rule?

    >
    > int const * ptr
    >
    > ptr is a pointer to a constant int

    [snip]

    How would you apply your suggestion to this?

    int *p[];

    LR
    LR, Jun 1, 2008
    #6
    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. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    ASP.Net "Warning :Page has expired" Question

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Dec 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,659
    Kumar Reddi
    Dec 2, 2004
  2. Pete Becker
    Replies:
    0
    Views:
    1,374
    Pete Becker
    Feb 10, 2005
  3. B. Williams

    warning C4267 and warning C4996

    B. Williams, Oct 26, 2006, in forum: C++
    Replies:
    17
    Views:
    2,631
  4. WARNING! Prosoftstore.com is a SCAM! WARNING!

    , Jul 8, 2007, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    318
  5. Julian Mehnle
    Replies:
    17
    Views:
    874
    Julian Mehnle
    May 18, 2006
Loading...

Share This Page