I have a problem with some code
MyClass.h
MyClass.ccCode:public: //stuff protected: // stuff char * path; //more stuff void function1(); void function2(); };
I need a char * in my function1(). I tried some possibilities, all envolving creating a new class variable (path).Code://stuff void MyClass::function1() { int spinvalue = 50; std::cout << "Parameter 1 = " << spinvalue << std::endl; std::cout << path << std::endl; //stuff } void MyClass::function2() { //stuff path = const_cast<char*> ( dialog.get_filename().c_str() ); std::cout << "pathImagen = " << path << std::endl; //stuff } // more stuff }
I tried for this variable a char * path, char path[] ... and tried to convert the const char * in that, but for most i got a memory crash and for others i was not obtaining the value in function1().
I don't know what is wrong with it, but when i run function2() and function1() in this order i got :
1 pathImagen = /home/myhome/pathToImage/image.jpg
2 Parameter 1 = 50
3 �6� �
The 1, is the cout just after the const_cast<char*>, the 2 is the spinbutton working and the 3 is some random garbage :S
Anyone know what i'm doing wrong or know the way to do what i want? any lead/hint/help will be appreciated.
Thx in advance for all!



LinkBack URL
About LinkBacks




