2010-09-20 4 views
2

J'ai lu quelques messages, mais ne peut pas comprendre ce qui est le code wrong.My est la suivanteerreur: attendu-id non qualifiée avant « public »

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

merci ... ce droit worked..ur I je suis un gars Java .. une chose

Il donne une erreur si je vous écris

private int x; int y privé;

et si dans le constructeur j'utilise Point() { this.x = 2; }

Merci à l'avance

+0

syntaxe correcte pour se référer à lui-même est 'this->', c'est un pointeur – Anycorn

+0

Merci beaucoup les gars ... il est fait. – abbas

+2

Vous devriez vraiment prendre [un bon livre d'introduction C++] (http://stackoverflow.com/questions/388242/the-definitive-c++-book-guide-and-list) si vous n'en avez pas déjà un. Si vous en avez un, vous devez le lire. Mis à part le fait qu'ils utilisent tous les deux des accolades et permettent de faire fonctionner l'ordinateur, Java et C++ ont très peu en commun. –

Répondre

4

Changer votre Java comme syntaxe:

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

Essayez ceci:

class Point { 
    int x; 
    int y; 

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

La syntaxe que vous utilisez ressemble Java.

Questions connexes