Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 |
class X; { public: int& Y() {return _y;} private: int _y; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
class X; { public: void Y(int y) {_y=y;} int Y() {return _y;} private: int _y; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
template <typename T> class foo { T m_data; public: foo(T const& data) : m_data(data) {} public: T const& get() const { return m_data; } void set(T const& data) { m_data = data; } }; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 |
class foo { int m_data; public: foo(int data) : m_data(data) {} public: int get() const { return m_data; } void set(int data) { m_data = data; } }; |
Zitat von »"Deviloper"«
Ehm das ist nicht nur stilistisch ekelhaft sondern untergräbt förmlich den Sinn von private. Dann kannst du es auch direkt lassen.
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
class window { private: HWND m_hwnd; public: HWND GetHwnd (void) { return m_hwnd; } // oder von mir aus: HWND& GetHwnd (void) { return m_hwnd; } } |
C-/C++-Quelltext |
|
1 2 3 |
T const& get() const { return m_data; } // = Datentyp constRef Funktionsname() const { return m_data; } |
C-/C++-Quelltext |
|
1 |
void foo(const bar& inst) { std::cout << inst.get_handle() << std::endl; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
class Window { ::HWND m_hWnd; public: ::HWND get_handle() const { return m_hWnd; } // oder von mir aus: ::HWND const & get_handle() const { return m_hWnd; } }; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
#if !defined (_FORMS_HPP_) #define _FORMS_HPP_ // i n c l u d e s #include <windows.h> namespace Forms { // class Window class Window { protected: // m e m b e r _ v a r i a b l e s HWND m_hWndWindow; HWND m_hWndParent; HMENU m_hMenu; HINSTANCE m_hInstance; LPCWSTR m_WindowName; // m e m b e r _ f u n c t i o n s void Close (void); public: // m e m b e r _ f u n ct i o n s Window (void); ~Window (void) { Close(); } int Create (const WNDCLASSEX& wc, DWORD dwExStyle, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, LPVOID lpParam); void Show (int nCmdShow); // g e t const HWND GetHandle (void) { return m_hWndWindow; } const HWND GetParent (void) { return m_hWndParent; } const HMENU GethMenu (void) { return m_hMenu; } const HINSTANCE GethInstance (void) { return m_hInstance; } const LPCWSTR GetName (void) { return m_WindowName; } }; // class WINDOW // class button class Button { protected: // m e m b e r _ v a r i a b l e s HWND m_hWndButton; HWND m_hWndParent; HINSTANCE m_hInstance; LPCWSTR m_ButtonName; public: // m e m b e r _ f u n c t i o n s Button (void); ~Button (void); int Create (DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpBtnText, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam); // g e t const HWND GethWnd (void) { return m_hWndButton; } const HWND GetParent (void) { return m_hWndParent; } }; // class Button } // namespace Forms #endif |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
// i n c l u d e s #include "Forms.hpp" using namespace Forms; // class CWindow // m e m b e r _ f u n c t i on s Window::Window (void) : m_hWndWindow(NULL), m_hWndParent(NULL), m_hMenu(NULL) {} // Window::WINDOW() int Window::Create(const WNDCLASSEX& wc, DWORD dwExStyle, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, LPVOID lpParam) { m_WindowName = lpWindowName; m_hInstance = wc.hInstance; if(!RegisterClassEx(&wc)) { return 1; } m_hWndWindow = CreateWindowEx( dwExStyle, wc.lpszClassName, m_WindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, wc.hInstance, lpParam); if(!m_hWndWindow) { return 1; } ShowWindow(m_hWndWindow, SW_HIDE); UpdateWindow(m_hWndWindow); return 0; } // Window::Create() void Window::Show (int nCmdShow) { ShowWindow(m_hWndWindow, nCmdShow); //UpdateWindow(m_hWndWindow); } // Window::Show() void Window::Close (void) { UnregisterClass(m_WindowName, m_hInstance); PostQuitMessage(0); } // Window::Close() |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
// i n c l u d e s #include "Forms.hpp" using namespace Forms; // class CButton Button::Button(void) : m_hWndButton(NULL), m_hWndParent(NULL) {} Button::~Button(void) {} int Button::Create (DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpBtnText, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) { m_hWndParent = hWndParent; m_hInstance = hInstance; m_hWndButton = CreateWindowEx( dwExStyle, lpClassName, lpBtnText, dwStyle, X, Y, nWidth, nHeight, m_hWndParent, hMenu, m_hInstance, lpParam); return 0; } // Create() |
C-/C++-Quelltext |
|
1 2 3 4 5 6 |
// g e t const HWND GetHandle (void) { return m_hWndWindow; } const HWND GetParent (void) { return m_hWndParent; } const HMENU GethMenu (void) { return m_hMenu; } const HINSTANCE GethInstance (void) { return m_hInstance; } const LPCWSTR GetName (void) { return |
Werbeanzeige