Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C: Casting an int array to a double array?

  • 09-12-2004 09:30PM
    #1
    Registered Users, Registered Users 2 Posts: 3,354 ✭✭✭


    Is it possible to convert an int array to a double array?

    I have written a function which accepts an array of doubles as an argument.

    Most of the time I will be passing an array of doubles to it, but in one location in my program, I need to pass an array of ints to it.

    I've tried casting the array to a double array, but no luck.

    Is there a way of doing this? I might be doing it wrong.

    I suppose I could always use a for loop to cast each individual array element to a double, and then put those doubles into a new array...


Comments

  • Registered Users, Registered Users 2 Posts: 1,865 ✭✭✭Syth


    A for loop does seem like the best way to do it...


  • Registered Users, Registered Users 2 Posts: 3,354 ✭✭✭radiospan


    Yep, that did it, thanks.
    for( i= 0; i<= 7; i++ ) {
    				doublebytes[i] = double(bytes[i]);
    			}
    


  • Registered Users, Registered Users 2 Posts: 7,279 ✭✭✭kenmc


    why would you not handle it as a double always?
    or, at least pass it as an unadulterated array to the function and let the function cast the necessary elements to ints inside it if it still needs to play with ints??
    but yeah, you basically can't cast an array of things at once


Advertisement