Type traits

A

Asif Zaidi

Hi:

I am following the doc http://boost.cowic.de/rc/pdf/type_traits.pdf
and trying to do the example from pg 4. I want to create my own
'is_pointer' trait. I have done this as shown in code below, and am
trying to test it as shown below.

When I don't have the 'debug0' & 'debug1' statements in my is_pointer
templates, I can compile. But when I do have them, I get compile
errors. What am I missing - and how can I test my code ?

I want to see if 'a' is a pointer.

Plz advise.

Thanks
Asif

====


#include <iostream>
#include <boost/type_traits.hpp>
using namespace boost;
using namespace std;



namespace my_namespace
{

template <typename T> struct is_pointer : public false_type
{ cout << "debug0" << endl; };
template <typename T> struct is_pointer<T*> : public true_type { cout
<< "debug1" << endl; };
}


int main ( )
{
my_namespace::is_pointer<int> a;

return 0;
}
 
R

red floyd

Hi:

I am following the dochttp://boost.cowic.de/rc/pdf/type_traits.pdf
and trying to do the example from pg 4. I want to create my own
'is_pointer' trait. I have done this as shown in code below, and am
trying to test it as shown below.

When I don't have the 'debug0' & 'debug1' statements in my is_pointer
templates, I can compile. But when I do have them, I get compile
errors. What am I missing - and how can I test my code ?

I want to see if 'a' is a pointer.

Plz advise.

Thanks
Asif

====

#include <iostream>
#include <boost/type_traits.hpp>
using namespace boost;
using namespace std;

namespace my_namespace
{

        template <typename T> struct is_pointer     : public false_type
{  cout << "debug0" << endl; };
        template <typename T> struct is_pointer<T*> : public true_type { cout
<< "debug1" << endl;  };

}

You can't have executable statements directly as part of a class.
They need
to be part of a member function.

Try:
template <typename T> struct is_pointer :
public false_type
{
is_pointer() { cout << "debug0" << endl; }
};
template <typename T> struct is_pointer<T*> :
public true_type
{
is_pointer() { cout<< "debug1" << endl; }
};
 
A

Asif Zaidi

Great.. thank you.
I don't know why I didn't see that !!

I will probably have more questions later on


Thanks

Asif
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top