Linux 错误:“公共”之前的预期不合格ID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3748439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error: expected unqualified-id before ‘public’
提问by abbas
I have read a few posts but cannot figure out what is wrong.My Code is a s follows
我已经阅读了一些帖子,但无法弄清楚出了什么问题。我的代码如下
#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
}
thanks...it worked..ur right I am a Java guy.. one more thing
谢谢...它有效...你对,我是一个 Java 人...还有一件事
It gives an error if I write
如果我写它会出错
private int x; private int y;
私有整数 x; 私人内部 y;
and if in the constructor I use Point() { this.x=2; }
如果在构造函数中我使用 Point() { this.x=2; }
Thanks in advance
提前致谢
采纳答案by Prasoon Saurav
Change your Java like syntax to :
将类似 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
回答by sje397
Try this:
尝试这个:
class Point {
int x;
int y;
public:
Point(): x(0), y(0) {
}
};
The syntax you are using looks like Java.
您使用的语法看起来像 Java。