只是好奇为什么C++标准库使用小写和下划线代替camelCase或PascalCase命名约定.
就个人而言,我发现后者在输入代码时更容易处理,但有没有合理的理由使用前者?
我想知道是否在C++中使用g ++ -O3选项对类和C样式结构进行性能比较.有关于此的任何基准或比较.我一直认为C++类比结构更重,也可能更慢(编译时间对我来说不是很重要,运行时间更重要).我将实现一个B树,我应该为了性能而使用类或结构来实现它.
我是C++的初学者.__CODE__当我尝试调试Microsoft Visual C++ 2010 Express中的任何项目时,我收到错误.我在Stackoverflow和Google上搜索了我应该做的事情,但找不到答案.我所理解的文件msvcrtd.lib应该在map\Microsoft Visual Studio 10.0\VC\lib中,但该文件不存在.我该怎么办?
>>>被贬低为>> >.但是如果第一个>关闭模板参数列表会发生什么,结果是否应该等于> > >或> >>?
它在以下代码中很重要:
template<class T> struct X { };
void operator >>(const X<int>&, int) { }
int main() {
*new X<int>>> 1;
}
Run Code Online (Sandbox Code Playgroud) 我一直在研究,没有任何相关的问题,所以我来到这里.
我试图避免内存泄漏,所以我想知道:
假设我有一个MyClass成员ints a和b一个类int array c,它们填充了一个成员函数:
class MyClass
{
public:
int a, b;
int c[2];
void setVariables()
{
a, b = 0;
for (int i = 0; i < 2; i++)
{
c[i] = 3;
}
}
};
int main(int argc, char* argv[])
{
MyClass* mc = new MyClass();
mc->setVariables();
delete mc;
}
Run Code Online (Sandbox Code Playgroud)
现在,我打电话后delete mc,会a,b以及所有的内容c被删除?或者我必须在析构函数中明确地做到这一点MyClass?
根据MSDN,typedef语法是:
typedef type-declaration同义词;
很容易:
typedef int MY_INT;
Run Code Online (Sandbox Code Playgroud)
但是成员函数指针typedef如何符合这条规则呢?
typedef int (MyClass::*MyTypedef)( int);
Run Code Online (Sandbox Code Playgroud)
100%混淆 - 同义词(MyTypedef)在中间?
有人可以解释从MSDN的非常容易理解的语法格式到上面的typedef的反向/随机/前/上/混合语法的逻辑步骤是什么?
*编辑感谢所有快速答案(和我的帖子的美化):)
以下代码:
template <class T1>
struct A1
{
template <int INDEX>
struct A2 { /* ... */ };
template <>
struct A2<-1> { /* ... */ };
};
int main()
{
A1<int>::A2<-1> x;
}
Run Code Online (Sandbox Code Playgroud)
给出了这个错误:
prog.cpp:7:13:错误:非命名空间范围的显式特化
'struct A1<T1>'prog.cpp:8:10:错误:部分特化中未使用的模板参数:
prog.cpp:8:10:错误:'T1'
如何最好地解决此错误?我试过这个:
template <class T1>
struct A1
{
template <int INDEX, class DUMMY = void>
struct A2 { /* ... */ };
template <class DUMMY>
struct A2<-1, DUMMY> { /* ... */ };
};
int main()
{
A1<int>::A2<-1> x;
}
Run Code Online (Sandbox Code Playgroud)
这似乎工作,但似乎有点软糖. …
我想将函数的"binder"保存到变量中,通过利用其运算符重载工具在下面的代码中重复使用它.这是实际做我想要的代码:
#include <boost/bind.hpp>
#include <vector>
#include <algorithm>
#include <iostream>
class X
{
int n;
public:
X(int i):n(i){}
int GetN(){return n;}
};
int main()
{
using namespace std;
using namespace boost;
X arr[] = {X(13),X(-13),X(42),X(13),X(-42)};
vector<X> vec(arr,arr+sizeof(arr)/sizeof(X));
_bi::bind_t<int, _mfi::mf0<int, X>, _bi::list1<arg<1> > > bindGetN = bind(&X::GetN,_1);
cout << "With n =13 : "
<< count_if(vec.begin(),vec.end(),bindGetN == 13)
<< "\nWith |n|=13 : "
<< count_if(vec.begin(),vec.end(),bindGetN == 13 || bindGetN == -13)
<< "\nWith |n|=42 : "
<< count_if(vec.begin(),vec.end(),bindGetN == 42 || bindGetN …Run Code Online (Sandbox Code Playgroud) 要使用FreeGlut librarie功能,我必须执行以下操作,
但是,整个系统(.h,.lib和.dll)如何相互关联?
我知道,最基本的事情是添加一个带有类声明的头文件,并在其各自的源文件中写入正文.最后将头文件包含在主应用程序中.
c++ ×10
c++11 ×2
class ×2
boost-bind ×1
coding-style ×1
header-only ×1
lowercase ×1
member ×1
performance ×1
struct ×1
templates ×1
typedef ×1
types ×1
variables ×1
visual-c++ ×1