微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

外部模板DLL和程序crypto ++

如何解决外部模板DLL和程序crypto ++

| 我已经将Crypto ++与VS2005和VS2010一起使用了一段时间。但是最近我需要将它直接用于和应用程序。当我将其编译为DLL时,相同的代码可以正常编译,而作为应用程序编译时,则不会编译。 这是产生误差的最小样本是这个(基于
cryptopp561\\algparam.h:301 CryptoPP::AlgorithmParameterstemplate
class Base 
{
protected:
    virtual void MoveInto(void *p) const = 0;
};

template<class T>
class Test: public Base
{
public:
    void MoveInto(void * buffer) const
    {
        Test<T> *x = new(buffer) Test<T>(*this);
    }
};

extern template class Test<bool>;
编译参数是相同的,唯一的区别是项目中的配置类型(\“ Application(.exe)\”生成错误,而\“ Dynamic Library(.dll)\”则不会)。 这是编译器错误
main.h(15): error C2061: Syntax error : identifier \'buffer\'
      main.h(14) : while compiling class template member function \'void Test<T>::MoveInto(void *) const\'
      with
      [
          T=bool
      ]
      main.h(20) : see reference to class template instantiation \'Test<T>\' being compiled
      with
      [
          T=bool
      ]
它似乎仅在有继承的情况下发生。在
class Test
声明中省略
: public Base
可使错误消失。 编辑: 问题出在标头中,该标头定义了用于ѭ5的调试版本,但未声明放置新版本。     

解决方法

        您是否
#include <new>
,它是声明新放置的头文件?     ,        有趣的是,外部模板会告诉编译器在某些时候不要实例化,因此第二个错误对我来说没有意义。您确定您的编译器支持extern模板吗?如果您执行相反的显式实例化,该怎么办:
template class Test<bool>;
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。