class Image : public Media {
/*Variaveis*/
private:
//Posicao da imagem presente na original
int* initPosition;
//Tamanho da imagem presente na original
int* initSize;
//Posicao da imagem presente na janela
int* destPosition;
//Tamanho da imagem presente na janela
int* destSize;
/*Metodos*/
public:
//Construtor
Image(string path, int* initPosition, int* initSize, int* destPosition, int* destSize);
//Obter posicao da imagem presente na original
int* getInitPosition();
//Obter tamanho da imagem presente na original
int* getInitSize();
//Obter posicao da imagem presente na janela
int* getDestPosition();
//Obter tamanho da imagem presente na janela
int* getDestSize();
};
For Media.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
class Media {
/*Variaveis*/
private:
//Caminho para encontrar o ficheiro de multimedia
string path;
/*Metodos*/
public:
//Construtor
Media(string path);
//Obter path do GUI
string getPath();
};
#endif
You probably need the default, no argument constructor because you're using an instance of Image in your HUD class. But without seeing the HUD constructor this is only a guess. Remember whenever you define a constructor for a class the compiler will no longer supply the default no argument constructor.
Image backgroundImg; Is created using constructor... which? Unless you initialise it in membr initialisation list, it created using default constructor.
You need to use an initialization list instead of initializing it in the constructor body and you need to pass the correct number of variables to match one of the constructors you have defined. Since you have pointers in your class you need to also define the destructor and the copy constructor and assignment operator=. Why the pointers by the way?
My HUD.cpp is something like this:
What we really need to see is the complete Image class definition and implementation.
I'm gonna be honest with you, i'm more like a java/c# programmer, so this is getting me a bit confused. What is an initialization list? I check some examples over the Internet, and i thought this was my best bet. Sorry.
Also using assignment for those variables is probably not a good idea, it is possible that the original variables could have a shorter lifespan than this class. If those variables go out of scope before the class the class variables will be referencing memory that is no longer valid.
IMO returning pointers from classes should also be avoided, except in certain circumstances, unless those return values are const qualified.
#ifndef Image_H
#define Image_H
#include "Media.h"
class Image : public Media {
/*Variaveis*/
private:
//Posicao da imagem presente na original
int* initPosition;
//Tamanho da imagem presente na original
int* initSize;
//Posicao da imagem presente na janela
int* destPosition;
//Tamanho da imagem presente na janela
int* destSize;
/*Metodos*/
public:
//Construtor
Image(string path, int* initPosition, int* initSize, int* destPosition, int* destSize) : Media(path) {
this->initPosition = initPosition;
this->initSize = initSize;
this->destPosition = destPosition;
this->destSize = destSize;
};
//Obter posicao da imagem presente na original
int* getInitPosition();
//Obter tamanho da imagem presente na original
int* getInitSize();
//Obter posicao da imagem presente na janela
int* getDestPosition();
//Obter tamanho da imagem presente na janela
int* getDestSize();
};
#endif
jlb, thanks for your cooperation, and i don't want to sound like a jerk, but I can't understand what I am doing wrong and what i suppose to do to make it right. So could you give me some examples or some links to help me understand?