#include<stdio.h>
#include<conio.h>
#define ABC 20
#define XYZ 10
#define XXX ABC - XYZ
void main()
{
int a;
a = XXX * 10;
printf("\n %d \n", a);
getch();
}
Run Code Online (Sandbox Code Playgroud)
我认为输出应该是100但是当我看到结果时我发现输出为-80.当我把括号作为#define XXX (ABC-XYZ)然后我输出为100但没有括号我输出为-80.
我想知道为什么我们不能创建对象,如果构造函数在私有部分.我知道如果我使方法静态,我可以调用该方法
<classname> :: <methodname(...)>;
Run Code Online (Sandbox Code Playgroud)
但为什么我们不能创造对象是我不明白的.
我也知道如果我的方法不是静态的,那么我也可以通过以下方式调用函数:
class A
{
A();
public:
void fun1();
void fun2();
void fun3();
};
int main()
{
A *obj =(A*)malloc(sizeof(A));
//Here we can't use new A() because constructor is in private
//but we can use malloc with it, but it will not call the constructor
//and hence it is harmful because object may not be in usable state.
obj->fun1();
obj->fun2();
obj->fun3();
}
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是:为什么我们不能在构造函数是私有时创建一个对象?
我做了以下代码: -
class A{
bool bFlag[2];
public:
A(){
for(int i = 0; i < 2; i++)
bFlag[i] = false;
}
bool operator[](int r){ //i know how to assign value to R.H.S using operator[]
if( r >= 0 || r < 2 ){
bFlag[r] = true;
return bFlag[r];
}
return false;
}
};
int main(){
A obj;
bool x;
x = obj[0]; //this i know
//obj[1] = x; //how to do this is my doubt?
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不知道设定值L.H.S使用 …
我想了解为什么在下面的typedef语法中使用FAR?
#define FAR
//some other instructions
//.....
//.....
typedef struct tagDEVICE_BUFFER_W
{
....
....
}DEVICE_BUFFER_W;
typedef DEVICE_BUFFER_W FAR * LPDEVICE_BUFFER_W; //Why FAR is used here?
Run Code Online (Sandbox Code Playgroud)
如果我不使用下面提到的FAR怎么办?会有什么不同吗?
typedef DEVICE_BUFFER_W * LPDEVICE_BUFFER_W;
Run Code Online (Sandbox Code Playgroud) 在for循环条件中使用三元运算是一种好习惯.我问这个是因为我遇到过这样的情况:三元操作将解决我在循环条件中的问题.
例如:
for( short i = 0 ; i < count ; i++ ){
for( short j = 0 ; j < ( ( x[i] < y[i] ) ? x[i] : y[i] ) ; j++ ){ //Here I am using ternary operation at for loop condition place
//.....
//.....Some Code Here .......
//.....
}
}
Run Code Online (Sandbox Code Playgroud) 什么是覆盖表面?我现在必须在覆盖表面上工作,我应该知道覆盖表面的概念吗?因为我不得不转换YUV444-> RGB888
提前致谢
我想以二进制形式将数据写入文件.
我正在尝试使用下面提到的
FILE *fp = fopen("binaryoutput.rgb888", "ab+");
for(int m=0; m<height; m++)
{
for (int n=0; n< width; n++)
{
temp = (pOutputImg+m*3+n*3); // here pOutputImg & temp is a pointer to a unsigned char
fprintf(fp,"%u",*temp);
}
}
fclose(fp);
Run Code Online (Sandbox Code Playgroud)
我能够获得以pOutputImg而非二进制形式的数据.
任何人都可以指导我正确的步骤..
提前致谢
在下面的代码中,"a"和"&a"包含什么?
class list{
};
int main(){
list *a= new list();
cout<<"\n Values:a="<<a<<" & &a="<<&a<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) c++ ×5
c ×2
object ×2
binary ×1
class ×1
constructor ×1
file ×1
for-loop ×1
overlay ×1
private ×1
rgb ×1
side-effects ×1
windows-ce ×1
yuv ×1