Thread: Help with " expected specifier-qualifier-list before 'public' "

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    7

    Help with " expected specifier-qualifier-list before 'public' "

    Guys i tried many things but i can't resolve this error,
    here is the code:

    RawImage.h
    Code:
    struct RawImage
    {
        public: // <- error
            int get_width() const { return width; }
            int get_height() const { return height; }
            byte[] get_raw() const { return raw; }
            void set_width(int w) { width = w; }
            void set_heigth(int h) { heigth = h; }
            void set_raw(byte[] r) { raw = r; }
            RawImage(int w, int h, byte[] r) : width(w), heigth(h), raw(r) { }
            RawImage() { }
        private:
            int width;
            int heigth;
            byte[] raw;
    };
    error :
    Code:
    /RawImage.h|6|error: expected specifier-qualifier-list before ‘public’|

    I'm having the same error in another struct, but i think that isn't necessary put the other struct here since the errors are the same, and resolving this i will be able to resolve the other.
    Many Thanks.
    ps : English isn't my native language, so sorry for any mistake.
    Last edited by nickstyle; 03-17-2012 at 03:29 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > public: // <- error
    Well if you're compiling this as C, then stop using C++ syntax in a struct.

    > byte[] get_raw() const ....
    And also stop using Java syntax for declaring byte arrays as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    7
    What a shame, sorry about that, I'm new with c, but now I'm getting a new error:
    Code:
    RawImage.h|6|error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘{’ token|
    the new code:
    Code:
    struct RawImage
    { //error
            int get_width() { return width; }
            int get_height() { return height; }
            byte *get_raw() { return raw; }
            void set_width(int w) { width = w; }
            void set_heigth(int h) { heigth = h; }
            void set_raw(byte *r) { raw = r; }
            RawImage(int w, int h, byte *r) : width(w), heigth(h), raw(r) { }
            RawImage() { }
        private:
            int width;
            int heigth;
            byte *raw;
    };
    Thanks.

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Quote Originally Posted by nickstyle View Post
    What a shame, sorry about that, I'm new with c, but now I'm getting a new error:
    Code:
    RawImage.h|6|error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘{’ token|
    the new code:
    Code:
    struct RawImage
    { //error
            int get_width() { return width; }
            int get_height() { return height; }
            byte *get_raw() { return raw; }
            void set_width(int w) { width = w; }
            void set_heigth(int h) { heigth = h; }
            void set_raw(byte *r) { raw = r; }
            RawImage(int w, int h, byte *r) : width(w), heigth(h), raw(r) { }
            RawImage() { }
        private:
            int width;
            int heigth;
            byte *raw;
    };
    Thanks.
    • Get rid of "private:". It should be obvious that this, along with the already-removed "public:", shouldn't be here.
    • "byte" is most likely not a type, unless you've type-def'd it. Use "unsigned char" or simply "char".
    • You can't define functions inside a struct. You *might* want to use a function pointer > Function Pointers in C and C++ - Cprogramming.com but still, you can't define the function there.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by nickstyle View Post
    What a shame, sorry about that, I'm new with c

    Then stop posting what is ostensibly still C++ code. If you're so new you aren't aware that the concept of public and private don't exist, then you're not ready for structs yet. Sit down with some good C tutorials. Start at the beginning, with Hello World and the like. Learn C as a totally new language, nothing like C++, except for one letter in the name.

    Tutorials to get you started:
    C Tutorial - Learn C - Cprogramming.com,
    http://kldp.org/files/c+in+21+days.pdf

    Google will turn up scads more. Read through all the lessons and work all the practice problems.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    In C, structs contain data. The data may be basic types (int, float, double), pointers, enumerated types, and other structs.

    Your code has the structs having member functions. Such things are not permitted in C.

    Quote Originally Posted by anduril462 View Post
    Then stop posting what is ostensibly still C++ code.
    The code being posted is more likely to be based on Java, not C++ (that byte[] return type and argument in the first post is certainly not C++). Either way, the code is using multiple features that are not part of C.

    The real mistake the OP is making is to try to learn one programming language by analogy from another. C has more in common with C++ than with Java, but I would never recommend trying to learn C by analogy from C++ (or vice versa). Trying to learn C by analogy from Java is wasting time.
    Last edited by grumpy; 03-17-2012 at 05:59 PM.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by grumpy View Post
    The code being posted is more likely to be based on Java, not C++
    Just to nitipick: looks more like C++ because of the way "public" and "private" are deployed; in java they are used like any other modifier, and doing that would be a basic syntax error ("illegal start of type"). Also, while const is a reserved word in java, it has no use (it is not really a keyword, using it in any context is just an error; the real equivalent is "final").
    Last edited by MK27; 03-17-2012 at 06:59 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Registered User
    Join Date
    Mar 2012
    Posts
    7
    Ok guys, thanks for the help. I'm compiling in C because I was getting an error using the GTK+ library and C++ but maybe you can help me. I will create another topic since the problem now is different and then i will edit this post with the link.
    Thanks

  9. #9
    Registered User
    Join Date
    Mar 2012
    Posts
    7
    So here is the link for the other topic, i think this topic can be closed. But I'm new here and I don't know how to do this.
    GTK+ C++ compiler and signal handlers.
    Thanks again, I'm loving this forum

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: expected specifier-qualifier-list at the end of input
    By DeanWinchester in forum C Programming
    Replies: 5
    Last Post: 12-28-2011, 09:52 AM
  2. Replies: 1
    Last Post: 02-15-2011, 01:51 AM
  3. expected specifier-qualifier-list ip.h
    By quantt in forum C Programming
    Replies: 1
    Last Post: 02-12-2009, 10:24 AM
  4. error: expected specifier-qualifier-list before
    By chinook86 in forum C Programming
    Replies: 6
    Last Post: 03-01-2008, 02:02 AM
  5. Replies: 1
    Last Post: 01-24-2008, 01:07 PM

Tags for this Thread