c++

Grouping Controls

I'm using C++ Builder 5. Is there a way to group a disparate set of controls so that by simply calling, for instance, myGroup.Enabled = false; will set all group of controls enabled property to false? I can't use a GroupBox since the controls (labels, checkboxes, etc) are on different TabPages. The reason I ask is so I don't have to cal...

typeid and typeof in C++

I just wonder what's the difference between typeid and typeof in C++? typeid is defined in standard C++ Library Header File typeinfo. typeof is defined in the GCC extension for C or in C++ Boost library. update: Thank you! my following test code for typeid does not output the correct type name. what's wrong? //main.cpp #inclu...

Continue C++ project in VB.Net?

I was given a half-finished project to finish. It was written in C++ using Visual Studio 2005. Is it possible to somehow continue the project in VB.Net? If it is, can you guide me? Thanks ...

Why is it important for C / C++ Code to be compilable on different compilers?

I'm interested in different aspects of portability (as you can see when browsing my other questions), so I read a lot about it. Quite often, I read/hear that Code should be written in a way that makes it compilable on different compilers. Without any real life experience with gcc / g++, it seems to me that it supports every major platf...

C++ length of file and vectors

Hi I have a file with some text in it. Is there some easy way to get the number of lines in the file without traversing through the file? I also need to put the lines of the file into a vector. I am new to C++ but I think vector is like ArrayList in java so I wanted to use a vector and insert things into it. So how would I do it? Thank...

Why don't we have <cstdfloat> in C++ ?

Why doesn't C++ have <cstdfloat> header for floats like it has <cstdint> for integers? EDIT : By <cstdfloat> I mean header that provides typedefs for float and double. Much like qreal typedef in Qt. Hope my question is clear now. ...

Does "&s[0]" point to contiguous characters in a std::string?

I'm doing some maintenance work and ran across something like the following: std::string s; s.resize( strLength ); // strLength is a size_t with the length of a C string in it. memcpy( &s[0], str, strLength ); I know using &s[0] would be safe if it was a std::vector, but is this a safe use of std::string? ...

static initialization in c

I have a function which is passed a list of ints, until one value is "-1" and calculates the minimum. If the function gets called couple times, it is supposed to return the minimum between all calls. So I wrote something like that: int min_call(int num, ...) { va_list argptr; int number; va_start(argptr, num); //stat...

Game Engine Development

Is there any reading material you would recommend on the subject of game engine development? Specifically 2D engines. I've read up on SDL and I want to get started programming some games but I find myself a bit overwhelmed by the whole thing and I don't have a clear picture of what needs to be done. I just end up building complex, ineff...

Native C++ and C# interop

So I'm architecting an application that does necessarily C++ work, but MFC/ATL is too messy for my liking, so I had this brilliant idea of doing all the "thinking" code in native C++ and all the pretty UI code in C#. The problem, though, is interoperability between the two of them. Before I get too carried away with this, I was wondering...

Get type of variable

If I understand correctly, typeid can determine the actual type in polymorphism, while typeof cannot. Is it also true that their returns are used for different purposes: the return of typeof is used as type keyword that can define variable, but the return of typeid cannot? Is there any way to both get the actual type for polymorphism a...

Inclusion of unused symbols in object files by compiler in C vs C++

This might be a dumb question, but maybe someone can provide some insight. I have some global variables defined in a header file (yes yes I know that's bad, but this is just a hypothetical situation). I include this header file in two source files, which are then compiled into two object files. The global symbols are not referenced anyw...

Why is being explicit in C++ required?

In C++, you have to be explicit about many things, like using delete. This gives the programmer more options, but, it doesn't always make sense to me. For example: initializing an array of characters in the constructor. Why aren't simple tasks like these can be handled easier than this way: class x{ enum {Lim =20}; char a[Lim]; x(co...

Cannot marshal a struct that contains a union

I have a C++ struct that looks like this: struct unmanagedstruct { int flags; union { int offset[6]; struct { float pos[3]; float q[4]; } posedesc; } u; }; And I'm trying to Marshal it like so in C#: [StructLayout(Layou...

Pure virtual method called

I understand why calling a virtual function from a constructor is bad, but I'm not sure why defining a destructor would result in a "pure virtual method called" exception. The code uses const values to reduce the use of dynamic allocation - possibly also the culprit. #include <iostream> using namespace std; class ActionBase { public:...

C++0x static initializations and thread safety

I know that as of the C++03 standard, function-scope static initializations are not guaranteed to be thread safe: void moo() { static std::string cat("argent"); // not thread safe ... } With the C++0x standard finally providing standard thread support, are function-scope static initializations required to be thread safe? ...

boost::mpl for_each with normal 'C' Array.

Using boost::mpl, I can create a typedef of a three element vector like follows: typedef boost::mpl::vector_c<int,1,2,3> height_t; I can pull the values out of this typedef with the following snippit: std::vector<int> height; boost::mpl::for_each<height_t>(boost::bind(&std::vector<int>::push_back, &height, _1)); assert(height[0] ...

Why OpenCV's `cvCreateCameraCapture` and `cvCreateFileCapture` do not work? How can I fix it?

Have an AVI videofile, and a webcam. cvQueryFrame returns null in both cases. Code is applied(only for cam): #include "highgui.h" #include <iostream> using namespace std; int main( int argc, char** argv ) { cvNamedWindow( "KillCam", CV_WINDOW_AUTOSIZE ); cvWaitKey(0); CvCapture* capture = cvCreateCameraCapture(-1); ...

Which is more efficient: Bit, byte or int?

Let's say that you were to have a structure similar to the following: struct Person { int gender; // betwwen 0-1 int age; // between 0-200 int birthmonth; // between 0-11 int birthday; // between 1-31 int birthdayofweek; // between 0-6 } In terms of performance, which would be the best data ...

ACE_Mutex::acquire problem

Hi, I have a mutex in my class with the following definition: ACE_Mutex m_specsMutex; When i use the acquire() method that takes no parameters everything works just fine. But when i use it with a time value (as follows) it just immediately returns with -1 value. I'm sure that this mutex hasn't been acquired anywhere else so it should...