查看以下C++代码
class Base1 {
public:
Base1();
virtual ~Base1();
virtual void speakClearly();
virtual Base1 *clone() const;
protected:
float data_Base1;
};
class Base2 {
public:
Base2();
virtual ~Base2();
virtual void mumble();
virtual Base2 *clone() const;
protected:
float data_Base2;
};
class Derived : public Base1, public Base2 {
public:
Derived();
virtual ~Derived();
virtual Derived *clone() const;
protected:
float data_Derived;
};
Run Code Online (Sandbox Code Playgroud)
"C++对象模型内部"4.2表示类Base1,Base2和Derived的虚拟表布局如下:


我的问题是:
Base2::mumbleDerived类的Base1子对象的虚拟表包含.为什么?我知道Derived类与Base1共享这个虚拟表,所以我认为Base2的功能不应该出现在这里.有人可以告诉我为什么?谢谢.
我已经学习了一段时间的OpenGL编程.我发现了一个非常奇怪的现象:我的FPS(每秒帧数)总是保持在60左右,无论程序是非常容易还是有点复杂.实际上,我的电脑是去年购买的性能很好.显卡是nVidia GTX570,CPU是I7.
所以我做了一个实验:在我的电脑和朋友的电脑上运行相同的程序.这个程序实现阴影映射:

我的计算机中的FPS大约是60.但是当我在朋友的电脑上运行它时,FPS超过400.

但是我的电脑性能明显优于他.现在我发布电脑的参数.
我的电脑:
tgt.init (Info) GLEW version: 1.7.0
tgt.GpuCapabilities (Info) OS version: Windows 7 (build 7600)
tgt.GpuCapabilities (Info) OpenGL Version: 4.2.0
tgt.GpuCapabilities (Info) OpenGL Renderer: GeForce GTX 570/PCIe/SSE2
tgt.GpuCapabilities (Info) GPU Vendor: NVIDIA Corporation (NVIDIA)
tgt.GpuCapabilities (Info) Texturing: yes, max size: 16384, 3D: yes, max 3D size: 2048
tgt.GpuCapabilities (Info) Texture features: 32 units, NPOT, rectangles, compression, 16x anisotropic
tgt.GpuCapabilities (Info) Framebuffer Objects: yes, max 8 color attachments
tgt.GpuCapabilities (Info) Shaders: yes (OpenGL 2.0), GLSL Version 4.20, …Run Code Online (Sandbox Code Playgroud) 我是C++的新生,特别是关于面向对象的编程.现在我在学习期间遇到了问题.
下面是一个类层次结构:
class Class{};
class Base:public Class{};
class Derived1:virtual public Base{};
class Derived2:virtual public Base{};
class MI:public Derived1,public Derived2{};
class Final:public MI,public Class{};
Run Code Online (Sandbox Code Playgroud)
现在我想知道Final类对象定义的构造函数的顺序是什么.
我画了一个图:
类继承的结构http://hi.csdn.net/attachment/201203/16/2712336_1331902452BziD.jpg
我知道虚拟基类总是在非虚基类之前构建,而不管它们在继承层次结构中出现的位置.我感到困惑的是,如果Class类的构造函数在Base之前,并且如果Class的构造函数被调用两次.为什么?
有人可以告诉我答案吗?越详细越好.
在下面的C++ STL程序中,我定义了一个算子Nth,如果它在第n次撤销,它返回true.我将它转换为通用算法remove_if,我得到一些奇怪的东西.
代码:
#include <iostream>
#include <list>
#include <algorithm>
#include "print.hpp"
using namespace std;
class Nth{
private:
int nth,ncount;
public:
Nth(int n):nth(n),ncount(0){}
bool operator()(int)
{
return ++ncount == nth;
}
};
int main()
{
list<int> col;
for (int i = 1;i <=9 ;++i)
{
col.push_back(i);
}
PRINT_ELEMENTS(col,"col : ");
list<int>::iterator pos;
pos = remove_if(col.begin(),col.end(),
Nth(3));
col.erase(pos,col.end());
PRINT_ELEMENTS(col,"nth removed : ");
}
Run Code Online (Sandbox Code Playgroud)
print.hpp:
#include <iostream>
template <class T>
inline void PRINT_ELEMENTS (const T& coll, const char* optcstr="")
{
typename …Run Code Online (Sandbox Code Playgroud) 我正在学习OpenGL 4.0,我想用OpenGL 4.0和GLSL绘制一个简单的三角形.我正在使用带有交错数组的VAO来实现它,但它显示的结果并不是我想要的结果:

现在我发布部分代码:
void SceneBasic::setupVAOInterleavedArrays()
{
//?????????????:????
float positionAndColorData[] = {
-0.8f, -0.8f, 0.0f,1.0f, 0.0f, 0.0f,
0.8f, -0.8f, 0.0f,0.0f, 1.0f, 0.0f,
0.0f, 0.8f, 0.0f,0.0f, 0.0f, 1.0f };
//glInterleavedArrays(GL_C3F_V3F,0,positionAndColorData)
GLuint vboHandle;//VBO
glGenBuffers(1,&vboHandle);
glBindBuffer(GL_ARRAY_BUFFER,vboHandle);
glBufferData(GL_ARRAY_BUFFER,18 * sizeof(float),
positionAndColorData,GL_STATIC_DRAW);
//VAO
glGenVertexArrays(1,&vaoHandle);
glBindVertexArray(vaoHandle);
//enable the generic vertex attribute indexes
//indicates that the values for the attributes will be accessed
//and used for rendering
glEnableVertexAttribArray(0);//position
glEnableVertexAttribArray(1);//color
//make the connection between the buffer objects and the generic
//vertex attributes indexes
glBindBuffer(GL_ARRAY_BUFFER,vboHandle);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3 * sizeof(float),BUFFER_OFFSET(0));
glBindBuffer(GL_ARRAY_BUFFER,vboHandle); …Run Code Online (Sandbox Code Playgroud) 看下面的代码:
#include <iostream>
using namespace std;
class Widet{
public:
Widet(int val = 0):value(val)
{
}
Widet& operator=(Widet &rhs)
{
value = rhs.value;
return *this;
}
int getValue()
{
return value;
}
private:
int value;
};
int main()
{
Widet obj1(1);
Widet obj2(2);
Widet obj3(0);
(obj3 = obj2) = obj1;
cout << "obj3 = " << obj3.getValue() << endl;
}
Run Code Online (Sandbox Code Playgroud)
代码运行成功,输出为(使用VS2008):

当我让operator =返回一个值而不是引用时:
Widet operator=(Widet &rhs)
{
value = rhs.value;
return *this;
}
Run Code Online (Sandbox Code Playgroud)
它也成功运行,输出为:

我的问题是:为什么第二个代码运行良好?我们不应该得到错误吗?
为什么返回引用*this而不是*this这是一个好习惯?
我已经阅读了有关意图锁定的MySQL手册? http://dev.mysql.com/doc/refman/5.5/zh-CN/innodb-locking.html#innodb-intention-locks
它说“使在多个粒度级别上的锁定切实可行”,但是如何呢?它没有告诉我们这件事。
谁能提供详细的解释和样本?
我想监控 Spring-data-redis 中的池指标。JedisConnectionFactory 的池是私有的。我怎么才能得到它?我搜索谷歌,但我找不到这样做的好方法。
我现在想使用非对称高斯滤波器内核来使用matlab平滑图像,因为我不希望在垂直和水平方面具有相同的平滑度(具有不同的高斯模式大小和不同的标准偏差).但我找不到一个系统功能来完成这项工作.似乎函数fspecial不支持这一点.
那么,我该如何实现这个过滤器呢?
非常感谢.
我们知道,可以在类结构中初始化整数const静态成员.这在初始化后在类结构中使用常量时很有用.例如,它可以用作int数组的大小.查看以下代码:
class MyClass{
static const int num = 100;
int elems[num];
...
};
Run Code Online (Sandbox Code Playgroud)
但是我们仍然需要在类定义之外定义成员num:
const int MyClass::num;
Run Code Online (Sandbox Code Playgroud)
我不知道为什么我们要这样做.有人能告诉我为什么吗?非常感谢.
另外,我写了以下代码:
#include <iostream>
using namespace std;
class MyClass{
public:
MyClass()
{
cout << "instruct class MyClass!" << endl;
}
static const int num = 100;
int elems[num];
};
//const int MyClass::num;
int main()
{
MyClass a;
const int *b = &(a.num);
cout << "&(a.num): " << &(a.num) << endl;
cout << "a.num: " << a.num << endl;
cout << "*b: …Run Code Online (Sandbox Code Playgroud)