c++

C++: Define bitset size at initialization?

I want to make a bitset in C++. I did a bit of research. All examples I found where like this: bitset<6> myBitset; // do something with it But I don't know the size of the bitset when I define the variable in my class: #include <bitset> class Test { public: std::bitset *myBitset; } This won't compile... And initializing like ...

Indexing hash tables

I am just starting to learn hashtables, and so far, I know that you take the object you want to hash and put it through an hash function, then use the index it returns to get the corresponding object you want. There is something I don't understand though: What structure do you use to store the objects in so you can quickly index them wi...

C++ program design question

Hello! In couple of recent projects that I took part in I was almost addicted to the following coding pattern: (I'm not sure if there is a proper name for this, but anyway...) Let's say some object is in some determined state and we wan't to change this state from outside. These changes could mean any behaviour, could invoke any algori...

LNK 2028 - 2019 / Managed and Unmanaged C++ ? (VS 2008)

Hi, I am trying to link an open-source library to one of my project. The library is unmanaged (named Tetgen) and my project is in managed C++. I create a .lib or a .dll, that doesn't change anything. My project recognizes the header and can use the functions defined in it, but cannot access to the cpp. I got a 2028 error each time it wa...

Optimizing C++ code

I'm designing classes for my application (network tool). I this base class: class Descriptor { // ... public: virtual void data_read (void); virtual void data_write (void); virtual void data_error (void); protected: int socket_descriptor; // ... } class TcpClient : public Descri...

Local time with milliseconds

Hello, how can I get current time with library boost. I can do this: ptime now = boost::posix_timesecond_clock::local_time(); tm d_tm = to_tm(now); But the last time unit of tm structure is second and I need in millisecond. Can I get current time with milliseconds? ...

In C++, is it still bad practice to return a vector from a function?

Short version: It's common to return large objects—such as vectors/arrays—in many programming languages. Is this style now acceptable in C++0x if the class has a move constructor, or do C++ programmers consider it weird/ugly/abomination? Long version: In C++0x is this still considered bad form? std::vector<std::string> BuildLargeVector...

How can I map a remote device as an array in C++?

I would like to create a C++ object to wrap the RAM of an external peripheral device. I'm trying to set up something like the following: Peripheral p; p[4] = 10; int n = p[5]; To do this I need to read or write to the peripheral whenever an array element is accessed. I cannot work out how to do this using operator overloading etc. I ...

Ways to Find a Race Condition

I have a bit of code with a race condition in it... I know that it is a race condition because it does not happen consistently, and it seems to happen more often on dual core machines. It never happens when I'm tracing. Although, there is a possibility that it could be a deadlock as well. By analyzing stages of completion of logs where ...

SMTP Authentication QT/C++

I am trying to create a simple send mail function for a custom app created with the Qt framework in C++. I am very close just at the point where SMTP is trying to authenticate and can't for the life of me to get this to work. Here is what I am working with do { responseLine = socket->readLine(); response += responseLine; } while...

sem_t union/struct C++ inherintance

I'm porting some old C++ project on Linux (RHEL 5.3). The situation is the following #include <semaphore.h> class OldClass: public sem_t This used to work because till glibc-2.3.3.20040420 sem_t was a struct. Now, with the newer version of glib is a union =>inheritance not allowed. so the compilation doesn't work. how it was: type...

c++ Difference between two vector<MyType*> A and B

Dear reader, I've got two vector<MyType*> objects called A and B. The MyType class has a field ID and I want to get the MyType* which are in A but not in B. I'm working on a image analysis application and I was hoping to find a fast/optimized solution. Kind regards, Pollux ...

Call C/C++ code form a fortran program in visual studio? (How to compile mixed C and fortran code in visual studio)

Hi every one, i am looking for a way, how i can integrate a c++ code with fortran code (i want simply call some C/C++ functions in the fortran code). I have found some proposals for gcc or console compilers, but i have not any idea how to translate this approach to solve integrationproblem within the visual studio. At the time I am thi...

Having trouble adding a dll to my project in visual C++

So I have gone through this tutorial three times: http://msdn.microsoft.com/en-us/library/1ez7dh12.aspx Every time I get to the end and try to run the program, it says: Error 1 fatal error C1083: Cannot open include file: 'MathFuncsDll.h': No such file or directory Using a .dll was so simple in C#. Could anyone explain to me, assum...

How is a pipe reading with a size of 4 bytes into a 4 byte int returning more data?

Reading from a pipe: unsigned int sample_in = 0; //4 bytes - 32bits, right? unsigned int len = sizeof(sample_in); // = 4 in debugger while (len > 0) { if (0 == ReadFile(hRead, &sample_in, sizeof(sample_in), &bytesRead, ...

Why does this template class in a library generate linker errors when used?

I've got the following setup. RectangleT class defined in a header file in a library. Attempted to use the class in my main application. When linking I get an error for every function I try to call - except constructor and the GetLeft/GetTop/GetRight/GetBottom - BUT - I do get the error when calling GetWidth / GetHeight. Here's the code...

Access own bank account via self-written application

Hi Guys, as I can imagine, this is a quite big topic. Let me explain: I have used MS Money for several years now and due to my "coding interest" it would be great to know where to start learning the basics for programming such an application. Better to say: Its not about how to design and write an application, its about the "bank detail...

Select() + UDP resulting in too many open files

I currently have a select() statement configured to keep track of two UDP sockers. I send perhaps 10 - 20 messages a second at one general data socket, which is this interpreted as I expected. However, once I hit around 1024 messages, I get the notice: talker: socket: Too many open files talker: failed to bind socket This is lo...

pwsz string confusion

Hi, I have never posted before so I am sorry if I am not clear. I am trying to use a third party DLL written in c++ on 2005 and all I have is some very poor documentation. I am dynamically linking to the DLL and using the Ordinal value read from Dependency walker to get a pointer to a method in the DLL. Such as (LPFNDDLLZC) GetProcAddr...

Need help with configuration of codeblocks for Qt !

codeblocks 8.02. , win xp SP2 , Qt 4.6 After installing Qt SDK, I installed QtWorkbench (codeblocks plugin that allows you to create Qt applications.) http://code.google.com/p/qtworkbench/. I worked under instructions from that page. I opened the folder "dialogs" and in it I opened a new empty codeblocks project. Also in this folder "d...