Skip to main content
9 events
when toggle format what by license comment
May 31, 2017 at 7:01 comment added Code Gorilla If you can spot my mistakes and correct them then I think you have got it :) Sorry about that, yes you corrected it right. Yes you are "correct" about Print. By "correct" I mean you understanding is good enough for a beginner, but someone may come along and expand your understand later in life. Good luck
May 30, 2017 at 16:21 vote accept Andrea Ciufo
May 30, 2017 at 16:21 comment added Andrea Ciufo So, if i undestood, Print is not a method rather a data type. cgp and Serial are two objects from two different classes. I can invoke the method .print(Time0) on the two objects because they are "printable" a sort of operation like the operation of "sum" that i can do with int data types? :) Thanks :)
May 30, 2017 at 16:05 comment added Andrea Ciufo Thanks for your patience. I made an error studying your answer, mea culpa, my question about the class inside the function was nosense :( In the last comment you wrote this void add (int a) {++a;} int a = 0; a = add(a); // a = 0 against void add (int a) {++a;} int a = 0; a = add(a); // a = 1 but is the same. Maybe, if i understood , you will write this void add (int a) {++a;} int a = 0; a = add(a); // a = 0 against void add (int& a) {++a;} int a = 0; a = add(a); // a = 1 ? Thanks a lot @Code Gorilla it is very useful for me and I'm very grateful to you :)
May 30, 2017 at 7:10 comment added Code Gorilla The & turns the function parameter means the variable is "passed by reference". This means it is not copied, the address is passed to the function and it works on that memory address rather than the actual value. This means the parameter becomes an IN/OUT value, any modifications made inside the function are passed back to the caller. For example: void add (int a) {++a;} int a = 0; a = add(a); // a = 0 against void add (int a) {++a;} int a = 0; a = add(a); // a = 1 Note that (const int& a) in not modifiable.
May 30, 2017 at 7:06 comment added Code Gorilla I'm not clear what you mean. If you mean in the case of printImuData() you can't pass a class into the function. A class is a type name, so try doing what you are saying with a char or an int. If you have the function void DoStuff (int& a) can you call DoStuff (n); if int n = 4;? Yes or course you can, but can you pass in int does DoStuff(int); make sense? Its the same with classes if you have void OtherFunc(CHole& a); and then call CHole n; OtherFunc(n); calling OtherFunc(CHole) wouldn't make sense.
May 26, 2017 at 18:13 comment added Andrea Ciufo But is still not clear for me :( Inside the function you can put both a class and an object (istance of a class) that belong to that class, why? Why not only one of the two?
May 26, 2017 at 18:12 comment added Andrea Ciufo In the argument list ex int16_t Time0 i have 1st the data type and then the rval of my variable. In the case Print &printer i have something in the 1st place (an object that belong to the Print class) and a reference in the 2nd(something that inform the compiler about the lval of my variable referenced), but is not a Method. A Friend of mine from CS told me that Print was a method, so i belive he was wrong, this is one reason of my confusion.
May 25, 2017 at 13:54 history answered Code Gorilla CC BY-SA 3.0