c++ - 错误 : expected unqualified-id before ‘public’

标签 c++ linux eclipse ubuntu

我已经阅读了几篇文章,但无法弄清楚哪里出了问题。我的代码如下

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

谢谢...它成功了..你说得对,我是 Java 专家.. 还有一件事

如果我写的话会报错

私有(private)整数 x; 私有(private)整数 y;

如果在我使用的构造函数中 观点() { 这个.x=2;

提前致谢

最佳答案

将类似 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

关于c++ - 错误 : expected unqualified-id before ‘public’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3748439/

相关文章:

java - 如何从 clojure 项目在 eclipse 中使用 java 项目

c++ - 如何调用作为槽的qt函数?

c++ - 使用 libxml++ 将处理指令添加到现有 XML 文档

c++ - 在 Unix/Linux (Ubuntu) 中编译头文件和两个 .cpp 文件

java - Eclipse 桌面应用程序

linux - 如何在 Linux 中为 opencl 编程(安装英特尔 OpenCL SDK)准备 eclipse

c++ - 更少的恒定时间迭代花费更多时间-C++编译器依赖项?

c++ - 获取R数据帧的内存地址

linux - 如何确保一次只运行一个 Bash 脚本实例?

linux - Fedora 21下ARM-GCC编译报错