Hi i have next problem with the number line 12 the file: text.hpp
(http://img832.imageshack.us/img832/7138/sinttulo2vg.png) (http://imageshack.us/photo/my-images/832/sinttulo2vg.png/)
Here the code
main.cpp
#include <iostream>
using namespace std;
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "object.hpp"
#include "text.hpp"
int main(int argc,char *argv[]){
// Definition
sf::RenderWindow myWindow(sf::VideoMode(800,400,32),"class Text");
Text *Texto1 = new Text;
Texto1->Display(myWindow);
Texto1->SetText("hola");
cout << "\n# Game Over"<< endl;
myWindow.display();
return 0;
}
object.cpp
#include "object.hpp"
Object::Object(){}
Object::~Object(){}
void Object::Display(sf::RenderWindow &t){
cout << "Invoked class Object"<< endl;
}
object.hpp
#ifndef _objecthpp_
#define _objecthpp_
#include <iostream>
using namespace std;
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
class Object {
public:
Object();
~Object();
virtual void Display(sf::RenderWindow &);
private:
};
#endif
text.hpp
#ifndef _texthpp_
#define _texthpp_
#include <iostream>
using namespace std;
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "object.hpp"
class Text : public Object {
public:
Text();
~Text();
void Display(sf::RenderWindow &);
void SetText(char *);
private:
sf::Text myText;
};
#endif
text.cpp
#include "Text.hpp"
Text::Text(){
}
Text::~Text(){
}
void Text::Display(sf::RenderWindow &t){
cout << "Invoked class Text"<< endl;
}
void Text::SetText(char *t){
myText.setString(sf::String(t));
//cout << "Text: "<< string(myText->getString()) << endl;
}
xploiter, in this case, when will the memory be released.
Never actually, that's why it's called memory leaks. But I guess the development enviroment takes care of that a bit more and releases it anyways which then again is after the opengl context are already destroyed and thus could lead to such problems.
Maybe some help please?
How about this:
int main(){
// Definition
sf::RenderWindow myWindow(sf::VideoMode(800,400,32),"class Text");
Text Texto1;
Texto1.Display(myWindow);
Texto1.SetText("hola");
cout << "\n# Game Over"<< endl;
myWindow.display();
return 0;
}
How about this:
int main(){
// Definition
sf::RenderWindow myWindow(sf::VideoMode(800,400,32),"class Text");
Text Texto1;
Texto1.Display(myWindow);
Texto1.SetText("hola");
cout << "\n# Game Over"<< endl;
myWindow.display();
return 0;
}
Error
I tried that and continues the problems, i want is pointer for the polimorfisms.
Example:
Object *text = new text;
Object *button= new Button;
Does this minimal example also crash?
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Test");
}
i want is pointer for the polimorfisms.
Object *text = new text;
Object *button= new Button;
You have to know C++ is not equal to Java. So whenever you call new you have to call delete! ;)
It's generally not the best design to have one object from which every other class derives. C++ is not a fully object oriented language and one should not try to force such a thing up on it. So one should use polymorphism and other OOP principles only in places where the make sense and are not artificial products.
This also error.
using namespace std;
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
int main(int argc,char *argv[]){
sf::Text t1;
t1.setString("hola");
return 0;
}
sorry i am moron xDD