首页 > 解决方案 > 使用本机事件的 C++ 内部编译器错误

问题描述

__event T e(args);

在第 9 行,VS 在“e”下给了我绿色的波浪线,并带有警告:“e”的函数定义未找到。

在编译/构建时,它会抛出编译器中发生的 C1001 内部错误(再次是第 9 行)。

我尝试重命名变量,尝试删除模板并仅使用普通类型,尝试将其公开。

如果有人可以提供帮助,将不胜感激,谢谢。(整个代码可能不是必需的,只是为了说明我要做什么)

#include <cstdarg>
#include <functional>
#include <iostream>
template <typename T, typename ... args>
[event_source(native)]
class Action {

    private:
        __event T e(args);

    public:
        ~Action() {
            __unhook(this);
        };

        void operator +=(std::function<T(args...)> f) {
            __hook(e, this, &f);
        }

        void operator -=(std::function<T(args...)> f) {
            __unhook(e, this, &f);
        }

        void operator()(args...) {
            __raise e(args);
        }   
};


void print(const char* s) {
    std::cout << s << std::endl;
}
int main() {

    Action<void, const char*> printAction;

    printAction += print;
    printAction("Print a string.");
    printAction -= print;
}

标签: visual-studioeventsvisual-c++compiler-errors

解决方案


推荐阅读