小编Hai*_*x64的帖子

用于本机C++的C++/CLI包装器,用作C#中的引用

标题解释.我有原生的C++ dll,我正在编写C++/CLI包装器,而这些包装器又将作为参考在C#中导入.

问题是在C#中我没有看到我在包装器中的类(从DLL导入).

我应该使用哪些关键字以及如何重新声明我的本机C++对象在C#中可见?

c# c++ dll c++-cli

32
推荐指数
1
解决办法
3万
查看次数

C++/CLI全局函数可访问性问题

当在C#中导入编译的DLL时,如何使C++/CLI函数可见?

我只需将它们的名字与public一起使用就可以用类来完成它,但它不是函数的情况,当我这样做时我会遇到语法错误.

我怎么能这样做?

谢谢!

c# dll c++-cli visual-studio-2010

4
推荐指数
1
解决办法
2050
查看次数

unique_ptr upcast 作为回报

我有这个函数应该生成不同的派生对象并作为一个返回unique_ptr<base>

class base {};  // contains pure functions.
class derived1 {}; // reifies that pure iface.
class derived2 {}; // reifies that pure iface.

unique_ptr<base> factory::load(int param)
  {
    switch (param)
      {
      case PARAM_MAIN:
        return new derived1();
        // return std::move(new derived1());

      case PARAM_2:
        return new derived2();

      case ...:
        return new derived...();

      }
  }
Run Code Online (Sandbox Code Playgroud)

即使使用 std::move,我也无法让这件事继续下去。(也使用了 dynamic_cast,但可能做错了)。

这是我得到的错误:(gcc (GCC) 4.8.1 20130725 (prerelease) on ArchLinux)

could not convert '(std::shared_ptr<base::model>((*(const std::shared_ptr<base::model>*)(& associatedModel))), (operator new(48ul), (<statement>, ((derived1*)<anonymous>))))' from 'derived1*' to 'std::unique_ptr<base>'
            associatedModel));
Run Code Online (Sandbox Code Playgroud)

我希望我已经清楚我想做什么。 …

polymorphism upcasting unique-ptr c++11

3
推荐指数
1
解决办法
7320
查看次数

C++ pthread成员函数

可能重复:
来自类的pthread函数

我有这个代码,由于这pthread_create行代码我无法编译:

void* gtk_functor::_threaded_run(void* win)
{
    Gtk::Window* w = static_cast<Gtk::Window*>(win);
    Gtk::Main::run(*w);
    delete w;
}

void gtk_functor::operator ()(Gtk::Window& win, bool threaded)
{
    if (threaded)
    {
        pthread_t t_num;
        pthread_create(&t_num, NULL, (void* (*)(void*))&gtk_functor::_threaded_run, static_cast<void*>(&win));
    }
    else
    {
        Gtk::Main::run(win);
    }
}
Run Code Online (Sandbox Code Playgroud)

这个gcc线:

g++ -o main 'pkg-config --cflags --libs sqlite3 gtkmm-3.0' -lpthread main.cpp

最后用这个输出编译:

code/ui.cpp: In member function 'void ui::gtk_functor::operator()(Gtk::Window&, bool)':
code/ui.cpp:45:65: warning: converting from 'void* (ui::gtk_functor::*)(void*)' to 'void* (*)(void*)' [-Wpmf-conversions]
Run Code Online (Sandbox Code Playgroud)

显然代码不能正常工作,我得到sementation faultif (threaded)提升.

我知道它与演员,但我不知道将成员函数传递给pthread_create的正确形式.有什么建议?

c++ g++ pthreads member-functions

1
推荐指数
2
解决办法
8416
查看次数

Variadic递归模板mem有趣的专业化

这是我想写的代码:

template <typename T1, typename ... tail>
  class record : public record<tail...>
{
  using baseT = record<tail...>;

  T1 elem;

public:
  record(T1 first, tail... rest)
    : elem(first), baseT(rest...)
  {}

  template <int index>
  inline constexpr T1& get()
  {
        // line 83:
    return baseT::get<index-1>();
  }
  // line 85:
  template <>
  inline constexpr T1& get<0>()
  {
    return elem;
  }
};
Run Code Online (Sandbox Code Playgroud)

和我得到的编译器输出:( GCC 4.8.2 with -std=c++11)

record.hpp:85:15: error: explicit specialization in non-namespace scope 'class base::record<T1, tail>'
 template <>
       ^
record.hpp:86:33: error: template-id 'get<0>' in …
Run Code Online (Sandbox Code Playgroud)

c++ specialization variadic-templates c++11

1
推荐指数
1
解决办法
182
查看次数

忽略元素编译的指令

我想编写一个名为 的指令ng-ignore来阻止 HTML 编译器处理元素及其子元素。

我一直在练习编写指令,但对此有点困惑。


我想要这样的东西:

angular.module("myMod", [])
.directive("ngIgnore", function()
{
    var dirDefObj = {
        // What should I write here to have compiler ignore this element?
    };
    return dirDefObj;
});
Run Code Online (Sandbox Code Playgroud)

像这样使用:

<div ng-ignore>
    This div must be ignored by Angular's compiler.
</div>
Run Code Online (Sandbox Code Playgroud)

需要帮助和指导来编写它。谢谢。

angularjs angularjs-directive

1
推荐指数
1
解决办法
2418
查看次数