我第一次使用eclipse.我是一名经验丰富的VisualStudio用户,所以我试图在eclipse中找到类似的功能.我有两个项目,A和B.项目A在完成编译后吐出libA.a.项目B链接libA.a. 这是我的问题.
如何让项目B知道项目A的输出?目前我不得不做一个干净的项目B构建,以便重新链接libA.a.
谢谢.
编辑:在我的ProjectB->路径和符号 - >参考选项卡中,我检查了项目A. 重建项目A后,这不会重新链接.
来自C++背景,我习惯于将const关键字粘贴到函数定义中,以使对象以只读值传递.但是,我发现在C#中这是不可能的(如果我错了请纠正我).经过一些谷歌搜索后,我得出的结论是,制作只读对象的唯一方法是编写一个只有'get'属性并将其传入的接口.优雅,我必须说.
public interface IFoo
{
IMyValInterface MyVal{ get; }
}
public class Foo : IFoo
{
private ConcreteMyVal _myVal;
public IMyValInterface MyVal
{
get { return _myVal; }
}
}
Run Code Online (Sandbox Code Playgroud)
我会把它传递给:
public void SomeFunction(IFoo fooVar)
{
// Cannot modify fooVar, Excellent!!
}
Run Code Online (Sandbox Code Playgroud)
这可以.但是,在我的其余代码中,我想正常修改我的对象.向接口添加"set"属性会破坏我的只读限制.我可以添加一个'set'属性Foo(而不是IFoo),但签名需要一个接口而不是一个具体的对象.我不得不做一些铸造.
// Add this to class Foo. Might assign null if cast fails??
set { _myVal = value as ConcreteMyVal; }
// Somewhere else in the code...
IFoo myFoo = new Foo; …Run Code Online (Sandbox Code Playgroud) 我是一名C++开发人员,在测试时,通过注入依赖项,覆盖成员函数等来测试类很容易,这样您就可以轻松地测试边缘案例.但是,在C中,您无法使用这些精彩的功能.我发现很难将单元测试添加到代码中,因为编写C代码的一些"标准"方法.解决以下问题的最佳方法是:
传递一个大的'context'结构指针:
void some_func( global_context_t *ctx, .... )
{
/* lots of code, depending on the state of context */
}
Run Code Online (Sandbox Code Playgroud)
没有简单的方法来测试依赖函数的失败:
void some_func( .... )
{
if (!get_network_state() && !some_other_func()) {
do_something_func();
....
}
...
}
Run Code Online (Sandbox Code Playgroud)
具有大量参数的函数:
void some_func( global_context_t *, int i, int j, other_struct_t *t, out_param_t **out, ...)
{
/* hundreds and hundreds of lines of code */
}
Run Code Online (Sandbox Code Playgroud)
静态或隐藏功能:
static void foo( ... )
{
/* some code */
}
void some_public_func( ... }
{
/* …Run Code Online (Sandbox Code Playgroud) 我一直在寻找OpenGL着色器的例子,我看到了一些不同的风格.一些着色器专门使用内置类型(即gl_Vertex)与应用程序代码和着色器之间传输数据.
一些着色器使用变化类型将数据从顶点传输到片段着色器而不是gl_Position和gl_FragColor.
一些着色器使用前缀'in'和'out'来指定数据传输:
in vec3 vertex;
void main() {
gl_Position = projection_matrix * modelview_matrix * vec4(vertex, 1.0);
}
Run Code Online (Sandbox Code Playgroud)
...而其他人使用属性:
attribute vec4 vertex_attrib;
attribute vec4 tex_coord_attrib;
attribute vec4 color_attrib;
uniform mat4 mvp_matrix;
uniform mat4 texture_matrix;
varying vec4 frag_color;
varying vec2 tex_coord;
void main(void)
{
gl_Position = mvp_matrix * vertex_attrib;
vec4 transformed_tex_coord = texture_matrix * tex_coord_attrib;
tex_coord = transformed_tex_coord.st / transformed_tex_coord.q;
frag_color = color_attrib;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,GLES 2.0中编写着色器的首选方法是什么?有最佳实践指南吗?有人可以提供一个顶点和片段着色器的例子,它是"怎样做"的光辉榜样?
谢谢.
这可能是一个菜鸟问题.据我了解,只要AAA是唯一的,glBindAttribLocation(...,AAA,...)就会将程序中的属性绑定到AAA的位置ID.如果我有以下代码:
glBindAttribLocation(..., 0, "XXX");
glBindAttribLocation(..., 1, "YYY");
Run Code Online (Sandbox Code Playgroud)
这会将我的两个变量绑定到位置ID 0和1.然后我会调用:
glBindBuffer(GL_ARRAY_BUFFER, VBId);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBId);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 6, 0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 6, (void *) 0 + sizeof(float) * 3);
glEnableVertexAttribArray(1);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
Run Code Online (Sandbox Code Playgroud)
到目前为止,我理解0和1的ID作为第一个参数传递给glVertexAttribPointer().
如果我通过glGetAttribLocation()调用获得属性的位置ID(如上所述),以便返回的ID是5和6而不是0和1,我是否可以安全地将5和6传递给glVertexAttribPointer( )和glEnableVertexAttribArray()而不是0和1 ??
我有一个WinForm应用程序,它承载了许多图像.当我将应用程序放在DPI为120的Win7机器上时,它完全破坏了表单的外观.有没有办法禁用我的表单缩放?
我知道这是不建议的事情,DPI应该是无缝的并由操作系统处理.但是当谈到皮肤应用程序时,图像不能很好地扩展.我没有为所有DPI变体创建图像的奢侈,所以请不要建议作为答案.
I have a Label on a Windows.Form. I set the AutoSize property on the label to True and I noticed that when I do that, it pads the right hand side with ~5px of white background. I have the Padding property set to [0, 0, 0, 0]. Is there a way to get rid of this?
I would like to get the bounds of the label as close as possible to the text within the label.
我正在测试我公司编写的应用程序.其中一个场景是查看该应用程序崩溃时系统状态会发生什么.那里有一个应用程序可以强制崩溃我的应用程序吗?我宁愿不在代码本身写崩溃(即空指针取消引用).使用任务管理器终止进程不会产生相同的结果.
以下是演员:
int foo = (int) somefloat;
Run Code Online (Sandbox Code Playgroud)
但是,这被视为演职员吗?
int foo = int( somefloat );
Run Code Online (Sandbox Code Playgroud)
更重要的是,如果两者之间存在差异,那么得到的编译代码是不同的?
将类成员变量放在初始化列表中不需要在初始化列表中是否有任何好处?例:
class Foo
{
public:
Foo() {}
};
class Bar
{
public:
Bar() : _foo() {}
private:
Foo _foo;
};
Run Code Online (Sandbox Code Playgroud)
在这种情况下,编译器是否会执行任何特殊操作?
c++ compiler-construction optimization coding-style initializer-list