2010-09-20 113 views
2

我讀了幾個帖子,但無法弄清楚wrong.My碼是什麼,是錯誤:之前預期不合格的ID「公共」

#include <iostream> 
using namespace std; 


/* compiles with command line gcc xlibtest2.c -lX11 -lm -L/usr/X11R6/lib */ 
#include <X11/Xlib.h> 
#include <X11/Xutil.h> 
#include <X11/Xos.h> 
#include <X11/Xatom.h>  
#include <stdio.h> 
#include <math.h> 
#include <stdlib.h> 

public class Point 
{ 
    int x; 
    int y; 

public Point() 
     { 
      this.x=0; 
      this.y=0; 
     } 
}; 



/*Code For XLib-Begin*/ 

Display *display_ptr; 
Screen *screen_ptr; 
int screen_num; 
char *display_name = NULL; 
unsigned int display_width, display_height; 

Window win; 
int border_width; 
unsigned int win_width, win_height; 
int win_x, win_y; 

XWMHints *wm_hints; 
XClassHint *class_hints; 
XSizeHints *size_hints; 
XTextProperty win_name, icon_name; 
char *win_name_string = "Example Window"; 
char *icon_name_string = "Icon for Example Window"; 

XEvent report; 

GC gc, gc_yellow, gc_red, gc_grey,gc_blue; 
unsigned long valuemask = 0; 
XGCValues gc_values, gc_yellow_values, gc_red_values, gc_grey_values,gc_blue_values;; 
Colormap color_map; 
XColor tmp_color1, tmp_color2; 

/*Code For Xlib- End*/ 





int main(int argc, char **argv) 
{ 
//////some code here 
} 

感謝如下......這worked..ur我的權利是一個Java的傢伙.. 一件事

它給了,如果我寫

私人詮釋具有誤差X; private int y;

如果在構造函數中我使用 Point() { this.x = 2; }

在此先感謝

+0

正確的語法,用於參照本身就是'這個 - >',這是一個指針 – Anycorn 2010-09-20 03:06:52

+0

非常感謝你們......它全部完成。 – abbas 2010-09-20 03:10:51

+2

如果你還沒有的話,你應該選擇[一本好的入門C++書](http://stackoverflow.com/questions/388242/the-definitive-c++-book-guide-and-list)。如果你有一個,你需要閱讀它。除了它們都使用花括號並讓你使計算機做事情之外,Java和C++幾乎沒有什麼共同之處。 – 2010-09-20 03:26:02

回答

4

更改Java的語法來:

class Point //access modifiers cannot be applied to classes while defining them 
{ 
    int x; 
    int y; 

    public : //Note a colon here 

    Point() :x(),y() //member initialization list 
    { 
     //`this` is not a reference in C++     
    } 
}; //Notice the semicolon 
3

試試這個:

class Point { 
    int x; 
    int y; 

    public: 
    Point(): x(0), y(0) { 
    } 
}; 

的語法使用的是看起來像Java。

相關問題