ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Yes, it should be &var the & is supposed to go before the variable that it is associated with. also, are you using any uncommon namespaces? because instead of using std::cout you could use just cout if you did this at the beginning of the file.
#include <iostream>
using namespace std;
then you could use just cout and it would save you alot of time typing and far less errors
What exactly are you trying to do with that code? because I don't think that that is your only problem, it looks like you are wanting to send two variables into your function, but you need to add a semi-colon ( in between them in the function header.
The code looks fine to me, T is not a variable but a type specifier (I'm not sure what the proper term is).
As far as T& var and T &var are concerned, I think they mean the same thing. People do the same with pointers (e.g. int* my_pointer or int *my_pointer).
There is some more user friendly stuff out there to learn C++ I have tried nearly every website and book that you can buy, lol well not EVERY book or website. But, the best one that I have found is called "Object-Oriented Program Development Using C++" the ISBN is 0-619-15966-9. and this was the easiest for me to learn out of myself. I would definitely check it out if I were you, it is only about $30. and it is far less confusing then that website you were on!
The book I am referring too is actually a college textbook for their first computer science class, and I learned more reading that book then any other book. SO, if you are looking it up on like amazon or half, you might have to go to the text book area.
That is correct matthewg42, the reasons for using one form or another normally boil down to the idea of cleanliness when declaring pointers. for example
Code:
char *c,d,e;
//compared to:
char* c,d,e;
Yet this argument is mute really for references as they must be seated when declared.
char a = 56;
char &c,d = a;//invalid
sleepyhomme I have had a look at the reference docs which you are using as a learning aid and would have to reiterate the point that they are not a good learning source. I found a number of incorrect statements and facts, in addition his logic for the function 'zap' is just plain stupid.
See the following for a recommended reading. http://www.parashift.com/c++-faq-lite/ http://www.mindview.net/Books/TICPP/...ngInCPP2e.html
It's all in your style of code. I personally place pointer and reference qualifiers next to the variable name because they're associated with the variable, not the type. As was implied above, you get a pointer and an object doing this:
Code:
int* A, B;
but two pointers doing this:
Code:
int *A, *B;
It makes no difference which because the C++ ISO is too freaking huge as it is without arbitrary whitespace restrictions. You could even do this:
Code:
int*A,*B;
which many developers do. Use a style that makes sense to you, but be prepared to learn new styles if you ever plan to work with other developers.
ta0kira
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.