0

I've got a templated class mostly dedicated to holding a boost:: multi_array. I am trying to initialize the array in the initialization class, but I am getting an error:

template <typename T>
class Hist2D
{
private:
  typedef boost::multi_array<T, 2> array_type;
  array_type MatrixCount;

public:
  Hist2D(int width, int height): array_type MatrixCount(boost::extents[width][height]){}; 
};

This gives the following error:

ctest.cpp: In constructor ‘Hist2D<T>::Hist2D(int, int)’:
ctest.cpp:34:45: error: expected ‘(’ before ‘MatrixCount’
   Hist2D(int width, int height): array_type MatrixCount(boost:extents[width][height]){}; 
                                             ^
ctest.cpp:34:45: error: expected ‘{’ before ‘MatrixCount’

What do these errors mean?

1
  • The error means you're trying to invent syntax of your own. If you replaced array_type MatrixCount; with int MatrixCount;, would this make sense? Hist2D() : int MatrixCount(10) {} Commented Jul 16, 2015 at 22:35

1 Answer 1

3

It is a syntax error. You do not need to declare the type in the initialization list.

Try this:

Hist2D(int width, int height): MatrixCount(boost::extents[width][height]){}

C++ compilation errors can be confusing. You'll get used to them after a while :D

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

2 Comments

@Praetorian thanks for the fix up, didn't spot those mistakes
Yup, I always find that the toughest part of learning a new language, and C++ does seem more confounding than others. Thanks a lot.

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.