I need help solving a compile error in the following code.
I am trying to set an array size at compile time.
Child class will be in a library, and the user would pass in the array size via non-type template argument.
Using a non-type template argument to set array size would avoid the overhead of dynamically allocate the array.
This is for an Arduino microprocessor, so C++11 and vectors are not an option.
It compiles when line 22 commented:
class Parent
{
};
template <constint SAMPLE_COUNT> //Non-type Template Argument
class Child : public Parent
{
private:
int samples[SAMPLE_COUNT];
};
class Matrix
{
private:
Parent* ptrParent;
public:
Matrix(Parent* pd): ptrParent(pd) {}
};
Child<3> child1();
Matrix matrix0(&child1);
int main() {}
output:
C:\Users\wolf\Documents\demo_MinGW>g++ error.cpp
error.cpp:22:23: error: no matching function for call to 'Matrix::Matrix(Child<3
> (*)())'
Matrix matrix0(&child1);
^
error.cpp:22:23: note: candidates are:
error.cpp:17:3: note: Matrix::Matrix(Parent*)
Matrix(Parent* pd): ptrParent(pd) {}
^
error.cpp:17:3: note: no known conversion for argument 1 from 'Child<3> (*)()'
to 'Parent*'
error.cpp:12:7: note: Matrix::Matrix(const Matrix&)
class Matrix
^
error.cpp:12:7: note: no known conversion for argument 1 from 'Child<3> (*)()'
to 'const Matrix&'
C:\Users\wolf\Documents\developer\uC\teensy\demo_MinGW>