小编Abh*_*eet的帖子

为什么"a"的输出是-80?

#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.

c side-effects operator-precedence c-preprocessor

2
推荐指数
1
解决办法
319
查看次数

如果构造函数在私有部分,为什么我们不能创建Object?

我想知道为什么我们不能创建对象,如果构造函数在私有部分.我知道如果我使方法静态,我可以调用该方法

<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)

所以,我的问题是:为什么我们不能在构造函数是私有时创建一个对象?

c++ constructor private object

2
推荐指数
1
解决办法
6139
查看次数

如何使用Overload operator []为左侧赋值?

我做了以下代码: -

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使用 …

c++ operator-overloading

2
推荐指数
1
解决办法
1268
查看次数

使用typedef的语法解释

我想了解为什么在下面的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)

c++

2
推荐指数
1
解决办法
744
查看次数

在"for"循环条件下使用"三元运算"是一种好习惯吗?

在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)

c++ for-loop ternary-operator conditional-statements

2
推荐指数
1
解决办法
3260
查看次数

覆盖表面

什么是覆盖表面?我现在必须在覆盖表面上工作,我应该知道覆盖表面的概念吗?因为我不得不转换YUV444-> RGB888

提前致谢

rgb overlay yuv windows-mobile windows-ce

1
推荐指数
1
解决办法
516
查看次数

以二进制形式存档

我想以二进制形式将数据写入文件.

我正在尝试使用下面提到的

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而非二进制形式的数据.

任何人都可以指导我正确的步骤..

提前致谢

c binary file

1
推荐指数
1
解决办法
307
查看次数

c ++类的实例

在下面的代码中,"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++ class object

0
推荐指数
1
解决办法
168
查看次数