Is this possible anyway

Say if i have a class or function that has an array parameter that can be passed in.
Is there anyway to pass it in without having a premade variable.

eg
1
2
3
4
5
6
7
8
9
class myClass
{
    public:
         myClass(float passArray[3]): storeArray(myArray){//}
         float storeArray[3];
}
/* is there a way to pass in 3 numbers instead of an array and have them count as an array eg:
myClass object(1,2,3);
*/


I know of creating a seperate constructor and setting x y z to [0][1][2] of the array if thats suggested.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
class myClass
{
    public:
         myClass(float passArray[3]): storeArray(myArray){}

         myClass(float a, float b, float c)
         { storeArray[0] = a;
           storeArray[1] = b;
           storeArray[2] = c;}

         float storeArray[3];
}
Last edited on
Must of posted my edit when you was writing that, im aware of that, but its not what im after. Thanks for the reply though.
why don't you want to either make an array to pass to it, or make a constructor accept 3 floats?
but its not what im after.


So what are you after? Show us the line of code you would like to use to create the object, and we'll tell you how to do it.
You mean...like a vector?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <vector>
#include <iostream>


int main ()
{
 int a[]={1,2,3,4,5};

 std::vector<int> b(a,a+5);

 for( auto c : b)
  std::cout << c << std::endl;

}
Topic archived. No new replies allowed.