Quantcast
Channel: Active questions tagged header - Stack Overflow
Viewing all articles
Browse latest Browse all 649

How to correctly declare function with templated class as return type in header? [duplicate]

$
0
0

I have a template class declared in a header file.

// Matrix.htemplate <class X> class Matrix {};

In another header file I have a function declaration which has an instantiation of that template class as return type:

// OtherModule.hMatrix<double> do_stuff();

In the source file of the other module I include the header of the Matrix class:

// OtherModule.cpp#include "Matrix.h"Matrix<double> do_stuff() {  // do stuff}

How do I make the compiler know what Matrix<double> is in the OtherModule header file without including Matrix.h in the header itself?

I tried forward declaration as shown here:

// OtherModule.htemplate class Matrix<double>Matrix<double> do_stuff();

but it doesn't work.


Viewing all articles
Browse latest Browse all 649

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>