Questions on C++

Started by
10 comments, last by MaulingMonkey 19 years, 6 months ago
C++ is pretty cross platform (except for embedded systems and such), but 3rd party librarys may not be cross platform. So if your concerned about the app running on Windows, Mac, and Linux, you'll need to do some research before you can begin.
Advertisement
edit: unborked

1. If you overload an operator does this work like a function
and creates the variables on the stack ?

Yes, but of course your compiler is allowed to make optimizations.

2. If so can you inline operator overloads ?

Yes, and for trivial operations your compiler will most likely inline them anyways.

3. If not...

Not applicable since #2 is "Yes".

4. I have heard C++ is not portable to another sytem in some
cases were C can be ported. What is the reason for this ?

Well, you should be able to compile a C++ compiler using the C compiler, but some systems only have very broken implementations of C or linking utilities that are very broken, resulting in much pain if you try to get a C++ compiler running. People being lazy, sometimes this means nobody will have done it for you on obscure platforms.

There's also embedded systems, where some of the overhead of C++ is insane for useage with them (example: you can easily add many kilobytes of program .exe size just from using the iostream library)

5. Should I try to avoid polymorphy and function pointers to
avoid a virtual table to make my code faster ?

No. They will make your code somewhat slower, but not any more so than any workarounds to the problem in many circumstances. Also, the slowdown is very minor - you should only go to the effort of avoiding it in a very few cases. Places to avoid virtual or pointers to functions do exist, such as:

The code for a vertex class, if it will be called every frame for every vertex (aka, Vertex.Draw() being overloaded to glVertex3f(...) or the DirectX equivilant).

In my above example, a more appropriate solution would be to make a higher level construct (such as a mesh object) be the point where the virtual function/choice occurs, then have that class contain an array of COpenGL_Vertex or CDirectX_Vertex depending on if the class was an COpenGL_Mesh or CDirectX_Mesh - meaning you get 1 virtual call per mesh per frame instead of per vertex per frame.

6. Once I use a virtual table does it matter to code speed how
many virtual classes I use?

No. Well, okay, technically, yes, since more classes in general means a larger .exe file size, which will slightly increase the load time of your application due to the speed of your hard drive - but nothing more trivial than that.

[Edited by - MaulingMonkey on October 19, 2004 12:18:39 PM]

This topic is closed to new replies.

Advertisement