template error

Discussion in 'C++' started by Adam Coutee, Aug 19, 2003.

  1. Adam Coutee

    Adam Coutee Guest

    Hello,

    I am trying to compile some code that includes third party header files
    (part of a library). I keep getting an error on the templates they've
    defined. An example error follows:

    "/usr/local/SensAble/GHOST/v31/include/gstGenericMatrix.h", line 115:
    error(1424):
    constant "DIMM" is not used in declaring the parameter types of
    function template "gstGenericMatrix::mulPointMatrix"
    template <class PT1, class PT2, class MAT, int DIMM, int DIMN>

    The code excerpt that generates this error is:

    template <class PT1, class PT2, class MAT, int DIMM, int DIMN>
    inline void mulPointMatrix(PT1 & res,
    const PT2 & p,
    const MAT & m)
    {
    for (int i = 0; i < DIMN; ++i)
    {
    res = 0;
    for (int j = 0; j < DIMM; ++j)
    {
    res += p[j] * m[j];
    }
    }
    }

    Does anyone know what the problem is? As mentioned, this is a header file
    for a third-party library (that I don't have source code for). Apparently,
    they built their applications with MIPSpro 7.3. I am using MIPSpro 7.2.1 on
    an Octane running Irix 6.5.19f. Is this something that is allowed in MIPSpro
    7.3, but not MIPSpro 7.2.1?

    Thanks for any help,
    Adam
     
    Adam Coutee, Aug 19, 2003
    #1
    1. Advertising

  2. On Tue, 19 Aug 2003 12:53:18 -0400, "Adam Coutee" <> wrote:

    >I am trying to compile some code that includes third party header files
    >(part of a library). I keep getting an error on the templates they've
    >defined. An example error follows:
    >
    >"/usr/local/SensAble/GHOST/v31/include/gstGenericMatrix.h", line 115:
    >error(1424):
    > constant "DIMM" is not used in declaring the parameter types of
    > function template "gstGenericMatrix::mulPointMatrix"
    > template <class PT1, class PT2, class MAT, int DIMM, int DIMN>
    >
    >The code excerpt that generates this error is:
    >
    >template <class PT1, class PT2, class MAT, int DIMM, int DIMN>
    >inline void mulPointMatrix(PT1 & res,
    > const PT2 & p,
    > const MAT & m)
    >{
    > for (int i = 0; i < DIMN; ++i)
    > {
    > res = 0;
    > for (int j = 0; j < DIMM; ++j)
    > {
    > res += p[j] * m[j];
    > }
    > }
    >}
    >
    >Does anyone know what the problem is?


    That the compiler requires all template parameters to be used somehow
    in the function's signature (because the compiler says so).

    One solution could be to introduce dummy arguments, like so:


    inline void mulPointMatrix(
    PT1& res,
    PT2 const& p,
    MAT const& m,
    int dummy1 = DIMM,
    int dummy2 = DIMN
    )


    or perhaps


    inline void mulPointMatrix(
    PT1& res,
    PT2 const& p,
    MAT const& m,
    int dummy1[DIMM] = 0,
    int dummy2[DIMN] = 0
    )


    Another solution, to use a better compiler.

    A third solution, not incompatible with the second, to use a better
    library... ;-)
     
    Alf P. Steinbach, Aug 19, 2003
    #2
    1. Advertising

  3. Adam Coutee

    Ron Natalie Guest

    "Alf P. Steinbach" <> wrote in message news:...

    > inline void mulPointMatrix(
    > PT1& res,
    > PT2 const& p,
    > MAT const& m,
    > int dummy1 = DIMM,
    > int dummy2 = DIMN
    > )

    I don't think this one will work. If the compiler relies on the function signature
    to differentiate the template specializations, then it still fails.

    > inline void mulPointMatrix(
    > PT1& res,
    > PT2 const& p,
    > MAT const& m,
    > int dummy1[DIMM] = 0,
    > int dummy2[DIMN] = 0
    > )


    I don't think this will work either, the arrays are converted to int* to form the function
    type.
     
    Ron Natalie, Aug 19, 2003
    #3
  4. On Tue, 19 Aug 2003 13:23:58 -0400, "Ron Natalie" <> wrote:

    >
    >"Alf P. Steinbach" <> wrote in message news:...
    >
    >> inline void mulPointMatrix(
    >> PT1& res,
    >> PT2 const& p,
    >> MAT const& m,
    >> int dummy1 = DIMM,
    >> int dummy2 = DIMN
    >> )

    >I don't think this one will work. If the compiler relies on the function signature
    >to differentiate the template specializations, then it still fails.
    >
    >> inline void mulPointMatrix(
    >> PT1& res,
    >> PT2 const& p,
    >> MAT const& m,
    >> int dummy1[DIMM] = 0,
    >> int dummy2[DIMN] = 0
    >> )

    >
    >I don't think this will work either, the arrays are converted to int* to form the function
    >type.


    Well, what "used" means obviously depends on the (erronous) compiler.

    But how about


    template< int N >
    struct Dummy
    {
    Dummy( int ) {}
    };

    template <class PT1, class PT2, class MAT, int DIMM, int DIMN>
    inline void mulPointMatrix(
    PT1& res,
    PT2 const& p,
    MAT const& m,
    Dummy<DIMM> dummy1 = 0,
    Dummy<DIMN> dummy2 = 0
    )
    {
    }

    ?

    Of course, the best solution for the OP would be to use both a better
    compiler and a better library, if possible.
     
    Alf P. Steinbach, Aug 19, 2003
    #4
  5. Adam Coutee

    Ron Natalie Guest

    "Alf P. Steinbach" <> wrote in message news:...


    >
    > Well, what "used" means obviously depends on the (erronous) compiler.
    >
    > But how about
    >
    >
    > template< int N >
    > struct Dummy
    > {
    > Dummy( int ) {}
    > };
    >
    > template <class PT1, class PT2, class MAT, int DIMM, int DIMN>
    > inline void mulPointMatrix(
    > PT1& res,
    > PT2 const& p,
    > MAT const& m,
    > Dummy<DIMM> dummy1 = 0,
    > Dummy<DIMN> dummy2 = 0
    > )
    > {
    > }


    That one looks better.
    Another solution would be to wrap the function in a class that depends on the
    template args.
     
    Ron Natalie, Aug 19, 2003
    #5
  6. Adam Coutee

    Adam Coutee Guest


    >
    > Of course, the best solution for the OP would be to use both a better
    > compiler and a better library, if possible.
    >


    Thanks for all of the info guys...
    Sadly enough, I can't get a better library (what I have is what I get). :(

    However, it seems to me that you think a newer version of the compiler
    (MIPSpro) may do the trick. Is this the case?

    Thanks again,
    Adam
     
    Adam Coutee, Aug 19, 2003
    #6
  7. On Tue, 19 Aug 2003 13:36:16 -0400, "Ron Natalie" <> wrote:

    >
    >"Alf P. Steinbach" <> wrote in message news:...
    >
    >
    >>
    >> Well, what "used" means obviously depends on the (erronous) compiler.
    >>
    >> But how about
    >>
    >>
    >> template< int N >
    >> struct Dummy
    >> {
    >> Dummy( int ) {}
    >> };
    >>
    >> template <class PT1, class PT2, class MAT, int DIMM, int DIMN>
    >> inline void mulPointMatrix(
    >> PT1& res,
    >> PT2 const& p,
    >> MAT const& m,
    >> Dummy<DIMM> dummy1 = 0,
    >> Dummy<DIMN> dummy2 = 0
    >> )
    >> {
    >> }

    >
    >That one looks better.
    >Another solution would be to wrap the function in a class that depends on the
    >template args.


    If the library can be redesigned then _much_ better solutions exist. Keeping
    the "fixed size matrix type" idea the size should be deducible from the type.
    Even better, if possible allow mixture of fixed-size and dynamic-size with
    compile time checking where all necessary information is available (now that
    is, I think, a nice design problem -- is it possible to do in a clean way?).

    But the intent was to not require any changes to existing client code.
     
    Alf P. Steinbach, Aug 19, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Theis
    Replies:
    2
    Views:
    503
    Chris Theis
    Jul 24, 2003
  2. tom_usenet
    Replies:
    0
    Views:
    568
    tom_usenet
    Jul 24, 2003
  3. Replies:
    1
    Views:
    2,150
    Gianni Mariani
    Jun 8, 2007
  4. Peng Yu
    Replies:
    3
    Views:
    809
    Thomas J. Gritzan
    Oct 26, 2008
  5. nguillot
    Replies:
    5
    Views:
    562
Loading...

Share This Page