"unable to match function definition to an existing declaration"

Discussion in 'C++' started by Maett, Sep 10, 2005.

  1. Maett

    Maett Guest

    Hi.

    When I try to compile this piece of Code with VC.NET 2003

    // code start
    #include <vector>

    template< class T > struct Marker
    {
    public:
    Marker() : err( 0 ) {}
    unsigned long err;
    };

    template< class T > struct MarkerTable
    {
    public:
    typedef std::vector< Marker<T> > TableType;
    TableType data;
    typename TableType::iterator FindErr( unsigned long ); // line 15
    };

    template< class T >
    typename MarkerTable<T>::TableType::iterator
    MarkerTable<T>::FindErr( unsigned long n )
    {
    typename TableType::iterator iter
    = lower_bound( data.begin(), data.end(), Marker<T>( 0, n ) );
    if( ( data.end() != iter ) && ( (*iter).err != n ) ) {
    iter = data.end();
    }
    return iter;
    } // line 28
    // code end


    I get the error
    line 28 : error C2244: 'MarkerTable<T>::FindErr' : unable to match function
    definition to an existing declaration
    line 15 : see declaration of 'MarkerTable<T>::FindErr'
    definition
    'std::vector<T,T2>::iterator MarkerTable<T>::FindErr(unsigned long)'
    existing declarations
    'vector<Marker<T>>::iterator MarkerTable<T>::FindErr(unsigned long)'

    Comeau compiles with no error.
    Can you tell me what I'm doing wrong ?

    Maett
    Maett, Sep 10, 2005
    #1
    1. Advertising

  2. Maett

    Mike Wahler Guest

    "Maett" <> wrote in message news:eek:pswv68avtmmfhfz@max...
    > Hi.
    >
    > When I try to compile this piece of Code with VC.NET 2003
    >
    > // code start
    > #include <vector>
    >
    > template< class T > struct Marker
    > {
    > public:
    > Marker() : err( 0 ) {}
    > unsigned long err;
    > };
    >
    > template< class T > struct MarkerTable
    > {
    > public:
    > typedef std::vector< Marker<T> > TableType;
    > TableType data;
    > typename TableType::iterator FindErr( unsigned long ); // line 15
    > };
    >
    > template< class T >
    > typename MarkerTable<T>::TableType::iterator
    > MarkerTable<T>::FindErr( unsigned long n )
    > {
    > typename TableType::iterator iter
    > = lower_bound( data.begin(), data.end(), Marker<T>( 0, n ) );
    > if( ( data.end() != iter ) && ( (*iter).err != n ) ) {
    > iter = data.end();
    > }
    > return iter;
    > } // line 28
    > // code end


    Your code compiles OK for me with VC++ v6.0(SP6).

    >
    >
    > I get the error
    > line 28 : error C2244: 'MarkerTable<T>::FindErr' : unable to match
    > function
    > definition to an existing declaration
    > line 15 : see declaration of 'MarkerTable<T>::FindErr'
    > definition
    > 'std::vector<T,T2>::iterator MarkerTable<T>::FindErr(unsigned
    > long)'


    T2? I don't see that anywhere in your posted code.
    Have you made a typo somewhere and the above isn't the real code? :)


    > existing declarations
    > 'vector<Marker<T>>::iterator MarkerTable<T>::FindErr(unsigned
    > long)'
    >
    > Comeau compiles with no error.
    > Can you tell me what I'm doing wrong ?


    -Mike
    Mike Wahler, Sep 10, 2005
    #2
    1. Advertising

  3. Maett

    benben Guest

    "Maett" <> wrote in message news:eek:pswv68avtmmfhfz@max...
    > Hi.
    >
    > When I try to compile this piece of Code with VC.NET 2003
    >
    > // code start
    > #include <vector>
    >
    > template< class T > struct Marker
    > {
    > public:
    > Marker() : err( 0 ) {}
    > unsigned long err;
    > };
    >
    > template< class T > struct MarkerTable
    > {
    > public:
    > typedef std::vector< Marker<T> > TableType;
    > TableType data;
    > typename TableType::iterator FindErr( unsigned long ); // line 15
    > };
    >
    > template< class T >
    > typename MarkerTable<T>::TableType::iterator
    > MarkerTable<T>::FindErr( unsigned long n )
    > {
    > typename TableType::iterator iter
    > = lower_bound( data.begin(), data.end(), Marker<T>( 0, n ) );
    > if( ( data.end() != iter ) && ( (*iter).err != n ) ) {
    > iter = data.end();
    > }
    > return iter;
    > } // line 28
    > // code end
    >
    >
    > I get the error
    > line 28 : error C2244: 'MarkerTable<T>::FindErr' : unable to match
    > function
    > definition to an existing declaration
    > line 15 : see declaration of 'MarkerTable<T>::FindErr'
    > definition
    > 'std::vector<T,T2>::iterator MarkerTable<T>::FindErr(unsigned
    > long)'
    > existing declarations
    > 'vector<Marker<T>>::iterator MarkerTable<T>::FindErr(unsigned
    > long)'
    >
    > Comeau compiles with no error.
    > Can you tell me what I'm doing wrong ?
    >
    > Maett


    Looks like a compiler bug. VC++ 2005 Beta 2 compiles the code just fine.

    Ben
    benben, Sep 10, 2005
    #3
  4. Maett

    Maett Guest

    Mike Wahler:

    >
    > "Maett" <> wrote in message news:eek:pswv68avtmmfhfz@max...
    >> Hi.
    >>
    >> When I try to compile this piece of Code with VC.NET 2003
    >>
    >> // code start
    >> #include <vector>
    >>
    >> template< class T > struct Marker
    >> {
    >> public:
    >> Marker() : err( 0 ) {}
    >> unsigned long err;
    >> };
    >>
    >> template< class T > struct MarkerTable
    >> {
    >> public:
    >> typedef std::vector< Marker<T> > TableType;
    >> TableType data;
    >> typename TableType::iterator FindErr( unsigned long ); // line 15
    >> };
    >>
    >> template< class T >
    >> typename MarkerTable<T>::TableType::iterator
    >> MarkerTable<T>::FindErr( unsigned long n )
    >> {
    >> typename TableType::iterator iter
    >> = lower_bound( data.begin(), data.end(), Marker<T>( 0, n ) );
    >> if( ( data.end() != iter ) && ( (*iter).err != n ) ) {
    >> iter = data.end();
    >> }
    >> return iter;
    >> } // line 28
    >> // code end

    >
    > Your code compiles OK for me with VC++ v6.0(SP6).


    For me the code also compiled ok with VC++ 6.0 (SP5);
    I'm migrating to VC++.NET 2003.

    >
    >>
    >>
    >> I get the error
    >> line 28 : error C2244: 'MarkerTable<T>::FindErr' : unable to match
    >> function
    >> definition to an existing declaration
    >> line 15 : see declaration of 'MarkerTable<T>::FindErr'
    >> definition
    >> 'std::vector<T,T2>::iterator MarkerTable<T>::FindErr(unsigned
    >> long)'

    >
    > T2? I don't see that anywhere in your posted code.
    > Have you made a typo somewhere and the above isn't the real code? :)


    Unfortunately it really *is* what VC says.
    I don't use T2; no idea where the compiler takes it from.

    >
    >
    >> existing declarations
    >> 'vector<Marker<T>>::iterator MarkerTable<T>::FindErr(unsigned
    >> long)'
    >>
    >> Comeau compiles with no error.
    >> Can you tell me what I'm doing wrong ?

    >
    > -Mike


    Maett
    Maett, Sep 10, 2005
    #4
  5. Maett

    John Carson Guest

    "Maett" <> wrote in message news:eek:pswv68avtmmfhfz@max
    > Hi.
    >
    > When I try to compile this piece of Code with VC.NET 2003
    >
    > // code start
    > #include <vector>
    >
    > template< class T > struct Marker
    > {
    > public:
    > Marker() : err( 0 ) {}
    > unsigned long err;
    > };
    >
    > template< class T > struct MarkerTable
    > {
    > public:
    > typedef std::vector< Marker<T> > TableType;
    > TableType data;
    > typename TableType::iterator FindErr( unsigned long ); // line 15
    > };
    >
    > template< class T >
    > typename MarkerTable<T>::TableType::iterator
    > MarkerTable<T>::FindErr( unsigned long n )
    > {
    > typename TableType::iterator iter
    > = lower_bound( data.begin(), data.end(), Marker<T>( 0, n ) );
    > if( ( data.end() != iter ) && ( (*iter).err != n ) ) {
    > iter = data.end();
    > }
    > return iter;
    > } // line 28
    > // code end
    >
    >
    > I get the error
    > line 28 : error C2244: 'MarkerTable<T>::FindErr' : unable to match
    > function definition to an existing declaration
    > line 15 : see declaration of 'MarkerTable<T>::FindErr'
    > definition
    > 'std::vector<T,T2>::iterator MarkerTable<T>::FindErr(unsigned
    > long)' existing declarations
    > 'vector<Marker<T>>::iterator MarkerTable<T>::FindErr(unsigned
    > long)'
    > Comeau compiles with no error.
    > Can you tell me what I'm doing wrong ?
    >
    > Maett


    Apparently it is a VC++2003 bug. You can work around it by not using the
    typedef from MarkerTable when defining FindErr, i.e., make it:

    template< class T >
    typename std::vector< Marker<T> >::iterator
    MarkerTable<T>::FindErr( unsigned long n )
    {
    typename TableType::iterator iter
    = lower_bound( data.begin(), data.end(), Marker<T>( 0, n ) );
    if( ( data.end() != iter ) && ( (*iter).err != n ) ) {
    iter = data.end();
    }
    return iter;
    }

    --
    John Carson
    John Carson, Sep 11, 2005
    #5
  6. Maett

    Maett Guest

    John Carson wrote:

    >
    > Apparently it is a VC++2003 bug. You can work around it by not using the
    > typedef from MarkerTable when defining FindErr, i.e., make it:
    >
    > template< class T >
    > typename std::vector< Marker<T> >::iterator
    > MarkerTable<T>::FindErr( unsigned long n )
    > {
    > typename TableType::iterator iter
    > = lower_bound( data.begin(), data.end(), Marker<T>( 0, n ) );
    > if( ( data.end() != iter ) && ( (*iter).err != n ) ) {
    > iter = data.end();
    > }
    > return iter;
    > }
    >


    Great, this works.
    Thanks a lot !

    Maett
    Maett, Sep 11, 2005
    #6
    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.

Share This Page