Difference


Dear all,

Can some body explain the difference between

Basemap* basemap

and

Basemap *basemap


Thanks in advance
The meaning is exactly the same.
closed account (E0p9LyTq)
Basemap* basemap is the same as

Basemap * basemap is the same as

Basemap *basemap
Basemap* basemap
and
Basemap *basemap

They are just exactly the same.

Did you mean this :
Basemap* basemap
and
Basemap *basemap2

???
Did you mean this :
Basemap* basemap
and
Basemap *basemap2


Query:what makes the difference?
Is the two instance [basemap & basemap2] are created for the class Basemap?
closed account (48T7M4Gy)
It's also the same as Basemap*basemap
Dear All,

Thanks for the replies.

MMGIS
Am I missing something here??!
https://isocpp.org/wiki/faq/style-and-techniques#whitespace

For C++ they recommend Basemap* basemap because it emphasises the type.
closed account (48T7M4Gy)
I agree as it's clearer to me but the bottom line is it doesn't matter. Here's another authority.

Is ``int* p;'' right or is ``int *p;'' right?

http://www.stroustrup.com/bs_faq2.html#whitespace
It doesn't matter for the compiler but it might matter to people.
closed account (48T7M4Gy)
It doesn't matter for the compiler but it might matter to people.

Well read, that's exactly what Stroustrup says with his usual impeccable logic and advice.
Last edited on
closed account (E0p9LyTq)
TheIdeasMan wrote:
For C++ they recommend Basemap* basemap because it emphasises the type.


With that emphasis on type declaring multiple variables on a single line can cause problems.

int* p1, p2; // error!

p1 is a pointer to an int, p2 is just a POD int. Variables should always be declared on separate lines.

1
2
int* p1;
int  p2;


Readability is for us humans, the compiler doesn't need all the whitespace and extra lines.
> declaring multiple variables on a single line can cause problems.

The critical confusion comes (only) when people try to declare several pointers with a single declaration:
int* p, p1; // probable error: p1 is not an int*

Placing the * closer to the name does not make this kind of error significantly less likely.
int *p, p1; // probable error?

Declaring one name per declaration minimizes the problem - in particular when we initialize the variables. People are far less likely to write:
1
2
	int* p = &i;
	int p1 = p;	// error: int initialized by int* 
And if they do, the compiler will complain.

Stroustrup - http://www.stroustrup.com/bs_faq2.html#whitespace
Last edited on
closed account (48T7M4Gy)
Whenever something can be done in two ways, someone will be confused.

Whenever something is a matter of taste, discussions can drag on forever.

Stick to one pointer per declaration and always initialize variables and the source of confusion disappears.

Stroustrup - http://www.stroustrup.com/bs_faq2.html#whitespace

... now flogged to a standstill.
http://idioms.thefreedictionary.com/flog+to+death
Topic archived. No new replies allowed.