Mein Problem zu arbeiten, ist, dass ich weiß nicht, wie GetTexture und struct SDL_Rect * rect (public), die Mitglieder der Klasse TextureDer Versuch, mit Klassen (SDL)
innen Hauptklasse privaten Bereich zu beziehen, funktionieren, erklärte ich:
Texture box("textures/box.png",100, 100, 20, 20);
Der folgende Satz wurde im Hauptklasse MainLoop Funktion gesetzt:
SDL_RenderCopy(renderer, box.GetTexture(), NULL, box->rect);
Die Linie Fehler führt:
\Main.cpp|28|error: '((Main*)this)->Main::box' does not have class type|
\Main.cpp|28|error: invalid use of member function (did you forget the '()' ?)|
\Main.cpp|28|error: base operand of '->' is not a pointer|
Dies ist Texture.h Code:
#ifndef TEXTURE_H
#define TEXTURE_H
#include <string>
#include <SDL.h>
#include <SDL_image.h>
using namespace std;
class Texture
{
public:
Texture(string path, int x, int y, int w, int h);
virtual ~Texture();
SDL_Texture GetTexture();
SDL_Rect * rect;
protected:
private:
SDL_Texture * texture;
};
#endif // TEXTURE_H
Und Texture.cpp:
#include "Texture.h"
using namespace std;
Texture::Texture(string path, int x, int y, int w, int h)
{
texture = NULL;
texture = IMG_LoadTexture(renderer, path.c_str());
rect.x = x;
rect.y = y;
rect.w = w;
rect.h = h;
}
Texture::~Texture()
{
//dtor
}
SDL_Texture Texture::GetTexture()
{
return texture;
}
ich wenig verwirrt bin, haben wahrscheinlich einfach nicht objektiv Programmierung überhaupt noch verstanden. Danke für Ihre Hilfe.
Es half, Zeiger Fehler behoben. Aber es gibt immer noch ein Problem mit: \ Main.cpp | 28 | Fehler: '((Main *) this) -> Main :: Box' hat keine Klassenart | - es kommt 2 mal vor – Papiero
Oh, Recht, Sie haben Box als eine Funktion erklärt, weil Sie() verwendet haben. Sie sollten es so erklären: Textur-Box; und initialisiere es in cpp-Datei oder in der Kopfzeile mit {}. http://www.stroustrup.com/C++11FAQ.html#uniform-init – Murzinio