我一直在阅读C++中基于概念的继承.我为所有人附上了一个代码示例.我基本上问这是否正确实现了这个概念?我是新手,所以我只是放下我的想法.欢迎任何评论/批评.
#include "stdafx.h"
#include <memory>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
struct Point{
int x;
int y;
};
class graphics_surface{
class drawable_concept{
public:
virtual void draw(Point const& coordinate) {};
virtual ~drawable_concept() {};
};
template<class T>
class drawable_model : public drawable_concept{
public:
drawable_model(T& item) : item_(item){}
void draw(Point const& coordinate){
item_.draw(coordinate);
}
~drawable_model(){}
private:
T item_;
};
public:
template<class T>
void push_back(T& drawable){
v_.push_back(shared_ptr<drawable_concept>( new drawable_model<T>(drawable)));
}
void draw(Point const& coordinate) {
for_each(v_.begin(), v_.end(), [&](shared_ptr<drawable_concept>& concept){
concept->draw(coordinate);
}); …
Run Code Online (Sandbox Code Playgroud) 这个设计的术语是什么?
object.method1().method2().method3()
Run Code Online (Sandbox Code Playgroud)
..当所有方法都返回*这个?
我不久前找到了这个术语,但同时失去了它.我不知道如何在谷歌搜索这个:)如果有人能想到一个更好的标题的问题,随时改变它.
谢谢
更新-Gishu:阅读完之后,我觉得你的问题是误导的wrt代码片段..(随意回滚)
方法链接
object.method1().method2().method3()
Run Code Online (Sandbox Code Playgroud)
流畅的界面
private void makeFluent(Customer customer) {
customer.newOrder()
.with(6, "TAL")
.with(5, "HPK").skippable()
.with(3, "LGV")
.priorityRush();
}
Run Code Online (Sandbox Code Playgroud) 我目前正在我的大学注册一个Web应用程序课程,我们正在学习cgi脚本.我很难学习如何实现我的CGI脚本.当我点击我的链接时会弹出一个窗口,要求我下载helloworld.cgi文件而不是重定向.
HTML:
<html>
<body>
<a href="/user/local/apache2/cgi-bin/helloworld.cgi">click me</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
C++:
#include <iostream>
using namespace std;
int main(){
cout << "Content-type: text/html" << endl;
cout << "<html>" << endl;
cout << " <body>" << endl;
cout << " Hello World!" << endl;
cout << " </body>" << endl;
cout << "</html>" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
CGI脚本存储在 /user/local/apache2/cgi-bin/helloworld.cgi
我收到此编译错误:
fatal error: can’t create precompiled header f: Text file busy
compilation terminated.
Run Code Online (Sandbox Code Playgroud)
这是一个非常神秘的,因为我偶尔会得到它...
我哪里出错了?
std::vector<int> interpret(const std::string &src, const std::vector<int> &input = {});
Run Code Online (Sandbox Code Playgroud)
除了将引用输入设置为{}之外,我理解签名的所有内容.那是什么意思?
我想为我正在增强的程序调试TCP/IP交互.我没有root访问权限(所以没有tcpdump等),但应用程序在我自己的id下运行.我可以使用例如strace拦截系统调用,但有没有值得推荐的替代方案?如果是这样,为什么 - 他们提供什么?命令行首选(我的电脑上没有安装X服务器:-()),但对GUI也很好奇.
理想情况下,它会说:
app listening on port <portA> app listening on port <portB> client connection #1 accepted on listening port <portA> to local port <portC> from remote <hostX:portXA> app sent #1 <number> bytes "<data dump...>" app received from client #1 <number> bytes "<data dump...>" client #1 closed connection
会自己划伤一个,但是太多的车轮要重新发明......
提前致谢.
更新:paulrubel和ypnos都提出了非常有用的建议......(希望我能接受这两个答案,因为它们是独特的,同样好的).执行Paul建议的LD_PRELOAD拦截的代码如下:
// TCP comms trace library
// as per http://www.jayconrod.com/cgi/view_post.py?23
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <dlfcn.h>
typedef ssize_t (*Recv)(int s, void* buf, size_t …
Run Code Online (Sandbox Code Playgroud) const char *cval = "nothing"; // This is right.
int *ival = {1, 2, 3, 4}; // This is wrong.
Run Code Online (Sandbox Code Playgroud)
为什么第一个是对的,但第二个是错的?
在采访中被问到.
A* a=new A();
A b; A *c=&b;
1和2有什么区别?
我在第二个语句中说过,对象是在堆栈和堆栈中创建的.我的朋友说对象总是在堆上创建的.
什么是正确的答案?
我遇到了一个decltype()
带有两个参数作为模板函数的返回值类型:
template<class C, class F>
auto test(C c, F f) -> decltype((void)(c.*f)(), void()) { }
Run Code Online (Sandbox Code Playgroud)
有人知道第二个参数是什么void()
吗?非常感谢你.
对于班级中的枚举......
不正确:
class MyClass{
public:
enum kHTTPMethods {GET,PUT,POST}
};
void MyClass::Func(){
kHTTPMethods method = kHTTPMethod.GET;
}
Run Code Online (Sandbox Code Playgroud)
1)我是否正确地说这不起作用,因为.
运算符只能用于类的对象(实例)?
正确:
void MyClass::Func(){
kHTTPMethods method = GET;
}
Run Code Online (Sandbox Code Playgroud)
2)我是否正确地说这是正确的,因为类的所有元素在类中变为全局范围?