我从gcc收到一个奇怪的错误,无法弄清楚原因.我制作了以下示例代码,以使问题更加清晰.基本上,有一个类定义,我为其复制构造函数和复制赋值运算符私有,以防止意外调用它们.
#include <vector>
#include <cstdio>
using std::vector;
class branch
{
public:
int th;
private:
branch( const branch& other );
const branch& operator=( const branch& other );
public:
branch() : th(0) {}
branch( branch&& other )
{
printf( "called! other.th=%d\n", other.th );
}
const branch& operator=( branch&& other )
{
printf( "called! other.th=%d\n", other.th );
return (*this);
}
};
int main()
{
vector<branch> v;
branch a;
v.push_back( std::move(a) );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我希望这段代码能够编译,但是gcc失败了.实际上gcc抱怨"branch :: branch(const branch&)是私有的",据我所知,不应该调用它.
赋值运算符可以工作,因为如果我用main替换main()的主体
branch a;
branch b; …Run Code Online (Sandbox Code Playgroud) 我是一个javascript/web应用程序新手,并尝试使用hunchentoot和backbone.js实现我的第一个Web应用程序.我正在尝试的第一件事是理解model.fetch()和model.save()是如何工作的.
在我看来,model.fetch()会触发"GET"请求,而model.save()会触发"POST"请求.因此,我在hunchentoot中编写了一个easy-handler,如下所示:
(hunchentoot:define-easy-handler (dataset-handler :uri "/dataset") ()
(setf (hunchentoot:content-type*) "text/html")
;; get the request type, canbe :get or :post
(let ((request-type (hunchentoot:request-method hunchentoot:*request*)))
(cond ((eq request-type :get)
(dataset-update)
;; return the json boject constructed by jsown
(jsown:to-json (list :obj
(cons "length" *dataset-size*)
(cons "folder" *dataset-folder*)
(cons "list" *dataset-list*))))
((eq request-type :post)
;; have no idea on what to do here
....))))
Run Code Online (Sandbox Code Playgroud)
这旨在处理对应url为"/ dataset"的模型的获取/保存.获取工作正常,但我真的被save()搞糊涂了.我看到easy-handler触发并处理了"post"请求,但是请求似乎只有一个有意义的头,我找不到请求中隐藏的实际json对象.所以我的问题是
我在hunchentoot中尝试了"post-parameters"函数,它返回nil,并没有看到很多人通过googling使用hunchentoot + backbone.js.如果您可以引导我阅读一些有助于理解backbone.js save()工作原理的文章/博客文章,也会很有帮助.
非常感谢您的耐心等待!