Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > meaning of *& syntax

Reply
Thread Tools

meaning of *& syntax

 
 
Hansen
Guest
Posts: n/a
 
      02-13-2007
Hi there,

I just came across the following syntax in a class declaration:

my_base*& base_;

What does that mean? Is it a pointer to a reference? In my head * and & are
opposites meaning that my_base*& == my_base ...
But I have a feeling that I'm wrong ... )

Best Regards
Hansen


 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      02-13-2007
Hansen wrote:

> Hi there,
>
> I just came across the following syntax in a class declaration:
>
> my_base*& base_;
>
> What does that mean? Is it a pointer to a reference?


No. There are no such things as pointers to references. It's just the other
way round. It's a reference to a pointer.

> In my head * and & are opposites meaning that my_base*& == my_base ...


my_base*& is a type. What you mean would be *&my_base.

 
Reply With Quote
 
 
 
 
Clark S. Cox III
Guest
Posts: n/a
 
      02-13-2007
Hansen wrote:
> Hi there,
>
> I just came across the following syntax in a class declaration:
>
> my_base*& base_;
>
> What does that mean? Is it a pointer to a reference?


Close, it's a reference to a pointer.

> In my head * and & are
> opposites meaning that my_base*& == my_base ...
> But I have a feeling that I'm wrong ... )


Just like (int&) is a reference to an int, (int*&) is a reference to an
int pointer.


--
Clark S. Cox III
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Grizlyk
Guest
Posts: n/a
 
      02-13-2007

Hansen wrote:
>
> I just came across the following syntax in a class declaration:
>
> my_base*& base_;
>
> What does that mean?


"cdecl/cppdecl" can help you sometimes to resolve c-language expressions.

Also find a table with "C++ precedens of operators": all operators have
divided on groups by "priority level" and "associativity" ("left to right"
or "right to left").


--
Maksim A. Polyanin

"In thi world of fairy tales rolls are liked olso"
/Gnume/



 
Reply With Quote
 
Clark S. Cox III
Guest
Posts: n/a
 
      02-13-2007
Grizlyk wrote:
> Hansen wrote:
>> I just came across the following syntax in a class declaration:
>>
>> my_base*& base_;
>>
>> What does that mean?

>
> "cdecl/cppdecl" can help you sometimes to resolve c-language expressions.
>
> Also find a table with "C++ precedens of operators": all operators have
> divided on groups by "priority level" and "associativity" ("left to right"
> or "right to left").


This is not entirely true, some of the relationships between the
operators cannot be expressed in a simple precedence table.

--
Clark S. Cox III
(E-Mail Removed)
 
Reply With Quote
 
Grizlyk
Guest
Posts: n/a
 
      02-13-2007
Clark S. Cox III wrote:
>>
>> Also find a table with "C++ precedens of operators": all operators have
>> divided on groups by "priority level" and "associativity" ("left to
>> right"
>> or "right to left").

>
> This is not entirely true, some of the relationships between the
> operators cannot be expressed in a simple precedence table.


For example?

--
Maksim A. Polyanin

"In thi world of fairy tales rolls are liked olso"
/Gnume/


 
Reply With Quote
 
=?ISO-8859-15?Q?Juli=E1n?= Albo
Guest
Posts: n/a
 
      02-13-2007
Grizlyk wrote:

>> This is not entirely true, some of the relationships between the
>> operators cannot be expressed in a simple precedence table.

> For example?


Yes.

--
Salu2
 
Reply With Quote
 
Clark S. Cox III
Guest
Posts: n/a
 
      02-13-2007
Grizlyk wrote:
> Clark S. Cox III wrote:
>>> Also find a table with "C++ precedens of operators": all operators have
>>> divided on groups by "priority level" and "associativity" ("left to
>>> right"
>>> or "right to left").

>> This is not entirely true, some of the relationships between the
>> operators cannot be expressed in a simple precedence table.

>
> For example?
>


Consider the relationship between the '=' operator and the '?:' operator:

a?b:c=3; //Equivalent to a?bc=3)
a?b=3:c; //Equivalent to a?(b=3):c
a=3?b:c; //Equivalent to a=(3?b:c)


--
Clark S. Cox III
(E-Mail Removed)
 
Reply With Quote
 
Craig Scott
Guest
Posts: n/a
 
      02-14-2007
> > I just came across the following syntax in a class declaration:
>
> > my_base*& base_;

>
> > What does that mean? Is it a pointer to a reference?

>
> Close, it's a reference to a pointer.
>
> > In my head * and & are
> > opposites meaning that my_base*& == my_base ...
> > But I have a feeling that I'm wrong ... )

>
> Just like (int&) is a reference to an int, (int*&) is a reference to an
> int pointer.


Since the OP hasn't seen this before, I mention the following as
additional info. It can be useful to pass a "reference to a pointer"
to functions that need to change what the pointer points to from the
*caller's* point of view. For example (this is a very contrived
example):

void func(int*& foo, int* t)
{
// A real function would obviously do something
// more meaningful here!
foo = t;
}

int main(int argc, char* argv[])
{
int a = 0;
int b = 1;
int* myFoo = &a;

// This prints the value of a, which is 0
std::cout << *myFoo << std::endl;

// This will change myFoo to point to b
func(myFoo, &b);

// This now prints the value of b, which is 1
std::cout << *myFoo << std::endl;
}


Member variables can also be used in a similar fashion, but in my
experience, that is less common (but not any more or less valid).

--
Computational Fluid Dynamics, CSIRO (CMIS)
Melbourne, Australia

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Understanding search queries, semantics, and "Meaning" ...aren't weall looking for meaning? 5lvqbwl02@sneakemail.com Python 4 01-14-2009 02:28 PM
Syntax Checker that's better than the normal syntax checker Jacob Grover Ruby 5 07-18-2008 05:07 AM
Syntax bug, in 1.8.5? return not (some expr) <-- syntax error vsreturn (not (some expr)) <-- fine Good Night Moon Ruby 9 07-25-2007 04:51 PM
[ANN] SqlStatement 1.0.0 - hide the syntax of SQL behind familiarruby syntax Ken Bloom Ruby 3 10-09-2006 06:46 PM
Syntax highligth with textile: Syntax+RedCloth ? gabriele renzi Ruby 2 12-31-2005 02:44 AM



Advertisments