Sorry for this being a really newbie question; I know that I read it in one of the tutorials but I simply can't find it now...
What I mean is a variable ending with a *, like
Code:int my_var*;
Printable View
Sorry for this being a really newbie question; I know that I read it in one of the tutorials but I simply can't find it now...
What I mean is a variable ending with a *, like
Code:int my_var*;
A compiler error.
Ones like this though
Are called pointersCode:int *myVar;
Maybe it wasn't a variable.. but -something- ends with *...
maybe you saw it written aswhich is pretty much what prog-bman just showed you... and it's evil. don't do it.Code:int* myvar;
That's how I always declare pointers.
Looks weird. I guess you could do:Code:int *pointer;
For a compromise...Code:int * pointer;
I can't think of any valid C++ code ends with a *. Maybe a function prototype with a pointer parameter and no variable name specified:>> and it's evil. don't do it.Code:void foo(int* );
major_small must be kidding. Don't take that seriously.
no, I'm not. consider this:Quote:
Originally Posted by Daved
that makes it look like you may have intended both to be pointers, where only the first one is a pointer... and it just gets messy... for example:Code:int* myVar1,myVar2;
usually I declare pointers like so:Code:int* myVar1,myVar2,myVar3,*myVar4,myVar5;
as you can see, I generally declare each variable on it's own line.Code:int*myVar1;
int myVar2;
ohhh, Major Small is using old school declarations, not overloading any one line.
makes for much easier to read declarations. :)
void junk (vector <Books*>& v);
hmm.. thats like the only time i can see it on the rite side is in a funtion like it was said .
>> no, I'm not. consider this
I wouldn't consider that to be a question of evil. It's more a question of style. I'd put the evilness on the declaration of multiple variables on one line if something had to be called evil.
Consider this:Same issue, but = 0 is not evil, and there is nothing wrong with int myVar1 = 0;.Code:int myVar1,myVar2,myVar3,myVar4,myVar5 = 0;
My personal style is int* myVar. I never declare multiple pointers on the same line. I rarely declare multiple variables on the same line. This doesn't make the code extraordinarily long, since I rarely declare many variables together (declare variables as locally as possible). I also don't put them on the same line since I always try to initialize variables (especially pointers) when I declare them. The benefit is that it makes clear to me that the type is a pointer to int.
So int* myvar is not evil and IMO you can use it if you like.
I'll agree that it's a question of style, but that style is just evil.
take a look at this page and tell me that it's not evil. Sure, it's just a style, but it's an evil style ;)
You're right. Certain styles can be evil.
(But this is not one of them.)
I agree with Daved. Pointers are not a style :p and they are not evil. They are part of the language, and an important one at that.Quote:
Originally Posted by Daved
erm, we weren't talking about the pointers themselves, but how you choose to declare them. :rolleyes:Quote:
Originally Posted by MitchellH
Hey wait, I said that putting the * next to the type is not evil:I didn't say that pointers themselves aren't evil.Code:int* myvar;
They are.
(Of course, I am only kidding, although I tend to agree with that link in spirit.)