考虑以下课程:
class MyClass
{
int _id;
public:
decltype(_id) getId();
};
decltype(MyClass::_id) MyClass::getId()
{
return _id;
}
Run Code Online (Sandbox Code Playgroud)
它汇编很好.
但是,当我从中创建一个模板类时:
template <class T>
class MyClass
{
int _id;
public:
decltype(_id) getId();
};
template <class T>
decltype(MyClass<T>::_id) MyClass<T>::getId()
{
return _id;
}
Run Code Online (Sandbox Code Playgroud)
我明白了:
test.cpp:10:27: error: prototype for 'decltype (MyClass<T>::_id) MyClass<T>::getId()' does not match any in class 'MyClass<T>'
decltype(MyClass<T>::_id) MyClass<T>::getId()
^
test.cpp:6:19: error: candidate is: decltype (((MyClass<T>*)(void)0)->MyClass<T>::_id) MyClass<T>::getId()
decltype(_id) getId();
^
Run Code Online (Sandbox Code Playgroud)
这是为什么?
为什么不同的类型
decltype (MyClass<T>::_id) MyClass<T>::getId()decltype (((MyClass<T>*)(void)0)->MyClass<T>::_id)我可以通过在类中定义主体来修复它:
template <class T>
class MyClass …Run Code Online (Sandbox Code Playgroud) 在本教程中
有两种方法可以运行内核,另一种方法在评论中提到:
1.
cl::KernelFunctor simple_add(cl::Kernel(program,"simple_add"),queue,cl::NullRange,cl::NDRange(10),cl::NullRange);
simple_add(buffer_A,buffer_B,buffer_C);
Run Code Online (Sandbox Code Playgroud)
但是,我发现,KernelFunctor 已经消失了.
所以我尝试了另一种方式:
2.
cl::Kernel kernel_add=cl::Kernel(program,"simple_add");
kernel_add.setArg(0,buffer_A);
kernel_add.setArg(1,buffer_B);
kernel_add.setArg(2,buffer_C);
queue.enqueueNDRangeKernel(kernel_add,cl::NullRange,cl::NDRange(10),cl::NullRange);
queue.finish();
Run Code Online (Sandbox Code Playgroud)
它编译和运行成功.
但是,评论中有第3个选项:
3.
cl::make_kernel simple_add(cl::Kernel(program,"simple_add"));
cl::EnqueueArgs eargs(queue,cl::NullRange,cl::NDRange(10),cl::NullRange);
simple_add(eargs, buffer_A,buffer_B,buffer_C).wait();
Run Code Online (Sandbox Code Playgroud)
哪个不编译,我认为make_kernel需要模板参数.我是OpenCl的新手,并没有设法修复代码.
我的问题是:
1.我应该如何修改3.编译代码?
2.哪种方式更好,为什么?2.对阵3.?
我想知道这个(httptest)包是否可用于测试HTTP/2特定功能.
谁能指点我一些例子呢?
我知道工具h2i,但它是一个交互式工具.
我正在寻找可编程的东西.
编辑:
我真正想要的是一个工具,例如我可以启动服务器推送并在客户端测试它.
因此,使用此包,如何访问默认使用的基础HTTP/2内容?
编辑2:
在nghttp2源代码中找到一些示例:https:
//github.com/tatsuhiro-t/nghttp2/tree/master/integration-tests
编辑3: 对我来说,看起来net net/http2并不是任何人都可以直接使用的.我会试验这个.
在Qt中,它们都是有效的,并且行为相同:
emit someSignal(value);
Run Code Online (Sandbox Code Playgroud)
VS
emit(someSignal(value));
Run Code Online (Sandbox Code Playgroud)
有什么区别吗?
对不起,我无法粘贴特定代码.
我希望这个小样本足够了:
假设我有一个像这样的分配器:
template <class T>
class MyAllocator
{
// ... typedefs
MyAllocObject _allocObject;
public:
MyAllocator() {
// _allocObject = new ..
}
MyAllocator(const MyAllocator& alloc) {
_allocObject = alloc.getAllocObject();
}
template <class U>
MyAllocator(const MyAllocator<U>& alloc) {
_allocObject = alloc.getAllocObject();
}
MyAllocator(const MyAllocObject& allocObject) {
_allocObject = allocObject;
}
inline pointer allocate(size_type size) {
return _allocObject->alloc(size);
}
// other functions
};
Run Code Online (Sandbox Code Playgroud)
并使用如下:
MyAllocObject object;
MyAllocator<int> myAlloc(object);
std::list<int, MyAllocator<int> > list(myAlloc);
Run Code Online (Sandbox Code Playgroud)
我经历过,如果缺少默认构造函数,代码就不会编译,所以我添加了它.
但问题是,我依赖于那个论点,因为这就是我用于自定义内存分配的东西.
在这种情况下我该怎么办?
来自参考:
如果已知表达式始终为true,则is关键字会导致编译时警告.
我试图创建一个例子:
class MyClass
{
public void method(MyClass c)
{
if (c is MyClass)
{
//...
}
if (c is Object)
{
//...
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我没有得到任何警告.为什么?
有人能告诉我一个例子,我得到一个警告(因为表达式始终是真的)?
它适用于虚假.
我正在尝试获取io:format/1的输出结果.
我知道在io_lib,io_lib:format/2中有类似的功能,但输出不同.事实上,它根本没有做任何事情.如果我尝试绑定io:format,则ok是有界的,并且格式化的字符串被写出到控制台.
所以我的问题是,如何使用io_lib得到相同的输出:format/2?或者如何将格式化的字符串绑定到变量?
1> A = io:get_line('> ').
> "test".
"\"test\".\n"
2> io:format(A).
"test".
ok
3> B = io_lib:format(A, []).
"\"test\".\n"
4> B.
"\"test\".\n"
5> C = io:format(A).
"test".
ok
6> C.
ok
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用OpenCL的AMD实现编写Hello World应用程序. http://developer.amd.com/tools-and-sdks/heterogeneous-computing/amd-accelerated-parallel-processing-app-sdk/introductory-tutorial-to-opencl/
我设置的目录,LIB,等这里
以下编译:
#include "stdafx.h"
#include <CL/cl.h>
int _tmain(int argc, _TCHAR* argv[])
{
cl_platform_id test;
cl_uint num;
cl_uint ok = 1;
clGetPlatformIDs(ok, &test, &num);
return 0;
Run Code Online (Sandbox Code Playgroud)
}
然而,
#include "stdafx.h"
#include <utility>
#include <CL/cl.hpp>
int _tmain(int argc, _TCHAR* argv[])
{
cl::vector< cl::Platform > platformList;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
才不是.
我收到以下错误:
Error 1 error C2039: 'vector' : is not a member of 'cl' D:\Documents\Projects\Visual Studio\C++\cl_helloworld\cl_helloworld\cl_helloworld.cpp 12 1 cl_helloworld
Error 2 error C2065: 'vector' : undeclared identifier D:\Documents\Projects\Visual Studio\C++\cl_helloworld\cl_helloworld\cl_helloworld.cpp 12 …Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
#include <stdlib.h>
#include <iostream>
int main()
{
char* s = (char*)malloc(sizeof(char) * 3); //I allocate memory for 3 chars
s[0] = 'a';
s[1] = 'b';
s[2] = '\0';
s[3] = 'd'; //This shouldn't work
std::cout << s[3] << std::endl; //It prints out d, why?
free(s);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么我被允许写s [3]?
在Erlang中,\"是一个转义字符,意思是双引号.
我的问题是,"\"test\""和之间有什么区别""test""?我问的原因是因为,我正在尝试处理list_to_atom错误:
> list_to_atom("\"test\"").
'"test"'
> list_to_atom(""test"").
* 1: syntax error before: test
Run Code Online (Sandbox Code Playgroud) 请考虑以下示例:
List<String> myList = new List<string>();
myList.Add("Ford");
myList.Add("Porsche");
var filteredList = myList.Where(a => a.StartsWith("F"));
myList.Add("Ferrari");
foreach (string s in filteredList)
{
Console.WriteLine(s);
}
Run Code Online (Sandbox Code Playgroud)
输出是:
Ford
Ferrari
Run Code Online (Sandbox Code Playgroud)
当我创建筛选列表时,该列表仅包含:
Ford
Run Code Online (Sandbox Code Playgroud)
为什么修改原始列表会影响已过滤的列表?