Dynamic Arrays Problem

Started by
13 comments, last by vcGamer 21 years, 6 months ago
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?
Visit galaxyroad.com which soon will have english contents too
Advertisement
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=...


why does nobody use malloc and free?
http://www.8ung.at/basiror/theironcross.html
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
well i am used to malloc and free and i prefer to do it that way
http://www.8ung.at/basiror/theironcross.html
quote:well i am used to malloc and free and i prefer to do it that way
So 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);  

i am used to it thats all
http://www.8ung.at/basiror/theironcross.html
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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
i didn t advice anybody i just asked why nobody uses it
thats all

http://www.8ung.at/basiror/theironcross.html

This topic is closed to new replies.

Advertisement