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
    21,598
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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