c++

C++ Problem with explicit template instantiation of an operator

Hi, I have a template class that I m trying to explicitly instantiate: template<T> struct tmat2x3 { ... typedef tvec3<T> col_type; .. }; the operator is declared as follows: template <typename T> typename tmat2x3<T>::row_type operator* (tmat2x4<T> const & m, typename tmat2x3<T>::col_type const & v); I am explicitly instantiating t...

How to store OpenGL Primitives in a tree data structure in C++ ?

I'm new to OpenGL and C++. Say I start with a 2D square (on the very left) like shown in the picture below. I want to make it interactive with the glutKeyboardFunc() so when I press a number a new box will draw next to the corresponding edge. Figure the best way to do this is to have a tree structure that hold all the boxes. But I'm n...

Why does this divide-by-zero error only occur in optimized code?

I just found a bug that, strangely, occurred only when optimization was turned on (g++ -O2). It was an Arithmetic exception in the following code, when interval was set to zero (from a command line argument): for(int i = 0; i < n; ++i) { if((i + 1) % interval == 0) { // exception here DoSomething(); } } It's obvious that modul...

Problem with linking, c++ member function to C callback

I'm trying to interface a c++ member function with a legacy C library taking a function pointer - I can't see why this keeps coming up with link errors, Can anyone see why ? link errors /tmp/ccl2HY1E.o: In function `VerifyWrapper::verifyGlue(int)': callback.cpp:(.text._ZN13VerifyWrapper10verifyGlueEi[VerifyWrapper::verifyGlue(int)]+0xe...

Passing Pointer of vector of pointers... no no?

New to C++ and its giving me a hissy fit. The actual code is on a different computer and I can't copy it, so I'll do the best I can with pseudo code. My endgame is to have a vector [of pointers] that can be accessed by several different objects. The way I attempted to go about this is have the original class that contains the vector to...

C++: Why does my binary search function run into an infinite loop?

I am having a bit of trouble with creating a Binary Search using a templated dynamic array class and iterators. In my class I have the following function that causes an infinite loop. iterator binarySearch(const T& value) { T * indexOfFirst = begin(); T * indexOfLast = (end() - 1); size_t tempSize = m_size; while (ind...

Unsequenced value computations (a.k.a sequence points)

Sorry for opening this topic again, but thinking about this topic itself has started giving me an Undefined Behavior. Want to move into the zone of well-defined behavior. Given int i = 0; int v[10]; i = ++i; //Expr1 i = i++; //Expr2 ++ ++i; //Expr3 i = v[i++]; //Expr4 I think of the above expressions (in that order) as ...

Why ++ operator not incrementing in case of operator overloading in c++?

Possible Duplicate: Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc) Class test { public: int a=10; void operator ++(int) { a=a++; cout<<a; } }; after calling the function in main a displays same value? if i put only a++ in ++ function then its works or a=a++ is workin...

how to compare two endpoint address with C++ in windows:

bool checkSockaddr(sockaddr_in a, sockaddr_in b) check if they two have the same address information. ...

Ideas on implementing graph in C++

I need help to design the best data structure for a GRAPH. The following is my implementation. Please give your thoughts on this design. #ifndef _GRAPH_H_ #define _GRAPH_H_ #include <map> #include <vector> #include <iostream> #include <list> template <typename T> class Vertex { public: Vertex(){}; Vertex(T inVertex): m_ver...

Why I can apply array subscript access syntax on non array

Possible Duplicate: In C arrays why is this true? a[5] == 5[a] Consider the following code able to compile under VC2008. int i = 0; int *j = 0; int k = 0; i[j]; // OK?!?! i[k]; // Compile Error. I was wondering, what is the meaning of i[j] in this content? ...

Any reason to prefer memset/ZeroMemory to value initialization for WinAPI structs?

In Win32 programming a handful of POD structs is used. Those structs often need to be zeroed out before usage. This can be done by calling memset()/ZeroMemory() STRUCT theStruct; ZeroMemory( &theStruct, sizeof( theStruct ) ); or by value initialization: STRUCT theStruct = {}; Although the two variants above are not equivalent in g...

STL in embedded enviornment

I am a C++ programmer and over the years have been subjected to hearing the notion that STL is not good for use in embedded enviornments and hence usually prohibited in usage for embedded enviornment based projects.I believe STL libraries like Boost are far more powerful and provide a much more faster & less error prone means of developm...

How to open a file which is already open in exclusive mode?

Hi, I want to access a file which is already opened with exclusive access by some other process (not under my control). I know that the I/O manager will not grant my request, as some other process is holding the lock (with exclusive access). Is there any way by which I can bypass the checks (such as file opened in exclusive mode) made ...

Flash crashes when stopping directshow source filter

Here's the callstack : 0480b000() vcam.ax!CSourceStream::DoBufferProcessingLoop() + 0xe1 bytes vcam.ax!CSourceStream::ThreadProc() + 0x13e bytes vcam.ax!CAMThread::InitialThreadProc() + 0x51 bytes kernel32.dll!7c80b713() The callstack is from this thread: 0 > 0x000015b8 Worker Thread CAMT...

A ThreadPool library in C++

I am looking for a good and stable threadpool library for C++ that's fairly well documented. I know about the Native Windows thread pool API and the newer Vista Thread Pool API, however my program requires some backward compatibility, so perhaps an outside library I can provide with the program is better. I have looked into Boost's thr...

Monitor selections in any application

I want to monitor all text selections made in any application by the user. Is that possible? I would prefer a solution in .net, but vanilla C++ is OK. If not, can I monitor all text copy operations (CTRL+C) from a .net application? similar question: http://stackoverflow.com/questions/653003/in-c-is-there-a-way-to-consistently-be-able-...

What Linux IPC to use between a c program and a C++ Qt app?

Hi I have a old school c program that now and then need to tell a C++ Qt based application about some "events" that has occurred on my system. But when I started to work with this problem I noticed that some ipc techniques is quite easy to use in the c program. And then we have some Qt specific styles that works quite well in the "Qt...

What is an opaque value?

What is an "opaque value" in C++? ...

Overloading [] operator

I have overloaded [] operator in my class Interval to return minutes or seconds. But I am not sure how to assign values to minutes or second using [] operator. For example : I can use this statement cout << a[1] << "min and " << a[0] << "sec" << endl; but I want to overload [] operator, so that I can even assign values to minutes or ...