Class member initializations

This is a discussion on Class member initializations within the C++ Programming forums, part of the General Programming Boards category; My compiler refuses to compile this code because of "ISO c++ forbids 'in-class initialization of non-const static member `ExStyle' ' ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Class member initializations

    My compiler refuses to compile this code because of "ISO c++ forbids 'in-class initialization of non-const static member `ExStyle' ' How can I bypass this? Using Dev-cpp on Windows

    Thanks.

    here's the code:

    Code:
    #define _WRAPPER_H
    class Window
    {
    HWND hwnd;
          public:
                 Window();
                 virtual ~Window();//and this
                 HINSTANCE hInst;
                 DWORD ExStyle=0;
                 int   width=400;
                 int   height=300;
                 int   X=400;
                 int   Y=400;
                 HWND Parent=HWND_DESKTOP;
                 char* name[];
                 char* WndClass[]; //Ugly
                 DWORD style=WS_SYSMENU;
          
           hwnd=CreateWindowEx(ExStyle,
                               *WndCls,
                               *name,
                               style,
                                X,
                                Y,
                                width,
                                height,
                                Parent,
                                NULL,
                                hInst,
                                NULL);
           };
          
    };
    #endif

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Data members of a class are initialized in the constructor. You're not allowed to give data members a default value before the constructor is called unless they're static (ie. they belong to the class as opposed to objects of the class). You also have public data members, which is a big no-no, and your arrays lack the required sizes, and you try to call a global function in the class definition outside of a member function? I see a mismatched brace, and _WRAPPER_H stomps all over the implementation's namespace.

    This seems like an overly complicated attempt for someone who clearly has no idea how classes work. Might I recommend some simpler projects to become familiar with object based and object oriented programming?
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    17
    Yeah I guess I should review my classes 101...
    Thanks for comments.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class member function not recognized??
    By pwnz32 in forum C++ Programming
    Replies: 4
    Last Post: 08-23-2008, 04:33 AM
  2. Replies: 6
    Last Post: 07-29-2008, 05:37 AM
  3. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  4. SystemTray class
    By jair in forum C++ Programming
    Replies: 2
    Last Post: 07-28-2003, 07:27 PM
  5. Function pointer to class member?
    By no-one in forum C++ Programming
    Replies: 2
    Last Post: 04-22-2002, 09:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21