|
Post by counterfeit on Feb 12, 2015 12:13:23 GMT
Hey,
don't know if this is an error, but I find very strange. I work with Visual Studio 2013.
Ness::TextPtr text = scene->create_text("../ness-engine/resources/fonts/courier.ttf", "HelloWorld", 24); Ness::ManagedResources::ManagedFontPtr font("../ness-engine/resources/fonts/courier.ttf");
text->change_font(font); //crash on compile text->change_font(ness_make_ptr<Ness::ManagedResources::ManagedFont>("../ness-engine/resources/fonts/courier.ttf", 12)); //everything alright Error 1 error C2664: 'void std::_Ptr_base<_Ty>::_Reset0(_Ty *,std::_Ref_count_base *)' : cannot convert argument 1 from 'const char *' to 'Ness::ManagedResources::ManagedFont *' c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory 735 1
|
|
|
Post by Admin on Feb 13, 2015 11:44:49 GMT
hello counterfeit, welcome first, the compilation error you get is not on the change_font() line, its on this line: Ness::ManagedResources::ManagedFontPtr font("../ness-engine/resources/fonts/courier.ttf"); and here's the problem: ness-engine uses std::shared_ptr<> (managed pointer that delete the object when no one has reference to it) for all its basic types. which means, Ness::ManagedResources::ManagedFontPtr definition looks like this: std::shared_ptr<ManagedFont>. a shared ptr is a class that wraps the raw pointer, so the constructor must receive a raw pointer as a parameter. so the compilation error you are getting is for trying to send char* ("../ness-engine/resources/fonts/courier.ttf") instead of a ManagedFont* pointer to the shared_ptr constructor. now the macro ness_make_ptr<> is an alias to an std macro make_shared, which is a more efficient way to create a shared_ptr (you can read more here en.cppreference.com/w/cpp/memory/shared_ptr/make_shared ), and also get the original class constructor params. that's why you had no problem compiling it. hope I was clear enough, if not let me know and I'll try to explain further.
|
|
|
Post by counterfeit on Feb 13, 2015 12:18:28 GMT
Ah I see thank you for the good explanation.
|
|