Find the answer to your Linux question:
Results 1 to 2 of 2
Does anyone know why I get the following error when I compile this c++ program? g++ -g -Wall -c test.cpp -o test.o test.cpp: In member function ‘bool ComplexCompare<T>::operator()(const std::complex<_Tp>&, const ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2006
    Posts
    15

    Problem with a templated class


    Does anyone know why I get the following error when I compile this c++ program?

    g++ -g -Wall -c test.cpp -o test.o
    test.cpp: In member function ‘bool ComplexCompare<T>::operator()(const std::complex<_Tp>&, const std::complex<_Tp>&)’:
    test.cpp:19: error: `.' cannot appear in a constant-expression
    test.cpp:19: error: missing ‘>’ to terminate the template argument list

    Here is the program:

    #include <complex>

    #include "test.h"

    using namespace std;


    template<typename T>
    ComplexCompare<T>::ComplexCompare(int cflag=1)
    :m_cflag(cflag)
    {}


    template<typename T>
    bool ComplexCompare<T>::operator()( const complex<T>& c1, const complex<T>& c2)
    {
    if( c1.imag < c2.imag ) //line 19
    return true;
    else
    return false;
    }

  2. #2
    Just Joined!
    Join Date
    Feb 2006
    Posts
    15
    Changing line 19 to

    if( c1.imag<T> < c2.imag<T> )

    fixed the compile error.

    Its stange that the Visual Studio did not flag this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •