Arguments question

This is a discussion on Arguments question within the C++ Programming forums, part of the General Programming Boards category; Hallo, I have a question about aruments. One of my classes takes a Vector3D as an argument (3 floats), which ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485

    Arguments question

    Hallo,

    I have a question about aruments.

    One of my classes takes a Vector3D as an argument (3 floats), which is fine in some cases, but I have to do like this

    Vector3D pos(0,0,10);
    sphere.setPos(pos);

    Sometimes it wuld be nice to be able to do:
    Sphere.setPos(0,0,10)

    Is there a way so that I can switch between the two ways?

    thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,773
    Well, if you did not actually need pos, you could write:
    Code:
    sphere.setPos(Vector3D(0, 0, 10));
    Alternatively, if you are able to change the class of the sphere object, you could overload its setPos() member function.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Thank you, that works perfect for me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Command Line arguments question
    By micpi in forum C Programming
    Replies: 7
    Last Post: 04-24-2007, 08:46 PM
  2. question aboout arguments
    By only1st in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2007, 08:36 PM
  3. registry, services & command line arguments.. ?
    By BrianK in forum Windows Programming
    Replies: 3
    Last Post: 03-04-2003, 01:11 PM
  4. Easy question about arguments in a function
    By pond-person in forum C++ Programming
    Replies: 5
    Last Post: 12-12-2002, 09:36 PM
  5. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 02:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21