reference to type/object

First of all, I'd like to say hi to everyone as I am new to this place- so Hi!
As a newbie to C++ I have some lame questions, that I couldn't find answers to ;-)

The first one: what is a reference to type? I know references to variables (a bit different from pointers), but how would we refer to type?

The second question will include an example from the book I am learning from:
1
2
3
4
5
6
7
8
9
10
class SomeClass
{
int value=1;
friend void f1(SomeClass & p);
}

void f1 (SomeClass & p)
{
cout<<p.value;
}

To my knowledge references can work as pointers, so does this piece of code mean, that function f1 takes an argument being an object of type/class SomeClass and refers to it (manipulates the original instance of this object) using reference p just like a pointer?

Number three. Any good books on generic programming? I know I am still a bit far from it but I like to know things in advance :-)

Thank you for your time to read this post!
closed account (zb0S216C)
BR41NFCK wrote:
"Hi!"

Ay-up.

BR41NFCK wrote:
"what is a reference to type?"

There is no reference to types. References are aliases to other variables/objects; that is, they provide a alternative name for an existing variable/object. I guess you could say that "reference" is a synonym for variable x.

BR41NFCK wrote:
"but how would we refer to type?"

You can only refer to objects/variables, not types. When a parameter is of type reference, you're basically saying that reference x will refer to what ever you give it. Think about it, classes are templates for instances, so what good is a reference to a non-existent object?

BR41NFCK wrote:
"so does this piece of code mean, that function f1 takes an argument being an object of type/class SomeClass and refers to it (manipulates the original instance of this object) using reference p just like a pointer?"

Pretty much; yeah.

As for books, here's a few: http://stackoverflow.com/a/999976

Fill your boots :)

Wazzak
Last edited on
I am so grateful! If there was a "thank you" button, I'd set up a bot to click it like crazy :)
Topic archived. No new replies allowed.