"unable to match function definition to an existing declaration"

M

Maett

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
 
M

Mike Wahler

Maett said:
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
 
B

benben

Maett said:
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
 
M

Maett

Mike Wahler:
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.
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.

Maett
 
J

John Carson

Maett said:
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;
}
 
M

Maett

John said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top