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

1

29.05.2010, 21:34

Klasse als Parameter geht nicht

Hi Leute,

also ich habe mir eine eigene Farbklasse geschrieben, aber irgendwie will der Compiler nicht, dass ich die Klasse (die Instanzen :P) als Parameter
mache.

C-/C++-Quelltext

1
2
1>c:\c++projekte\batzer2d\batzer2d\graphics.hpp(42): error C4430: Fehlender Typspezifizierer - int wird angenommen. Hinweis: "default-int" wird von C++ nicht unterstützt.
1>c:\c++projekte\batzer2d\batzer2d\graphics.hpp(42): error C2143: Syntaxfehler: Es fehlt ',' vor '&'


Sorry das ich jetzt den Code hier so blöd hin poste, weiß aber net wie ich das eingrenzen soll.

Color.hpp:

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
#pragma once

#include"Batzer2D.hpp"

namespace b2d
{
    class DLL Color
    {
        public:
            //colorvalues red, green, blue, alpha
            BYTE r, g, b, a;

            //std ctor
            Color() : r(255), g(255), b(255), a(255) {}

            //assume colorvalues from another Color-object
            Color(const Color& c) : r(c.r), g(c.g), b(c.b), a(c.a) {}

            //set red, green, blue to the same value; alpha = 255
            Color(const BYTE c) : r(c), g(c), b(c), a(255) {}

            //set red, green, blue saparatly; alpha = 255
            Color(const BYTE r, const BYTE g, const BYTE b) : r(r), g(g), b(b), a(255) {}

            //set red, green, blue, alpha saparatly
            Color(const BYTE r, const BYTE g, const BYTE b, const BYTE a) : r(r), g(g), b(b), a(a) {}

            //casting operators
            operator DWORD () const
            {
                return (static_cast<DWORD>(r) | static_cast<DWORD>(g) | static_cast<DWORD>(b) | static_cast<DWORD>(a));
            }

            //allocation operators
            Color& operator =  (const Color& c) { r  = c.r; g  = c.g; b  = c.b; a  = c.a; return(*this); }
            Color& operator += (const Color& c) { r += c.r; g += c.g; b += c.b; a += c.a; return(*this); }
            Color& operator -= (const Color& c) { r -= c.r; g -= c.g; b -= c.b; a -= c.a; return(*this); }
            Color& operator *= (const Color& c) { r *= c.r; g *= c.g; b *= c.b; a *= c.a; return(*this); }
            Color& operator /= (const Color& c) { r /= c.r; g /= c.g; b /= c.b; a /= c.a; return(*this); }

            //comparision operator
            bool operator   == (const Color& c) const { return(r == c.r && g == c.g && b == c.b && c.a == a); }
            bool operator   != (const Color& c) const { return(r != c.r || g != c.g || b != c.b || c.a != a); }
            
            //predefined colors
            static const Color Black;
            static const Color White;
            static const Color Red;
            static const Color Blue;
            static const Color Green;
            static const Color Yellow;
            static const Color Magenta;
            static const Color Cyan;
    };

    //arithmetic operators
    inline Color operator + (const Color& c1, const Color& c2) { return( Color(c1.r+c2.r, c1.g+c2.g, c1.b+c2.b, c1.a+c2.a) ); }
    inline Color operator - (const Color& c1, const Color& c2) { return( Color(c1.r-c2.r, c1.g-c2.g, c1.b-c2.b, c1.a-c2.a) ); }
    inline Color operator * (const Color& c1, const Color& c2) { return( Color(c1.r*c2.r, c1.g*c2.g, c1.b*c2.b, c1.a*c2.a) ); }
    inline Color operator / (const Color& c1, const Color& c2) { return( Color(c1.r/c2.r, c1.g/c2.g, c1.b/c2.b, c1.a/c2.a) ); }
}


Color.cpp:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
#include"Color.hpp"

namespace b2d
{
    const Color Color::Black(0, 0, 0);
    const Color Color::White(255, 255, 255);
    const Color Color::Red(255, 0, 0);
    const Color Color::Blue(0, 0, 255);
    const Color Color::Green(0, 255, 0);
    const Color Color::Yellow(255, 255, 0);
    const Color Color::Magenta(255, 0, 255);
    const Color Color::Cyan(0, 255, 255);
}


und wenn ich jetzt schreib:

C-/C++-Quelltext

1
void DrawColor( const Color& color )

dann gibt der die Meldung von sich :(

hab echt alles versucht, aber irgendwie will der nicht so richtig :cursing:

2

29.05.2010, 21:42

Hast die Color.hpp nicht included?

Der Fehler lässt darauf zurückschließen, dass Color zu dem Zeitpunkt noch nicht deklariert ist.

3

29.05.2010, 21:57

Ich habe die Color.hpp included, das ist ja das seltsame :(

4

29.05.2010, 22:09

Wie sieht denn die Graphics.hpp aus in der der Fehler kommt?

dot

Supermoderator

Beiträge: 9 757

Wohnort: Graz

  • Private Nachricht senden

5

29.05.2010, 22:29

Ich habe die Color.hpp included, das ist ja das seltsame :(

Bist du dir da sicher? Kann es nicht sein dass du irgendwo ein zyklisches include hast das durch das #pragma once abgebrochen wird und dazu führt dass der Header doch nicht included wird?

6

29.05.2010, 22:37

so sieht Batzer2D.hpp aus:

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
#pragma once

#define _CRT_SECURE_NO_DEPRECATE
#pragma warning(disable:4995 4996 4251)

#ifdef BATZER2D_EXPORTS
#define DLL __declspec(dllexport)
#else
#define DLL __declspec(dllimport)
#endif

#include<Windows.h>
#include<string>
#include<list>
#include<vector>
#include<cmath>
#include"Color.hpp"
#include"Graphics.hpp"
#include"Logfile.hpp"
#include"Timer.hpp"
#include"Utils.hpp"
#include"Vector2.hpp"


diese Datei wird überall includiert(wegen dem export/import),
da wird Color.hpp auch includiert wie auch in Graphics.hpp:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
#pragma once

#include<d3d9.h>
#include<d3dx9.h>
#include"Batzer2D.hpp"
#include"Color.hpp"
#include"Logfile.hpp"
#include"Vector2.hpp"
#include"Utils.hpp"

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
//mehr code

7

29.05.2010, 23:15

Da haben wir den Fehler doch. Wie dot sagte. ;)

Als kleiner Tip:
Möglichst wenig inkludieren. Gibt genug Anwendungsfälle für Forward declaration.
Zyklen unbedingt und überhaupt und sowieso vermeiden.

Werbeanzeige