Click to See Complete Forum and Search --> : pointer to a parametrized template


enkie
March 14th, 2002, 12:17 PM
Hello, everybody!

I'm trying to do some programming in VC6, and ran into the following problem. I made a CMatrix<template T> class, that does some simple matrix calculations. Now I defined a (normal) class, in which I wanted to use a couple of these CMatrix'es in the following way:
CMatrix<double> *a;

(in the definition)

and to use a new operator with the parameterisation on these pointers later.

The compiler gives loads of errors :

missing ';' before '<'
'CMatrix' missing storage class or type specifiers
syntax error '<'
unexpected tokens preceding ';'

To me this makes no sense. Is this kind of thing impossible? Can anybody please help me?

Henk

NMTop40
March 14th, 2002, 12:39 PM
Does your template header include the fully defined class? With templates, it is not enough to provide function prototypes - you have to provide their implementation too.



The best things come to those who rate

enkie
March 14th, 2002, 12:46 PM
Yes, the template works in other instances...

Henk

NMTop40
March 14th, 2002, 12:49 PM
did you include the header file in which it is declared - and use any namespace you needed to use ?


The best things come to those who rate

enkie
March 14th, 2002, 12:51 PM
I included the matrix.h file, I'm not sure about the namespaces; the template works in all other things I tried...

Henk

Paul McKenzie
March 14th, 2002, 03:04 PM
The sure check to see if you are correct that matrix.h is included is to put the following line in matrix.h

#pragma message("Matrix.h is included")



This can go anywhere within the matrix.h file. When you compile your .CPP file, do you see the message "Matrix.h is included" in your compiler output window? If not, this means that you are not including the header, even though you think you are.

Regards,

Paul McKenzie

enkie
March 15th, 2002, 04:37 AM
I've tried this, and indeed the header file is included after the definition of the class.... Have you any idea how to correct this?

Thank you very much! Henk

enkie
March 15th, 2002, 04:42 AM
Well, everything works now.... It appears to be a problem of the order in which I include the header files, taking the matrix.h to the end of the list solved the errors. I didn't expect this! Oh well, for me there's always a bit of magic involved.

Thank you all for responding! Henk