template partially specialization for different namespaces

P

Peng Yu

Hi,

I have the following code (some part is not working). I would like A
behave differently depending on whether the template argument is from
the namespace space2 or not. Is it possible to do it?

Thanks,
Peng

#include <iostream>

namespace space2 {
class B { };
}

namespace space1 {

template <typename T>
struct A {
void doit() {
std::cout << "A<T>" << std::endl;
}
};

// I want this match any class from namespace space2
template <typename T>
struct A<typename space2::T> {
void doit() {
std::cout << "namespace space2" << std::endl;
}
};

}

int main() {
space1::A<double>().doit();
space1::A<space2::B>().doit();
}
 

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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top