Всем, спасибо за ваш интерес.
После того, как я поставил свой вопрос, я попытался использовать Python3.7.2 (32-битная версия) вместо python3.7.2 (64-битная версия), а затем на моем ПК (Windows 10, 64-битная версия) все прошло хорошо
Я предполагаю, что библиотека python win32com может работать с python3.7.2 (32-битная версия) в настоящее время.
Еще раз спасибо.
Рури Оби Киото / Иокогама, Япония
Когда вы специализируете шаблонный метод, вы должны делать это вне скобок класса:
template <typename X> struct Test {}; // to simulate type dependency
struct X // class declaration: only generic
{
template <typename T>
static void f( Test<T> );
};
// template definition:
template <typename T>
void X::f( Test<T> ) {
std::cout << "generic" << std::endl;
}
template <>
inline void X::f<void>( Test<void> ) {
std::cout << "specific" << std::endl;
}
int main()
{
Test<int> ti;
Test<void> tv;
X::f( ti ); // prints 'generic'
X::f( tv ); // prints 'specific'
}
Когда вы берете его за пределы класса, вы должны удалить ключевое слово static. Статическое ключевое слово вне класса имеет особое значение, отличное от того, что вы, вероятно, хотите.
template <typename X> struct Test {}; // to simulate type dependency
template <typename T>
void f( Test<T> ) {
std::cout << "generic" << std::endl;
}
template <>
void f<void>( Test<void> ) {
std::cout << "specific" << std::endl;
}
int main()
{
Test<int> ti;
Test<void> tv;
f( ti ); // prints 'generic'
f( tv ); // prints 'specific'
}
It's not directly an answer to your question but you can write this
template <typename T>
static T safeGuiCall(boost::function<T ()> _f)
{
if (_f.empty())
throw GuiException("Function pointer empty");
{
ThreadGuard g;
return _f();
}
}
It should work even if _f() return 'void'
Edit : In a more general case, I think we should prefer function overloading instead of specialization. Here is a good explanation for this : http://www.gotw.ca/publications/mill17.htm
Вы можете объявить явную специализацию так же, как и функцию-член вне ее класса:
class A
{
public:
template <typename T>
static void foo () {}
};
template <>
void A::foo<void> ()
{
}
Your problem appears to be with boost::function - the following specialisations work:
template <typename T>
T safeGuiCall()
{
return T();
}
template <>
void safeGuiCall<void>()
{
}
int main() {
int x = safeGuiCall<int>(); // ok
//int z = safeGuiCall<void>(); // this should & does fail
safeGuiCall<void>(); // ok
}