c++

Global multidimensional array not being written to [vs c++]

I have a global multidimensional array, g_iAllData[MAX_LEN][MAX_WIDTH] being used in a Form. When I write to it in a function: g_iAllData[iRow][iColumn]= iByte_Count; I can see in a Watch Window that it's contents are not being changed. If I put the array in the function, it works fine. Is there something I'm missing? I am declaring ...

Why does istream_iterator<unsigned char, unsigned char> throw std::bad_cast?

What is going on? #include <iostream> #include <iterator> #include <sstream> int main() { std::basic_stringbuf<unsigned char> buf; std::basic_istream<unsigned char> stream(&buf); // the next line throws std::bad_cast on g++ 4.4 std::istream_iterator<unsigned char, unsigned char> it(stream); } I've tried stream.write(s...

Is this a safe way to implement a generic operator== and operator<?

After seeing this question, my first thought was that it'd be trivial to define generic equivalence and relational operators: #include <cstring> template<class T> bool operator==(const T& a, const T& b) { return std::memcmp(&a, &b, sizeof(T)) == 0; } template<class T> bool operator<(const T& a, const T& b) { return std::mem...

How to clean up a bad OpenSSL connection

If a call to SSL_accept fails, I want to just bail out. Currently I'm calling SSL_shutdown and then SSL_free, but since implementing this, two customers have had crashes deep down in OpenSSL (when calling SSL_accept at a later time), so I'm guessing maybe this isn't the best way to clean up. The docs say SSL_shutdown is used to correct...

Enforce third party methods virtuality

I'm extending a class provided by a third part library. The class, let's call it Foo, has a reset() method which can be called in order to restart Foo's behavior. The reset() method is also used internally by the class. class Foo { public: void reset () { /* ... */ } void something () { reset(); } }; ...

data structure - running time

Just a confusion.... A portion of a C++ sample code is as follows I just re-edit the whole post. Sorry for any confusion int i, j; i = 0; // c1 j = 0; // c2 while (i < n) // (n+1)c3 { i++; // n c4 while ( j < i) // (2+3+....+n+(n+1)c5 { j++; // (1+2+...+n)c6 } j = 0; // c7 } Clearly, c1, c2, and c...

Interleaving/deinterleaving 3 vectors in C++ STL

I'm trying to combine three signal waveforms into a single, interleaved waveform. I need to know the best way to do it in C++ STL. Better solutions would use as much C++ STL style as possible, avoid redundant code, etc. Is there some STL "tuple" type class that would do this for me? I need contiguous storage at all times for backward com...

bitset for more than 32 bits?

I need to use bit flags with more than 32 bits (33 to be exact right now). I tried and find std::bitset doesn't handle more than 32 bits (ulong). Do I have to use vector or there's a way to make bitset to work? I am limited to c++98 in this project so I can't use boost. Thanks. Edit: I'd like to do something like this: const uint64 ...

Adding vectors of doubles of differing sizes in C++

Hi, I have a number of vector containers of varying size each containing doubles. I would like to add the elements of each vector to create a single vector of doubles. This simple example will example what I'm talking about: Consider two vectors A with three elements 3.0 2.0 1.0 and B with two elements 2.0 1.0. I would like to ad...

Why does MAKEINTRESOURCE() work?

Hi, The macro is defined as: #define MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(i)))) #define MAKEINTRESOURCEW(i) ((LPWSTR)((ULONG_PTR)((WORD)(i)))) How come this can be used to indicate either a resource ID (a 16-bit unsigned int) or its name (a pointer to an array of char)? Doesn't this effectively limit the address space (on ...

How reliable are basic_stringbuf::in_avail() and basic_stringbuf::str()?

Hi, I need to get all the contents from a stream, without actually extracting them (just like stringstream::str()). I've tried basic_stringbuf::str(), but it behaves incorrectly when the stream is empty. To avoid that case, I had a go at basic_stringbuf::in_avail(), but that hasn't worked out very well either. In the following test ca...

Help using MFC CMap (or std::map) please.

Hi, a C++ noob here. I am trying to tweak some code, with the following key lines (meaning they are not the only ones, but they are the only ones that should matter for this question). By the way, I am using Visual Studio 2010 C++ compiler on Windows. CMap<ATL::CAtlString,LPCTSTR,UINT,UINT> mapForDuplicates; // "dict" definition ATL::CA...

Cairo error message on exit

I'm currently doing some tests using Cairo to replace some existing GDI/GDI+ code in Visual C++ 2010 and it seems to be working fine, but I'm getting an error message each time I close down my application : "First-chance exception at 0x68e629dc in CairoTest.exe: 0xC0000005: Access violation reading location 0xabababa7" This error only ...

Can two applications communicate by UDP packets?

I'm looking for a way to ease the difficulty transferring data from one application/process to another, but should have some sort of error recovering capbility. As UDP is an existing protocol that works well over network, I wonder if it can also be used by processes in the same OS(windows xp here) . If yes can you provide some core cod...

Freeing static memory? no, that can't be right

I've been playing around with embedding resources into my c++ program. In order to do this I hexdump the data to a simple array, i.e. unsigned char image_png[] ={ 0x0a, 0x0b, 0x0c, 0x0d, ... }; Some of these resources are not used after loading (i.e. they get converted to something else and then the original data is just bulk... t...

Iterating C++ vector

Is it possible to iterate a vector from the end to the begin? for (vector<my_class>::iterator i = my_vector.end(); i != my_vector.begin(); /* ?! */ ) { } Or is that only possible with something like that: for (int i = my_vector.size() - 1; i >= 0; --i) { } ...

Why is this allowed in C++?

#include<iostream> using namespace std; class base { public: virtual void add() { cout << "hi"; } }; class derived : public base { private: void add() { cout << "bye"; } public: void start() { cout << "start"; } }; int main() { base *ptr; ptr = new derived; ptr->add(); r...

How to write a C or C++ program to act as a memory and CPU cycle filler?

I want to test a program's memory management capabilities, for example (say, program name is director) What happens if some other processes take up too much memory, and there is too less memory for director to run? How does director behave? What happens if too many of the CPU cycles are used by some other program while director is runn...

Correlation between specifier and qualifier?

const and volatile are called cv-qualifier by the C spec. What is exactly defference between specifier and qualifier (cv-qualifier)? Does a qualifier is a specifier as well? Is it necessarry that qualifier is with an lvalue only? What are qualifiers other than cv-qualifier? Does above understanding makes any sense? ...

InternetOpenUrl intermittently times out

I have some InternetOpenUrl requests that are strangely timing out. The endpoint is there and the URL is correct. This happens in a synchronous loop inside an activex control, and about the 6th time it executes, it times out without hitting the server. HINTERNET hINet = InternetOpen(TEXT("InetURL/1.0"), INTERNET_OPEN_TYPE_PRECONFIG, NUL...