srand()/rand()第三方库中有大量使用预定义种子的呼叫.在同一过程中组合不同的库时会出现问题.有时很难确保正确的呼叫顺序,混合srand()和rand()呼叫是可能的.另一个问题是无法在应用程序级别选择播种值.作为一般规则,我们是否应该避免srand()在库中使用(包括开源),将播种任务留给应用程序?
当我尝试使用带有流缓冲区重定向的三元条件运算符(?:)时,gcc会生成'此处首先需要的合成方法'错误.有什么问题,以及如何纠正以下程序?
#include <fstream>
#include <iostream>
int main(int argc, char* argv[])
{
using namespace std;
cout << cin.rdbuf(); //OK
ofstream("tmp.txt") << cin.rdbuf(); //OK
int i=1;
(i > 1 ? ofstream("tmp.txt") : cout) << cin.rdbuf(); //Compilation ERROR. Why?
return 0;
}
Run Code Online (Sandbox Code Playgroud)
用gcc4.4编译:
...
/usr/include/c++/4.4/bits/ios_base.h: In copy constructor ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’:
/usr/include/c++/4.4/bits/ios_base.h:790: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
/usr/include/c++/4.4/iosfwd:47: error: within this context
/usr/include/c++/4.4/iosfwd: In copy constructor ‘std::basic_ostream<char, std::char_traits<char> >::basic_ostream(const std::basic_ostream<char, std::char_traits<char> >&)’:
/usr/include/c++/4.4/iosfwd:56: note: **synthesized method** ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, …Run Code Online (Sandbox Code Playgroud) 在应用程序的res / values / colors.xml文件中,以#AARRGGBB格式定义了红色:
<color name="red">#ffff0000</color>
Run Code Online (Sandbox Code Playgroud)
如何将此颜色用作glClearColor和其他OpenGL ES函数的参数?例如:
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f); // <-- How to connect R.color.red here?
}
Run Code Online (Sandbox Code Playgroud)