class C
{
public:
void DoSomething(int n, C* ptrs[]) {
// do something with n number of pointers from ptrs array...
}
};
C c1, c2, c3, c4;
C* arr[] = {&c2, &c3, &c4};
c1.DoSomething(3, arr);
Alternatively:
class C
{
public:
template<size_t n>
void DoSomething(C* (&ptrs)[n]) {
// do something with n number of pointers from ptrs array...
}
};
C c1, c2, c3, c4;
C* arr[] = {&c2, &c3, &c4};
c1.DoSomething(arr);
Alternatively:
#include <initializer_list>
class C
{
public:
void DoSomething(std::initializer_list<C*> ptrs) {
// do something with ptrs...
}
};
C c1, c2, c3, c4;
c1.DoSomething({&c2, &c3, &c4});
Alternatively:
class C
{
public:
void DoSomething() {}
template<typename ...Ts>
void DoSomething(C* c, Ts... args) {
// do something with c...
DoSomething(args...);
}
};
C c1, c2, c3, c4;
c1.DoSomething(&c2, &c3, &c4);