 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ralph Zhang Guest
|
Posted: Wed Dec 22, 2004 8:51 am Post subject: typetraits fail on pointer to member function? |
|
|
Hi,
I am reading Modern C++ Design and it mentions typetraits of pointer to
member function, so I write the following program to test that:
-------------------------------------------------------------------------------
#include <iostream>
template <typename T>
class TypeTraits
{
private:
template <class U> struct PtoMTraits
{
enum {result = false};
};
template <class U, class V> struct PtoMTraits<U V::*>
{
enum {result = true};
};
public:
static const bool isPtoM = PtoMTraits<T>::result;
};
struct Empty
{
int MemFun(int){return 0;}
};
int main()
{
typedef int(Empty::*PtoMType)(int);
PtoMType pTomf = &Empty::MemFun;
bool isPtoM = TypeTraits<PtoMType>::isPtoM;
std::cout << "is a pointer to member function: " << isPtoM <<
std::endl;
}
-------------------------------------------------------------------------------
It compiles both on VC7.1 and g++ 3.3.3(cygwin), but the VC7.1
executable gives:
is a pointer to member function: 1
while the g++ executable gives
is a pointer to member function: 0
And on BCB5.5 it doesn't compile at all.
What's wrong with them? As 1 is my intentioned result, is that a bug of
g++?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Sharad Kala Guest
|
Posted: Thu Dec 23, 2004 11:49 am Post subject: Re: typetraits fail on pointer to member function? |
|
|
"Ralph Zhang" <ralph623 (AT) 126 (DOT) com> wrote in message
| Quote: | Hi,
I am reading Modern C++ Design and it mentions typetraits of pointer to
member function, so I write the following program to test that:
[snip]
--------------------------------------------------------------------------
-----
It compiles both on VC7.1 and g++ 3.3.3(cygwin), but the VC7.1
executable gives:
is a pointer to member function: 1
while the g++ executable gives
is a pointer to member function: 0
And on BCB5.5 it doesn't compile at all.
What's wrong with them? As 1 is my intentioned result, is that a bug of
g++?
|
Seems like a gcc bug to me. IMO VC++ is getting it correct i.e. it should
print 1. btw, Comeau online also agrees with VC++ (try to give array size as
TypeTraits<PtoMType>::isPtoM).
Sharad
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
L.Suresh Guest
|
Posted: Thu Dec 23, 2004 5:09 pm Post subject: Re: typetraits fail on pointer to member function? |
|
|
This template specialization expectes a pointer to a member, not a
member function.
template <class U, class V> struct PtoMTraits<U V::*>
{
enum {result = true};
};
This will work...
struct Empty
{
int mem;
};
int main() {
typedef int (Empty::*PtoMType);
.....
}
--lsu
[ 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
|
|