1

I'd like to instanciate my object with template parameters only. One of the parameters is a pointer to array, and I'm looking for the correct syntax.

const MyCustomType* array[2] = { &object1, &object2 };

OBJ1 < 10, 10, array > myobj1;

Below, a sample of the class OBJ1.

template < int a, int b, /* help ! */ >
class OBJ1
{
  public:
    OBJ1();
    ~OBJ1();

  private:
    //methods
};

What's the right syntax to use the third template parameter ? Is that even possible ?

2
  • That's not a pointer to an array, it's an array of [2] pointers. Commented Oct 12, 2012 at 9:29
  • @BenjaminLindley You're right :p Commented Oct 12, 2012 at 9:36

1 Answer 1

1

For an array of type int of size n the syntax is

int (*paramname)[N];

Or with a helper type alias

template<typename T>
using type = T;

Then

type<int[N]> *paramname;

In your case you pass a pointer to the arrays first element though, and not a pointer to the array. You need to prefix the array name with & to do the latter when passing the array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.