Dynamic Arrays Problem
Hi, I''ve just finished my engine, but only a little problem is preventing me from owning a completely Object Oriented Engine.
I want to declarer dynamic arrays (which there size is going to filled based on my game meshes), like VB, IB, world matrices...
I''ve a header, a class called:
in the .h file:
PowerXChar
{
LPVertexBuffer8* vb;
}
in the main .cpp engine file:
PowerXChar:owerXChar(.....)
{
LPVertexBuffer8* vb = new LPVertexBuffer8[num_of_meshes_in 3d file];
...
}
PowerXChar::Render{...)
{
Here I again use vb..., but it seems they have lost their values, why?
}
tell me what to do?
In this line here:
LPVertexBuffer8* vb = new LPVertexBuffer8[num_of_meshes_in 3d file];
You''re making a new varible, not changing the vb member of PowerXChar.
Try charging it to :
vb = new LPVertexBuffer8[num_of_meshes_in 3d file];
or this->vb=...
LPVertexBuffer8* vb = new LPVertexBuffer8[num_of_meshes_in 3d file];
You''re making a new varible, not changing the vb member of PowerXChar.
Try charging it to :
vb = new LPVertexBuffer8[num_of_meshes_in 3d file];
or this->vb=...
malloc and free are C
new and delete are C++. new and delete call constructors and destructors of classes. also you don''t need to do any sizeof crap. they''re easier to use in terms of less characters/thinking to type/do.
-me
new and delete are C++. new and delete call constructors and destructors of classes. also you don''t need to do any sizeof crap. they''re easier to use in terms of less characters/thinking to type/do.
-me
quote:well i am used to malloc and free and i prefer to do it that waySo you prefer to write:
MyClass* p = static_cast<MyClass*>(malloc(sizeof(MyClass)));new(static_cast<void*>(p)) MyClass;// use p...p->~MyClass();free(p);
Instead of:
MyClass* p = new MyClass;// use p...delete p;
I don''t think there is any advantage to using malloc/free, unless, of course, you need to do realloc.
Forgot error-checking:
MyClass* p = static_cast<MyClass*>(malloc(sizeof(MyClass)));if(!p) throw bad_alloc;try { new(static_cast<void*>(p)) MyClass;} catch(...) { free(p); throw;}// use p...p->~MyClass();free(p);
quote:Original post by Basiror
why does nobody use malloc and free?
quote:Original post by Basiror
well i am used to malloc and free and i prefer to do it that way
quote:Original post by Basiror
i am used to it thats all
Then you are a C programmer, there is nothing wrong with that, so long as you keep to the C library and don''t ever try to use C++ features.
Pick one language or the other and please, do not advise other people to use a bastard mix of the two (as you seem to do).
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement