LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Makeing my code look cleanner for others (http://www.linuxquestions.org/questions/programming-9/makeing-my-code-look-cleanner-for-others-289138/)

Starch 02-11-2005 08:55 PM

Makeing my code look cleanner for others
 
[in c++ using g++ compiler]

I have a class with 2 enums (actually more but for example to simplify things)
Code:

enum{
        a        =aa,
        b        =bb
        }

enum{
        aa        =2,
        bb        =3
        }

Now the second enum I want to be private because its not userfriendly. The problem is the second enum must be first for it to compile. Is there a way I can just keep all the public stuff in one section(beginning) and the rest afterwards.

Currently it looks alitle like a mess because of the enums.

Thanks in advance!

QtCoder 02-15-2005 08:57 PM

Well, as far as I know, you can't do it with G++ (MSVC maybe). What would need to be done is some sort of a forward declaration of your private enum, but forward declaring enums doesn't comply to ansi c++, and therefore doesn't work with G++. (plus, I don't know how an anonymous enum could be forward declared anyway).

You can have multiple public: and private: sections in a class. What I would do is something like this:

Code:

class myClass
{
  private:
      enum{aa=2, bb=3};

  public:
      enum{a=aa, b=bb};
      // public interface

  private:
      // the rest of the private functions & variables
}

In my opinion, that's very readable.


All times are GMT -5. The time now is 06:47 AM.