473,756 Members | 3,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reference syntax? (noob)

Calling the function

"float dist = Splines.Pick(Ve ctor2(x,y), 5.0f, type, &point);"
The function is now defined as

float BSpline::Pick(V ector2Coord, float radius, ePickType &type, Vector3
&point){}

I want to be able to change the point class it returns.

What is the syntax for making the "point" a reference that I can change?

Thanks.

//michael
Oct 8 '06 #1
4 1804
"Michael Holm" <Mi*********@th ismaildontwork. comwrote in message
news:45******** *************** @dread15.news.t ele.dk...
Calling the function

"float dist = Splines.Pick(Ve ctor2(x,y), 5.0f, type, &point);"
The function is now defined as

float BSpline::Pick(V ector2Coord, float radius, ePickType &type, Vector3
&point){}

I want to be able to change the point class it returns.

What is the syntax for making the "point" a reference that I can change?

Thanks.

//michael
Umm..., point is a reference. That's what the & in front of it means.
point is a reference to a Vector3 object.
Oct 8 '06 #2
LR
Jim Langston wrote:
"Michael Holm" <Mi*********@th ismaildontwork. comwrote in message
news:45******** *************** @dread15.news.t ele.dk...
>>Calling the function

"float dist = Splines.Pick(Ve ctor2(x,y), 5.0f, type, &point);"
The function is now defined as

float BSpline::Pick(V ector2Coord, float radius, ePickType &type, Vector3
&point){}

I want to be able to change the point class it returns.

What is the syntax for making the "point" a reference that I can change?

Thanks.

//michael


Umm..., point is a reference. That's what the & in front of it means.
point is a reference to a Vector3 object.
That's what I thought at first, but then I figured that might have
missed the.... no, wait, too obvious.

Ok.

In this thing (which won't compile)
float BSpline::Pick(V ector2Coord, float radius, ePickType &type, Vector3
&point){}

Pick is a member function of BSlpine which returns a float. 'point' is
a function parameter (I don't know if that's what it's called formally),
and is in fact, as JL pointed out, a reference. You could change the
object that is being referenced in the function, if that's what you want
to do.
>>Calling the function
float dist = Splines.Pick(Ve ctor2(x,y), 5.0f, type, &point);
Seems to me that it would be unlikely to work.

Suppose we have:

BSpline Splines;
ePickType someType;
Vector3 somePoint;

and then we do this

float dist = Splines.Pick(Ve ctor2(x,y), 5.0f, someType, &somePoint);

is not going to work, because in this context '&somePoint' is trying to
pass the address (ie a pointer) of somePoint to Pick.

Instead, try

float dist = Splines.Pick(Ve ctor2(x,y), 5.0f, someType, somePoint);

Also, Pick will have to return a value. Those empty {} braces shouldn't
compile. I think.

BTW, do you change Splines? If not, then maybe Pick should be const, ie
float BSplines::Pick( Vector2Coord, float radius, ePickType &type,
Vector3 &point) const { return float(0); }

Does type or point change? If not then maybe they should be const too.

float BSplines::Pick(
Vector2Coord, // do you use this in Pick?
float radius, // maybe should be const too?
const ePickType &type,
const Vector3 &point
) const {
return float(0.); //
}

But, if Pick is really returning something called dist, and a point as
well, then you ought to consider doing something like:

std::pair<float ,Vector3BSpline s::Pick(
Vector2Coord,
float radius,
const ePickType &type
) const {
// whatever you need to do, and return
return std::make_pair( 0.f, Vector3());
}

Warning, I haven't tried to compile any of this.

LR
Oct 8 '06 #3

Michael Holm wrote:
Calling the function

"float dist = Splines.Pick(Ve ctor2(x,y), 5.0f, type, &point);"
remove the address_of operator in front of the point variable in the
call.
>

The function is now defined as
actually, thats a proptotype, not a definition
>
float BSpline::Pick(V ector2Coord, float radius, ePickType &type, Vector3
&point){}

I want to be able to change the point class it returns.
Pick(...) returns a float, did you mean change the Point class it takes
as a parameter?
Did you mean that you want to reseat the reference?
>
What is the syntax for making the "point" a reference that I can change?
references are mutable by nature, what you can't do is reseat it.
Is that Point or point?
>
Thanks.

//michael
Oct 8 '06 #4

"Michael Holm" <Mi*********@th ismaildontwork. comwrote in message
news:45******** *************** @dread15.news.t ele.dk...
Calling the function

"float dist = Splines.Pick(Ve ctor2(x,y), 5.0f, type, &point);"
The function is now defined as

float BSpline::Pick(V ector2Coord, float radius, ePickType &type, Vector3
&point){}

I want to be able to change the point class it returns.

What is the syntax for making the "point" a reference that I can change?
Assuming that you're talking about the third parameter, point, that already
IS a reference. To use it, pass a Vector3 instance, not the address of one.
(In other words, assuming point is a Vector3 object, pass "point", not
"&point".)

What's "Vector2Coo rd"? Is that a typo? Did you mean "Vector2 coord"? If
not, then the type you're passing (a "Vector2") doesn't exactly match a
"Vector2Coo rd" (although there may be some automatic conversion I don't see
here), and also that means you haven't named the first parameter, which
makes it impossible to use inside the function.

Instead of typing code into your posts, try using copy&paste, so that we see
the real code. And let us know exactly what problem you're having. The
function above already uses a reference for the point parameter, so your
question doesn't really make much sense. If you'r problem is that you're
getting a compile error trying to write code to call the function (due to
passing &point instead of point), then you should post the error you're
getting, ok? That way we know what question we're really trying to answer.

-Howard

Oct 9 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2460
by: Ivan Shevanski | last post by:
Here's a noob question for everyone (I'm not sure if my first message got through, is had a "suspicious header" so sorry for double post is so), is there a way to turn off syntax warnings or just make them not visible? Thanks, -Ivan _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's FREE!
0
1251
by: Ivan Shevanski | last post by:
Here's a noob question for everyone which i can't seem to find the answer to on google. . .Is there a way to turn off syntax warnings? -Ivan _________________________________________________________________ FREE pop-up blocking with the new MSN Toolbar – get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
1
2828
by: hippo | last post by:
I am having trouble using the InDesign 2 library in VB net. I make a new exe project and open the project>add reference. I then browse to the reference and add it. However it shows up in the object browser as interop.indesign instead as indesign type library. I can get this to work in VB for controls 5. I'm v noob to this and I know this is a bit of an esoteric question but any help would be appreciated.
3
5435
by: Rich | last post by:
Another noob question for you all . . . I have functions written in C++ that I want to call from C#. I need to be able to pass a reference to a value type (like an int) so that the function can change the value - just like passing a pointer to an int in good old unmanaged C. Here is the function in C++ (member of testclass) - this compiles to a DLL without error in C++:
10
16671
by: ravi | last post by:
Hi, i am a c++ programmer, now i want to learn programming in c also. so can anybody explain me the difference b/w call by reference and call by pointer (with example if possible).
41
3660
by: Summercool | last post by:
Can we confirm the following? also someone said, Java also has "reference" like in C++, which is an "implicit pointer": Pointer and Reference --------------------- I am starting to see what pointer and reference are and how they relate to each other.
4
1588
by: Lumpy | last post by:
I am a complete noob with Access, and have been struggling along for a while and now reached a point where I am just stuck. I had made a custom form where some of it populates through other SQL queries and some of the information gets entered in by hand/keyboard. Now I am at the point where I want to save the data in the form to a table when the user clicks the button and I am having some syntax errors. The first way I tried is like...
7
1538
by: krishna | last post by:
What is the need of this syntax for initializing values, isn't this ambiguous to function call? e.g., int func_name(20); this looks like function call (of course not totally as there is no function body), but is declaration and initialization of an integer variable 'func_name', is it step towards completeness of OOP abstraction in the language, here one could say we are creating and initializing an integer object, but then again it (this...
275
12365
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.