vb style arrays in c++

Started by
20 comments, last by fireking 21 years, 7 months ago
quote:Original post by fireking
there are other memory functions, but i didnt read up on them..

please explain why i should not use them in C++? where is the concern?

It is good practice to advocate the use of C++ features exclusively (at least until you know better) when using a C++ compiler because of better interoperation of the features. The Standard C Library memory management functions do not know about the behaviors of classes (and structs; they''re functionally near-equivalent, only difference is inheritance/access specification), meaning they do not call constructors or destructors and other such nuances. The Standard C++ operators new and delete are not only aware of C++ features, but are user-extensible and fully support all C memory operations. That''s just one of the instances where modern C++ features are to be preferred.

Prefer std::string over null-terminated character strings.
Prefer std::vector over type *, dynamically allocated arrays.

Naturally, there are times when the right-hand constructs are logically equivalent - and occasionally even superior - but they are relatively few.
Advertisement
What you need to realize, fireking, is that VB does a TON of shit for you (meaning you don''t have to worry about it).

About the only thing that c++ does for you is maintain the program stack.

That''s it. Everything else, you''re on your own. That means that you have to explicitly tell your program exactly what you want it to do 99% of the time.

Now, you can simplify that by using C++ features, such as classes, templates, operator overloading, etc.. but the fact remains that you have to explicitly define the behavior somewhere before it can be used.

You''re a lot safer in C++ if you just basically assume that you (the programmer) have to tell the language what to do, throughout the entirety of the program.
daerid@gmail.com

This topic is closed to new replies.

Advertisement