polymorphism with template<>

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Parent
{
};

template <const int 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>

Thank you.
Last edited on
Child<3> child1(); Declares a function.
Try it without the parentheses.
That was it! I always miss the simple things when it gets complicated.

Thanks for your help norm b.
Topic archived. No new replies allowed.