warning question (C4114)

M

michael.goossens

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

Eric Pruneau

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
 
M

michael.goossens

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 :).
 
E

Erik Wikström

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
 
J

James Kanze

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.
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top