我似乎遇到了在Hibernate中映射List的问题.在我们的项目中有一类Card
用含有类Answer
与Answer
含有List<String>
.
是否可以List<String>
通过Hibernate使用注释进行映射?我的意思是,因为它没有@Entity
注释?
问候
在Stack Overflow上阅读关于C++迭代器和性能的各种问题**,我开始想知道for(auto& elem : container)
编译器是否"扩展"到最佳版本?(有点像auto
,编译器会立即推断出正确的类型,因此永远不会更慢,有时更快).
**例如,如果你写,这是否重要
for(iterator it = container.begin(), eit = container.end(); it != eit; ++it)
Run Code Online (Sandbox Code Playgroud)
要么
for(iterator it = container.begin(); it != container.end(); ++it)
Run Code Online (Sandbox Code Playgroud)
对于无效的容器?
我这样创建了我的lambda:
int i = 0;
auto gen_lam = [=]() mutable -> int {return ++i;};
Run Code Online (Sandbox Code Playgroud)
它有效地计算它被调用的次数,因为它存储了捕获的i
.有没有办法"重建"对象,所以它从初始值开始i
?
有点像:
decltype(gen_lam) gen_lam2;
Run Code Online (Sandbox Code Playgroud)
这样以下代码输出1 1
而不是1 2
std::cout << gen_lam() << std::endl;
decltype(gen_lam) gen_lam2;
std::cout << gen_lam2() << std::endl;
Run Code Online (Sandbox Code Playgroud) 我希望实现一个正在使用并显示简单图形的应用程序.其中一个是树,一个像自动机.
我决定在Qt之外使用OGDF,因为我需要布局.但是我不太明白......我是否必须自己实现所有绘图/定位功能(比如从GraphAttributes中获取所有节点和边缘坐标),或者OGDF是否提供了一些不错的界面?(和GraphAttributes :: writeGML()一样好)
这是我正在运行的代码,使用g ++ 4.6和 -std=c++0x
std::unordered_map<int, int> um;
um.insert(std::make_pair(42, 43));
um.insert(std::make_pair(342, 343));
um.insert(std::make_pair(142, 143));
um.insert(std::make_pair(242, 243));
for(auto e : um)
std::cout << e.first << std::endl;
Run Code Online (Sandbox Code Playgroud)
这打印:
242
342
42
142
Run Code Online (Sandbox Code Playgroud)
现在我可以用um.begin()->first
或访问242 um.begin(0)->first
.342可以使用um.begin(1)->first
.但是um.begin(2)->first
或者um.begin(3)->first
使程序崩溃.我能够访问不同的数字um.begin(2)->first
.我无法向自己解释这种行为.我用um.begin(int)
错了吗?
继承我的代码:
#include <stdio.h>
#include <CL/cl.h>
#include <CL/cl_platform.h>
int main(){
cl_float3 f3 = (cl_float3){1, 1, 1};
cl_float3 f31 = (cl_float3) {2, 2, 2};
cl_float3 f32 = (cl_float3) {2, 2, 2};
f3 = f31 + f32;
printf("%g %g %g \n", f3.x, f3.y, f3.z);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
使用gcc 4.6进行编译时,会产生错误
test.c:14:11: error: invalid operands to binary + (have ‘cl_float3’ and ‘cl_float3’)
Run Code Online (Sandbox Code Playgroud)
对我来说很奇怪,因为OpenCL规范在6.4节中只是增加了两个floatn
.我是否需要包含任何其他标题?
但更奇怪的是,在编译时-std=c99
我得到的错误就像
test.c:16:26: error: ‘cl_float3’ has no member named ‘x’
Run Code Online (Sandbox Code Playgroud)
..对于所有组件(x,y和z)......
我使用Configuration
派生自的自定义类 ( )QGraphicsItem
并将其对象添加到 a 中QGraphicsScene
,然后将其显示在QGraphicsView
. 平时的东西。我所做的就是画一棵树,分多个步骤,一步一步,每个节点都在我的自定义QGraphicsItem
.
这里有一个截图。在简单的情况下,树恰好是连续的。
我首先绘制根节点。在用户输入字符串后触发的信号。
void MainWindow::drawRootSlot(ConfigTreeBuilder & builder)//this is a slot
{
c_scene->clear(); //the clear cause headache. i'll expain
Configuration* conf = new Configuration(builder.getNodesX(), builder.getNodesY(),builder.getNodesConfig());
//code
c_scene->addItem(conf);
//code
}
Run Code Online (Sandbox Code Playgroud)
每个后续Configuration
都在另一个插槽内绘制。
void MainWindow::configTreeSlot(ConfigTreeBuilder & builder) //SLOT!!!
{
while(builder.chooseNextNode()) {
Configuration* conf = new Configuration(builder.getNodesX(), builder.getNodesY(), builder.getNodesConfig());
//code, while loop
QGraphicsLineItem *edge = c_scene->addLine(QLineF(*(parentsPoint), conf->getLeftOrigin()));
edge->setZValue(-1); //below the Configuration item
c_scene->addItem(conf);
}
}
Run Code Online (Sandbox Code Playgroud)
第一次完成时,一切正常。当我输入一个新字符串,重置树时,就会发生黑魔法。我期望它做的是:调用drawRootSlot()
,删除整棵树( …
在C中是否存在C++的新布局?我的意思是,一个对象可以在C中的指定位置构建吗?可以realloc()
用于吗?
如何下标多次的工作std::array
,即使所有operator[]
的回报是一个参考,而无需使用任何代理对象(如图所示这里)?
例:
#include <iostream>
#include <array>
using namespace std;
int main()
{
array<array<int, 3>, 4> structure;
structure[2][2] = 2;
cout << structure[2][2] << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是如何工作的?