 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Howard Gardner Guest
|
Posted: Sat Jul 15, 2006 1:57 am Post subject: error: no instance of function template "test_c" matches the |
|
|
/*
Sections a and b compile fine. There is a broken line in
section c (two broken versions of the broken line
are there, with diagnostics)
Other than the name changes, the the three sections differ
only in the default value of the size_t argument to the
temp_ struct.
The size_t argument to temp_a:
does not depend on the type argument
does use faux_ptr
The size_t argument to temp_b:
does depend on the type argument
does not use faux_ptr.
The size_t argument to temp_c:
depends ont the type argument
uses faux_ptr.
It's the form in section c that I'm trying to use,
naturally. I'm utterly baffled. If someone can see why this
doesn't work, please tell me!
*/
#include <ostream>
#include <cstddef>
// Promises to return a ptr to x
template< typename x >
x * faux_ptr();
// section a -----------------------------------------------
template< typename x, size_t = sizeof( faux_ptr< int >() ) >
struct temp_a{};
template< typename xSubject >
bool test_a( temp_a< xSubject > );
temp_a< int > instance_a;
size_t size_a = sizeof( test_a( instance_a ) );
// section b -----------------------------------------------
template< typename x, size_t = sizeof( x ) >
struct temp_b{};
template< typename xSubject >
bool test_b( temp_b< xSubject > );
temp_b< int > instance_b;
size_t size_b = sizeof( test_b( instance_b ) );
// section c -----------------------------------------------
template< typename x, size_t = sizeof( faux_ptr< x >() ) >
struct temp_c{};
template< typename xSubject >
bool test_c( temp_c< xSubject > );
temp_c< int > instance_c;
//size_t size_c = sizeof( test_c( instance_c ) );
/*
error: no instance of function template "test_c"
matches the argument list
argument types are: (temp_c<int, 4U>)
*/
//size_t size_c = sizeof( test_c< int >( instance_c ) );
/*
error: no instance of function template "test_c"
matches the argument list
argument types are: (temp_c<int, 4U>)
*/
int main()
{
using namespace std;
cout << typeid( instance_c ).name() << endl;
// outputs "temp_c<int, 4U>"
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Howard Gardner Guest
|
Posted: Tue Jul 18, 2006 7:39 am Post subject: Re: error: no instance of function template "test_c" matches |
|
|
Greg Herlihy wrote:
| Quote: |
template< typename x, size_t = sizeof( faux_ptr< x >() )
struct temp_c{};
Note that there are two parameterized type arguments for the temp_c
class template.
|
There aren't! x is a type parameter, but size_t is a non-type parameter.
I've got cleaner code to look at now. The forms of tpt that I've
commented out work fine. The one that I've left in doesn't.
I still don't know if it's legal code. In any event, it won't work on
Comeu, or gcc. It will work on VC++ 2005.
#include <ostream>
#include <cstddef>
template< typename x >
x * faux_ptr();
//template< typename x, size_t = sizeof( int * ) >
// struct tpt{};
//template< typename x, size_t = sizeof( faux_ptr< int >() ) >
// struct tpt{};
//struct has{ int memvar; };
//template< typename x, size_t = sizeof( faux_ptr< has >()->memvar ) >
// struct tpt{};
template< typename x, size_t = sizeof( faux_ptr< x >() ) >
struct tpt{};
template< typename x >
bool fnc( tpt< x > );
tpt< int > inst;
size_t size = sizeof( fnc( inst ) );
int main()
{
using namespace std;
cout << size << endl;
}
This code is the next step in the chain. It doesn't work right on Comeau
or VC++, noone has told me if it works on gcc.
I think it fails on Comeau for the same reason that the code above
fails. I don't know why it fails on VC++.
#include <ostream>
#include <cstddef>
struct has{ int memvar; };
template< typename x >
x * faux_ptr();
template< typename x, size_t = sizeof( faux_ptr< x >()->memvar ) >
struct tpt{};
typedef char no;
struct yes{ no val[2]; };
template< typename x >
no fnc( ... );
template< typename x >
yes fnc( tpt< x > * );
int main()
{
using namespace std;
cout << sizeof( fnc< has >( 0 ) ) << endl;
}
On my compiler, sizeof( no ) is 1, and sizeof( yes ) is 2.
The program selects the "no" version of fnc and prints:
1
I think that it should select the "yes" version of fnc and print:
2
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|