小编Max*_*rai的帖子

指向功能的指针

我必须将函数传递给指针.为此我正在使用boost :: function.对于不同的签名,捕获指针的函数被重载.例如:

void Foo(boost::function<int ()>) { ... }
void Foo(boost::function<float ()>) { ... }
void Foo(boost::function<double ()>) { ... }
Run Code Online (Sandbox Code Playgroud)

现在我想在那里传递一些类方法指针:

class test
{
   public:
      float toCall() { };
};

class Wrapper
{
  Wrapper() {
    test obj;
    Foo(boost::bind(&test::toCall, this));
  }
};


error: no matching function for call to ‘Foo(boost::_bi::bind_t<float, boost::_mfi::mf0<float, test>, boost::_bi::list1<boost::_bi::value<Wrapper*> > >)’
    note: candidates are: Foo(boost::function<float()>&)
Run Code Online (Sandbox Code Playgroud)

c++ pointers boost-bind boost-function

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

提升链接错误

所以,我正在尝试使用boost.process库.我从这个位置下载了包,复制包含从boost子目录到/ usr/include/boost,写了一个简单的代码:

    namespace bp = ::boost::process;
    std::string execApp = "make";
    std::vector<std::string> args;
    args.push_back("-C ../build");

    bp::context ctx;
    ctx.stdout_behavior = bp::silence_stream();

    bp::child buildProcess = bp::launch(execApp, args, ctx);
Run Code Online (Sandbox Code Playgroud)

它编译但链接器失败:

CMakeFiles/DebugConsole.dir/Debug/DebugConsole.cpp.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost/system/error_code.hpp:208: undefined reference to `boost::system::get_system_category()'
/usr/include/boost/system/error_code.hpp:209: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::get_system_category()'
CMakeFiles/DebugConsole.dir/Debug/DebugConsole.cpp.o: In function `boost::process::detail::file_handle::posix_remap(int)':
/usr/include/boost/process/detail/file_handle.hpp:264: undefined reference to `boost::system::get_system_category()'
/usr/include/boost/process/detail/file_handle.hpp:269: undefined reference to `boost::system::get_system_category()'
CMakeFiles/DebugConsole.dir/Debug/DebugConsole.cpp.o: In function `boost::process::detail::file_handle::posix_dup(int, int)':
/usr/include/boost/process/detail/file_handle.hpp:295: undefined …
Run Code Online (Sandbox Code Playgroud)

c++ linker boost

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

派生类和智能指针

class Object { /* */ };
Run Code Online (Sandbox Code Playgroud)

和一些派生的:

class Derived1 : public Object { /* */ };
class Derived2 : public Object { /* */ };
Run Code Online (Sandbox Code Playgroud)

我有一个函数,它使派生对象和返回指针Object;

Object *make()
{
   return new Derived1();
}
Run Code Online (Sandbox Code Playgroud)

所以,这种方式我必须通过智能指针包装返回的对象,但要使用什么返回类型?

TYPE? make()
{
   return boost::shared_ptr<Derived1>(new Derived1());
}
Run Code Online (Sandbox Code Playgroud)

c++ boost pointers smart-pointers

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

运营速度

我正在编写游戏编码,在渲染代码中进行速度计算非常重要.

我怎样才能获得某些操作的速度?

例如,如何知道乘法是否比sqrt快?或者我必须进行测试并计算时间.

编程语言是c ++,谢谢.

c++ performance operation

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

从XMLHttpRequest解析XML

我正在使用QML和XMLHttpRequest来获取一些XML数据.

  var doc = new XMLHttpRequest();
  if (doc.readyState == XMLHttpRequest.DONE) {
        var root = doc.responseXML.documentElement;

        // Go through recenttracks children
        var recentTracks = root.childNodes[1];
        for (var i=0; i < recentTracks.childNodes.length; ++i)
        {
            var child = recentTracks.childNodes[i];
            for (var j=0; j < child.childNodes.length; ++j)
            {
                if (child.childNodes[j].nodeName == "name")
                {
                    console.log(child.childNodes[j].nodeValue); // [!]
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我正在解析这样的XML.

<track>
<artist mbid="293f35f8-3682-44bd-9471-13ca94fa9560">Tyler James</artist>
<name>Tried To Measure</name>
<streamable>0</streamable>
<album mbid="">It Took The Fire</album>
<url>http://www.last.fm/music/Tyler+James/_/Tried+To+Measure</url>
<image size="small">http://userserve-ak.last.fm/serve/34s/59408859.jpg</image>
</track>
Run Code Online (Sandbox Code Playgroud)

现在看看代码中的注释[!].在该行之前,我正在检查当前节点名称是否为"name"(查看XML).现在我想获得name …

xml parsing xmlhttprequest qml

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

来自互联网和Qt的XML文件

我想在Qt中解析一些XML文件,但该文件位于Web中的某个服务器上.当我使用QML时,我能够使用XMLHttpRequest在互联网上获取文件地址的类(我需要的东西).

我只有一个想法:使用网络请求并直接下载该xml.这个想法可能是qt中的XML解析器中有一个特殊的接口,它接受来自互联网的xml路径?

c++ xml qt parsing

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

如何抓住内容

我有这样的HTML节点:

<div id='parent'>
   <a href="#">test</a>
   Need this
</div>
Run Code Online (Sandbox Code Playgroud)

如果我有parent对象的句柄,如何获得'需要这个'文本?我尝试过类似的东西:$('#parent').text()但它也会返回'test'.


ps 没有关于编辑HTML的事情!我只是有这样的内容,我需要解析它.

html javascript jquery dom

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

STL算法与普通代码

我有一个对象矢量:

std::vector<Object> data;
Run Code Online (Sandbox Code Playgroud)

现在我需要调用Object::Foo()数据数组:

for (int i=0; i < data.size(); ++i) data[i].Foo(); // I think, the most slower
for (Object *it : data) it->Foo(); // And these are equal?
for (auto it=data.begin(); i!=data.end(); ++it) it->Foo();
Run Code Online (Sandbox Code Playgroud)

我知道这些方法,但现在我正在学习STL,我在for_each那里找到了:

for_each(data.begin(), data.end(), mem_fun(&Object::Foo));
Run Code Online (Sandbox Code Playgroud)

哪一个更好?换句话说,前两个示例更"基础",并且很容易理解普通开发人员的构造.

怎么样的STL算法的速度(for_eachmem_fun当前的情况下).我真的需要学习它吗?

c++ algorithm for-loop stl

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

cakephp 中的 requestAction

我已将 GeoIP 集成到我的 CakePHP 中。现在我必须从我的视图文件中调用它。我在我的控制器中做了这样的功能:

function getCountry($ip)
{
    $this->GeoIP->countryName($ip);
}
Run Code Online (Sandbox Code Playgroud)

GeoIP是一个包含的组件。

当我在全球视野中写下这样的内容时: $this->GeoIP->countryName('8.8.8.8')它运行良好,但是,据我记得,这对于 MCV 架构来说是错误的。所以正确的方法是调用requestAction我的控制器。

这里我有两个问题:我必须在位于视图文件中的 php 函数中执行此操作:

// MyView.php:
<?php
   function Foo()
   {
      $this->GeoIP->countryName(...);
   }
?>
Run Code Online (Sandbox Code Playgroud)

第一个错误是$this函数内部不可用,第二个错误是如何getCountry从我的组件调用并将需要的 ip 地址传递到$ip

我试过了:

echo $this->requestAction('Monitoring/getCountry/8.8.8.8');
Run Code Online (Sandbox Code Playgroud)

Monitoring是控制器名称。

但这没有返回任何错误。什么是正确的方法以及如何在函数中调用它?

php cakephp

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

错误:在令牌之前缺少二元运算符"("

在gcc升级后,由于错误,我的项目无法构建:

In file included from /usr/include/luabind/wrapper_base.hpp:31:0,
                 from /usr/include/luabind/back_reference.hpp:27,
                 from /usr/include/luabind/class.hpp:93,
                 from /usr/include/luabind/luabind.hpp:28,
                 from /home/ockonal/Workspace/themisto/engine/include/Scripting/ScriptManager.hpp:21,
                 from /home/ockonal/Workspace/themisto/engine/source/Core/Root.cpp:28:
/usr/include/luabind/detail/call_member.hpp:319:1: error: missing binary operator before token "("
In file included from /usr/include/luabind/back_reference.hpp:27:0,
                 from /usr/include/luabind/class.hpp:93,
                 from /usr/include/luabind/luabind.hpp:28,
                 from /home/ockonal/Workspace/themisto/engine/include/Scripting/ScriptManager.hpp:21,
                 from /home/ockonal/Workspace/themisto/engine/source/Core/Root.cpp:28:
/usr/include/luabind/wrapper_base.hpp:92:1: error: missing binary operator before token "("
In file included from /usr/include/luabind/function.hpp:10:0,
                 from /usr/include/luabind/class.hpp:94,
                 from /usr/include/luabind/luabind.hpp:28,
                 from /home/ockonal/Workspace/themisto/engine/include/Scripting/ScriptManager.hpp:21,
                 from /home/ockonal/Workspace/themisto/engine/source/Core/Root.cpp:28:
/usr/include/luabind/detail/call_function.hpp:326:1: error: missing binary operator before token "("
In file included from /usr/include/luabind/detail/constructor.hpp:12:0,
                 from /usr/include/luabind/class.hpp:96,
                 from /usr/include/luabind/luabind.hpp:28,
                 from /home/ockonal/Workspace/themisto/engine/include/Scripting/ScriptManager.hpp:21,
                 from /home/ockonal/Workspace/themisto/engine/source/Core/Root.cpp:28:
/usr/include/luabind/wrapper_base.hpp:92:1: …
Run Code Online (Sandbox Code Playgroud)

c++ gcc luabind

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