答えが見つからないようですが、間違った用語を検索している可能性があります。探している答えがヒットに見つかりません。
メニューシステム用の派生クラスがたくさんあります。
aと aクラスCControl
の親である派生クラスがあります。テキストを SDL_Surface にアタッチし、openGL がレンダリングするテクスチャにバインドするだけです。 テキストを表示したり、パスワード ボックスのようにユーザーからテキストを収集したりするためのフィールドになります。明らかに、CEditBox は、ボックス内のテキスト レンダリングを処理するためにラベルを利用できます。 から導出されます。 CEditBox
CLabel
CLabel
CEditBox
CControl
CComponent
ヘッダーに含めない限り、CLabel
内部で宣言することはできませんが、すべてのヘッダーを構文でラップしているにもかかわらず、リンカーエラーが発生し続けると思いますが、初心者でもあります。代わりに、そのクラスから派生したポインターを宣言しています。 CEditBox
CLabel
#ifndef #define class #endif
CComponent*
罰金。今私が持っているのコンストラクターでCEditBox
:
#include "CLabel.h" //include in .CPP is fine I reckon.
CEditBox::CEditBox() {
CLabel Field; //Create CLabel
InputType = ALL; //Not important for my question related to allowed symbols
Label = &Field; //CComponent pointer to CLabel
}
このコンストラクター関数が戻ると、CLabel は範囲外になり、Feild が破棄され、ポインターが未定義のメモリ ブロックを指しているのではないでしょうか? これを行う適切な方法は何ですか?より良い解決策はありますか?
ありがとうございました
リンカーの問題
問題がもう存在するかどうかはわかりませんが、これはより重要な問題だと考える人もいます。これが実際のコードです。間違っていると思われる場合は教えてください。基本クラス CMenuObject
#ifndef _CMENUOBJECT_H_
#define _CMENUOBJECT_H_
class CMenuObject {
protected:
const char* ClassName;
public:
CMenuObject();
virtual const char* Object();
};
#endif
次のクラスは CComponent です
#ifndef _CCOMPONENT_H_
#define _CCOMPONENT_H_
#include "CMenuObject.h"
class CComponent : public CMenuObject {
protected:
const char* _Name;
int _Tag;
static int _ComponentCount;
static int _IDCount;
public:
CComponent();
virtual const char* Name();
virtual int Tag();
virtual void Tag(int t);
};
#endif
次に、CControl が続きます。これらは、ユーザーが対話するオブジェクト、または何らかの方法でディスプレイを制御する必要がある (つまり、タイマーはユーザー入力を必要としない) 巨大なオブジェクトです。私はまだそれで何をしているのかわからないので、関数ポインタのものを気にしないでください..これは、イベントを処理するための私の最初の推測アプローチです. 関数がパラメーターを受け取る必要がある場合にどうすればよいかがわからないため、制限があると思いますが、そうする必要はないかもしれません...今のところ、この詳細については説明しません。
#ifndef _CCONTROL_H_
#define _CCONTROL_H_
#include "CComponent.h"
class CControl : public CComponent {
protected:
int _X,_Y,_Width,_Height;
float R,G,B,A;
void (*OnClk)();
void (*OnDblClk)();
void (*OnMOver)();
void (*OnMHover)();
void (*OnKDown)();
void (*OnKUp)();
void (*OnFcs)();
bool Visible;
CComponent* Pappy;
public:
CControl();
//Render Control
virtual void Show(); // Show Component
virtual void Hide(); // Hide Component
virtual void OnRender(); // Render Component
virtual bool IsVisible(); // Get Current Visibility Status
//Paramater Control
//Write
virtual void X(int x); // Set Component's X coordinate
virtual void Y(int y); // Set Component's Y coordinate
virtual void Width(int w); // Set Component's Width
virtual void Height(int h); // Set Component's Height
//Read
virtual int X(); // Get Component's X coordinate
virtual int Y(); // Get Component's Y coordinate
virtual int Width(); // Get Component's Width
virtual int Height(); // Get Component's Height
//Display Control
virtual void Color(float r, float g, float b); // Set Color of Component- Multicolored objects, this will be the base or bkg color. Makes alpha 1.0f.
virtual void Color(float r, float g, float b, float a); // Same as above but allows for input of an alpha value.
//Font Control
virtual void FontName(const char* font); // Name of font to use
virtual void FontSize(int pt); // Pt size of font. Or maybe pixel, no idea.
virtual void Text(const char* msg); // Text message to render
//Read
virtual const char* Text(); // Read Text Message
//Interactive Control // These will register call back functions for user events
virtual void OnClick(void (*func)()); // On Single Click
virtual void OnDoubleClick(void (*func)()); // On Double Click
virtual void OnMouseOver(void (*func)()); // On Mouse Over
virtual void OnMouseHover(void (*func)()); // On Mouse Hover
virtual void OnKeyDown(void (*func)()); // On Key Down
virtual void OnKeyUp(void (*func)()); // On Key Up
virtual void OnFocus(void (*func)()); // On Focus
//Other
virtual void Parent(CComponent); // Set Parent
virtual CComponent* Parent(); // Get Parent
};
#endif
最後に、CLabel と CEditBox のエンド ゲーム ヘッダーです。
#ifndef _CLABEL_H_
#define _CLABEL_H_
#include "CTexture.h"
#include "CFont.h"
#include "CControl.h"
class CLabel : public CControl {
private:
const char* vText;
CFont Font;
CTexture Text_Font;
SDL_Surface* Surf_Text;
int X,Y,vWidth,vHeight;
public:
CLabel();
CLabel(const char* text);
virtual void OnRender();
virtual void OnCleanup();
virtual void Text(const char* msg);
virtual const char* Text();
virtual void FontName(const char* fname);
virtual void FontSize(int pt);
virtual void FontColor(float r, float g, float b);
};
#endif
と
#ifndef _CEDITBOX_H_
#define _CEDITBOX_H_
#include "CControl.h"
class CEditBox : public CControl {
protected:
CComponent* Label;
int InputType;
public:
CEditBox();
~CEditBox();
virtual void OnRender();
//virtual void OnCleanup();
virtual void OnLoop();
virtual void Text(const char* msg);
virtual const char* Text();
virtual void FontColor(float r, float g, float b);
virtual void OnClick(void (*func)()); // On Single Click
virtual void OnDoubleClick(void (*func)()); // On Double Click
virtual void OnMouseOver(void (*func)()); // On Mouse Over
virtual void OnMouseHover(void (*func)()); // On Mouse Hover
virtual void OnKeyDown(void (*func)()); // On Key Down
virtual void OnKeyUp(void (*func)()); // On Key Up
virtual void OnFocus(void (*func)()); // On Focus
enum {
ALL = 0, //abcdefghijklmnopqrstuvwxyz (and caps) 1234567890!@#$%^&*()_+-=[]{}<>\/|"';:,.?
ALPHA_NUMERIC, //abcdefghijklmnopqrstuvwxyz (and caps) 1234567890
ALPHA, //abcdefghijklmnopqrstuvwxyz (and caps)
NUMERIC, //1234567890
PASSWORD, //abcdefghijklmnopqrstuvwxyz (and caps) 1234567890!@#$%&. -- Render as *
IP //1234567890 . Maybe fix feild width and force xxx.xxx.xxx.xxx format.
};
};
#endif
[解決済み]
今日、#ifndef #define #endif でラップされていないヘッダーが 1 つ見つかりました。(これはCTexture
で再び呼び出されるものでしたCFont
。とにかく、継承と基本クラスのポインターの使用方法、および派生クラスが互いにどのように機能するかを理解したので、再構築も非常に有益でした。さらに多くのことは言うまでもありません。 :)
派生クラスの相互作用のために取っているルートは、仮想関数を介して派生クラス関数にアクセスできる基本クラス ポインターを使用することです。私は new と delete を使用しています。貢献してくれたみんな、ありがとう!それらはすべて良い答えです。