473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

To return a value or not to return a value, that is the question

I have a class Vector (representing a 3D Vector). I want to normalize that Vector (to give it a length of 1). From the three possibilities below (or feel free to suggest your own) what would you guys choose?

1. Normalize function that modifies the object:
Expand|Select|Wrap|Line Numbers
  1. public void Normalize()
2. Normalize function that returns a modified version of the object leaving the original object untouched.
Expand|Select|Wrap|Line Numbers
  1. public Vector Normalize()
3. Do both, modify the original and return that instance.
Expand|Select|Wrap|Line Numbers
  1. public Vector Normalize()
The question arises as I want to compare two vectors but I want to try and normalize the second vector within the equality operation:
Expand|Select|Wrap|Line Numbers
  1. v1 == v2.Normalize()
I like option 1 as it is simple when just normalizing a vector but stumps me for the problem above.
Jul 29 '10 #1
1 1081
Curtis Rutland
3,256 Expert 2GB
If you're going to be doing things like temporarily normalizing the vector for comparison purposes, I would suggest going with the second option. It's pretty easy to say v2 = v2.Normalize(); if you want to make your changes stick. Strings work that way, so it's not all that unfamiliar.
Jul 30 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Koji Ishii | last post by:
According to the doc, Stream.Read() returns: - # of bytes read, or - 0 for EOF But could that be a negative value? If so, how should we program against such case? I have a loop like this:...
8
by: Huibuh | last post by:
I start hating RETURN!!! list<happy> //#include <list>// is searched via iterator (ptr) so long until the argument "number" of the class "happy" is equal now. The function "findhappy" works...
5
by: Neal Coombes | last post by:
Posted to comp.lang.c++.moderated with little response. Hoping for better from the unmoderated groups: -------- Original Message -------- Subject: Return appropriately by value, (smart)...
15
by: Greenhorn | last post by:
Hi, when a function doesn't specify a return type ,value what value is returned. In the below programme, the function sample()is returning the value passed to 'k'. sample(int); main() { int...
4
by: Wardeaux | last post by:
Hope this is easy... I have a simple winform app that does some work and then exits... I need to return a value to the calling app/process to indicate completion status... what's the...
6
by: Shay1975 | last post by:
I am trying to return a variable value in a cursor below but I get the following error. I am not very familiar with PL/SQL so any help would be great. It compiles fine ...
4
by: Wayne Shu | last post by:
Hi everyone: I am reading Bjarne Stroustrup's The C++ Programming Language(Special Edition). In section 7.3, bs wrote "Like the semantics of argument passing, the semantics of function value...
2
by: nologo | last post by:
Hi, Visual Studio 2005, C#.net I wish to return a NULL value from a date control if no date is selected. Anyone got any idea on how i would do this? Cheers
1
by: psycho | last post by:
How do we return a single value from a stored procedure. Suppose I have a stored procedure like this: create proc dbo.spInsertGroup @ID uniqueidentifier @GroupName varchar(100), @IsActive...
33
by: zamaam0728 | last post by:
I am at the end of my first semester of C++, and I'm not sure what I should do to make this program meet the requested specifications. The assignment is as follows: Write a function called...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.