Du bist nicht angemeldet.

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

Databyte

Alter Hase

  • »Databyte« ist der Autor dieses Themas

Beiträge: 1 040

Wohnort: Na zu Hause

Beruf: Student (KIT)

  • Private Nachricht senden

1

04.12.2009, 16:26

Problem mit Klasseen-access

Hi

Also ich bin echt am verzeifeln und ich weiß einfach nicht woran das liegt:

Also ich habe folgende KLasse:

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
class CT_API App;
class CT_API Graphics;


class CT_API Core
{
    friend class App;
    friend class Graphcis;
public:
    inline static   App&        GetApp()        { return (*m_AppInstance); }
    inline static   Graphcis&   GetGraphics()   { return (*m_GraphicsInstance); }

    inline static   HMODULE     DllModule()     { return (m_DllModule); }
    inline static   HINSTANCE   PInstance()     { return (m_ProgramInstance); }

    inline static   bool        HasApp()        { return ToBool(m_AppInstance); }
    inline static   bool        HasGraphics()   { return ToBool(m_GraphicsInstance); }

private:
    static App*         m_AppInstance;
    static Graphcis*    m_GraphicsInstance;

    static HMODULE      m_DllModule;
    static HINSTANCE    m_ProgramInstance;
};



So mein Erstes Problem ist, dass bei

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
Graphics::Graphics()
{
    if(Core::HasGraphics())
        CT_EXCEPTION_LOG(ct::exp::AlreadyExistException, "An Instance of Graphics already exists !");
    Core::m_GraphicsInstance = this;   // <- Hier kommt der Fehler

    CT_INFO_LOG("Create Direct3D...");

    m_Direct3D = Direct3DCreate9(D3D_SDK_VERSION);
    CT_CHECK(m_Direct3D, "Can not create Direct3D !", CT_EXCEPTION(exp::Direct3DException)); 
}


Da kommen folgende Fehler:

Zitat

graphics.cpp(16) : error C2248: 'ct::Core::m_GraphicsInstance' : cannot access private member declared in class 'ct::Core'
core.h(29) : see declaration of 'ct::Core::m_GraphicsInstance'
core.h(14) : see declaration of 'ct::Core'
graphics.cpp(16) : error C2440: '=' : cannot convert from 'ct::Graphics *const ' to 'ct::Graphcis *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


Und dann gibt es in der Graphic-klasse eine instance-methode:

C-/C++-Quelltext

1
inline static Graphics& Inst()  { return Core::GetGraphics(); }


Und da kommt jetzt seltsamerweise folgender Fehler:

Zitat

graphics.h(37) : error C2440: 'return' : cannot convert from 'ct::Graphcis' to 'ct::Graphics &'


Das sind alle irgendwie komische Fehler... aber noch lustiger is es, weil die App-klasse genau so programmiert ist und die funktioniert ausnahmslos...

Also ich weiß nicht mehr weiter... vlt habt ihr ja ein paar Ideen ?....

2

04.12.2009, 16:31

Zum ersten Fehler:
Du kannst die Private Member von Core nicht einfach von aussen verändern

Databyte

Alter Hase

  • »Databyte« ist der Autor dieses Themas

Beiträge: 1 040

Wohnort: Na zu Hause

Beruf: Student (KIT)

  • Private Nachricht senden

3

04.12.2009, 16:43

Eigentlich schon, da es eine Friend-klasse ist:

C-/C++-Quelltext

1
friend class Graphcis; 

dot

Supermoderator

Beiträge: 9 757

Wohnort: Graz

  • Private Nachricht senden

4

04.12.2009, 16:48

du hast dich vertippt ;)

5

04.12.2009, 16:50

[OT]Was ist dieses

C-/C++-Quelltext

1
 friend
?[/OT]
Metal ist keine Musik sondern eine Religion.

6

04.12.2009, 16:55

/

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »E333« (02.09.2021, 13:30)


Databyte

Alter Hase

  • »Databyte« ist der Autor dieses Themas

Beiträge: 1 040

Wohnort: Na zu Hause

Beruf: Student (KIT)

  • Private Nachricht senden

7

04.12.2009, 17:57

Omg es handel sich um eine von mir geschickt plazierte Buchstabenvertauschung:

Zitat

Graphics und Graphcis


Was mich da wieder geritten hat ?

Naja es funktioniert.. danke an Mordrak

8

04.12.2009, 18:12

Wieso eigentlich alles statische Member? Wäre nicht sowas wie ein Singleton angebracht?

Databyte

Alter Hase

  • »Databyte« ist der Autor dieses Themas

Beiträge: 1 040

Wohnort: Na zu Hause

Beruf: Student (KIT)

  • Private Nachricht senden

9

04.12.2009, 21:22

Hehe jop. War auch erst so aber da gab es Probleme mit Dll´s und deshalb hab ich mich entschieden das so zu machen, was im Prinzip das gleiche ist :)


PS: Normalerweise müsste ich die Instance direkt in die Klasse mit einbauen... aber ich wollte nicht, dass m_DllModule und m_ProgramInstance sich so einsam fühlen ;) hahaha

xardias

Community-Fossil

Beiträge: 2 731

Wohnort: Santa Clara, CA

Beruf: Software Engineer

  • Private Nachricht senden

10

04.12.2009, 23:42

Zitat von »"Databyte"«


PS: Normalerweise müsste ich die Instance direkt in die Klasse mit einbauen... aber ich wollte nicht, dass m_DllModule und m_ProgramInstance sich so einsam fühlen ;) hahaha

Man sollte nie unterschätzen, dass Variablen auch Gefühle haben die leicht verletzt werden können *g*

Werbeanzeige