假设我有两个C++类:
class A
{
public:
A() { fn(); }
virtual void fn() { _n = 1; }
int getn() { return _n; }
protected:
int _n;
};
class B : public A
{
public:
B() : A() {}
virtual void fn() { _n = 2; }
};
Run Code Online (Sandbox Code Playgroud)
如果我写下面的代码:
int main()
{
B b;
int n = b.getn();
}
Run Code Online (Sandbox Code Playgroud)
人们可能期望将n
其设置为2.
事实证明,n
设置为1.为什么?
在C++中表示128位数的最佳方法是什么?它应该尽可能地与内置数值类型一致(即支持所有算术运算符等).
我正在考虑构建一个具有2个64位或4个32位数的类.或者可能只是创建一个128位的内存块并自己完成所有操作.
是否有一些更容易/更标准的方式,或者我自己实施它时不太可能搞砸的东西?:)
如果它可以扩展到256位,512位等等也会很好...
我正在针对Base 4.0 SDK编写iPhone应用程序,但我的目标是OS 3.1.3,因此OS 3用户可以使用该应用程序.
我打电话:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
Run Code Online (Sandbox Code Playgroud)
在iOS 4.0中已弃用.我知道这一点,如果我们在iOS 4.0或更高版本下运行,我们已采取措施调用较新的"withAnimation"版本.
但是,我收到一条警告,我正在调用一个已弃用的SDK.
我想在这个特定的地方禁用此特定警告.我想要所有其他警告(包括其他位置的相同弃用警告)
这可以在Xcode中实现吗?
将Visual Sourcesafe存储库移动到Mercurial的最佳方法是什么(我有兴趣保留所有历史记录)?
我想在Visual Studio项目中使用C99头文件inttypes.h(我想打印64位数字).
但是,我的安装中似乎不存在此文件.
这不是VS2005的一部分吗?还有其他选择吗?
有没有办法将Mercurial集成到Visual Studio 2005中?我们希望能够直接从IDE进行签入,查看历史记录等.
我在使用C++代码时遇到了问题,这些代码意外地对调用者抛出异常.读取用于查看是否抛出异常的模块的每一行并不总是可行或实际的,如果是,则抛出异常类型.
是否存在处理此问题的成语或"最佳实践"?
我想到了以下几点:
在我们的doxygen文档中,我们可以在每个预期会抛出异常及其类型的函数中添加注释.
我们可以安装应用程序try/catch(...)
.
使用例外规范
有这些方法的经验,还是我不知道的任何其他方法?
我们在Windows上有一个启动java进程的C++应用程序.这两个应用程序需要相互通信(通过xml的片段).
你会选择什么进程间通信方法,为什么?
我们的表上的方法是:共享文件,管道和套接字(虽然我认为这有一些安全问题).我对其他方法持开放态度.
当我在Visual Studio 2005中编译此代码时:
template <class T>
class CFooVector : public std::vector<CFoo<T>>
{
public:
void SetToFirst( typename std::vector<CFoo<T>>::iterator & iter );
};
template <class T>
void CFooVector<T>::SetToFirst( typename std::vector<CFoo<T>>::iterator & iter )
{
iter = begin();
}
Run Code Online (Sandbox Code Playgroud)
我收到这些错误:
c:\home\code\scantest\stltest1\stltest1.cpp(33) : error C2244: 'CFooVector<T>::SetToFirst' : unable to match function definition to an existing declaration
c:\home\code\scantest\stltest1\stltest1.cpp(26) : see declaration of 'CFooVector<T>::SetToFirst'
definition
'void CFooVector<T>::SetToFirst(std::vector<CFoo<T>>::iterator &)'
existing declarations
'void CFooVector<T>::SetToFirst(std::_Vector_iterator<_Ty,_Alloc::rebind<_Ty>::other> &)'
Run Code Online (Sandbox Code Playgroud)
如果我将一个typedef添加到CFooVector模板,我可以获得编译和工作的代码:
template <class T>
class CFooVector : public std::vector<CFoo<T>>
{
public:
typedef typename …
Run Code Online (Sandbox Code Playgroud)