c++

May a pointer ever point to a cpu register?

I'm wondering if a pointer may point to a cpu register since in the case it may not, using reference instead of pointer where possible would give compiler opportunity to do some optimizations because the referenced object may reside in some register but an object pointed to by a pointer may not. ...

calling boost::undirected_dfs from a constant context

I have a class that contains a BGL graph. I'd like to traverse the graph in a constant context. For example, I might want an accessor function to report if the graph is cyclic. As soon as I make my dfs function const the code won't compile. Here's a minimal example: #include <boost/graph/adjacency_list.hpp> #include <boost/graph/undir...

Can I remove items from a ComboBox without changing the index of other items?

I have a CComboBox control with several items and I need to remove some of them, but the indexes of the remaining items should be preserved. When the combo box is populated, the item data is set like so: index = mycombo.AddString(temp); mycombo.SetItemData(index, static_cast<DWORD>(count)); where count is a loop counter, and should b...

Using templates for 2D/3D point

Is it worth to write classes representing 1D, 2D, 3D points using templates template <class T> class Point2D { protected: T X, Y; public: Point2D(const T x, const T y) : hot smileyx), Y(y)) {} ... }; template <class T> class Point3D : public Point2D<T> { protected: T Z; public: Point3D(const T x, const T ...

How many threads can I spawn using boost in c++?

And what happens when I try to spawn too many? I'm getting the following error when I spawn more than about 900 threads: terminate called after throwing an instance of 'dining 1 boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::thread_resource_error> >dining 3 ' dining 2 what(): dining 4 boost:...

when i need pass by pointer (and not by reference)

Can you give me an example when I can't pass argument by reference and I need to use pointer. I've found an example, but I'm not sure. Suppose you have a class D derived from the base class B. You need pointer if you want do so: void function(B* b){...} int main{ D* d; function(d); } ...

How to create sound from an array of double and play it on speaker.

I have an array of double (size more than 60k entries), I have the frequency value. Now I want to create a sound from it using C/C++ which I can play on speaker. My OS is linux. Thanks. I hope I am clear enough. ...

Optimizing g++ when indexing an array with an injective function

I have a for loop where each step i, it processes an array element p[f(i)], where f(i) is an injective (one-to-one) map from 1...n to 1...m (m > n). So there is no data coupling in the loop and all compiler optimization techniques such as pipelining can be used. But how can I inform g++ of the injectivity of f(i)? Or do I even need to (c...

Does it make a difference if I make an enum in a class static?

Basically, if I don't do all objects get a copy of all the enum values? ps: as always, references for your answer are always welcome... ...

NetBeans 6.8 marks keywords as fault

Hey, I have just installed NetBeans 6.8. on Ubuntu 10.04 and it marks c++ keywords such as "using" or "namespace" as a fault. I checked that it compiles with g++ and I found an answer to that already here, but there it was a bug in Netbeans which had been fixed via updates within a few days. When I try to update, it tells me, I have the...

Rationale of enforcing some operators to be members

There are 4 operators in C++ which can be overloaded but cannot be overloaded as freestanding (aka nonmember, standalone) functions. These operators are: operator = operator () operator -> operator [] This thread explains perfectly well the rationale of prohibiting operator = to be a member function. Any ideas about the 3 others? TI...

invalid conversion from ‘char*’ to ‘char’ in C++

My code, when compiled, returns the error invalid conversion from ‘char*’ to ‘char’, and identifies the second last line, return char32 as the problem. I've searched internet and this site and haven't found anything that has helped. I've found the error goes away and the code compiles if I replace the problem line with return *char32, bu...

Debugging ncurses with Eclipse CDT

I'm writing a C++ application using ncurses in Eclipse CDT however I can't run/debug my app in eclipse because the console in eclipse does not work with curses. My app runs fine if I run it from a terminal but I just added some new code and now I'm getting a segmentation fault so I'd like to use the debugger in eclipse to help me fix the...

Serializing C-style structs (using C++)

Is it evil to serialize struct objects using memcpy? In one of my projects I am doing the following: I memcpy a struct object, base64 encode it, and write it to file. I do the inverse when parsing the data. It seems to work OK, but in certain situations (for example when using the WINDOWPLACEMENT for the HWND of Windows Media Player) i...

Detailed difference between functor's call and function call ?

The key reason this works is that for_each () doesn’t actually assume its third argument to be a function. It simply assumes that its third argument is something that can be called with an appropriate argument. A suitably defined object serves as well as – and often better than – a function. For example, it is easier to ...

xml to c++: handling escape characters <=

Hi All, I am using xsl to convert data from xml into C++ code. I am running into problems when I have <= or >= in the xml file that needs to be converted to C++ code. For example if I have (in .xml file) <Check>max(x,y) <= 20 </Check> and the .xsl file is if(<xsl:value-of select="Check"/>") { ... } But this does not compil...

CUDA counting, reduction and thread warps

I'm trying to create a cuda program that counts the number of true values (defined by non-zero values) in a long vector through a reduction algorithm. I'm getting funny results. I get either 0 or (ceil(N/threadsPerBlock)*threadsPerBlock), neither is correct. __global__ void count_reduce_logical(int * l, int * cntl, int N){ // sum...

nonrecursive mergesort in C++

I wrote the entire thing, but i get vague errors. I don't know what's wrong....ugh.Also, you may ask why non-recursive well my teacher has it that way for the test. void nonrec_mergesort(vector <int> & a, vector <int> & b, int s, int r) { int m = 1; while (m <= r) { int i = 0; while(s < (r-m)) { ...

What's the correct way to use const in C++?

const correctness has me somewhat confused. What rule of thumb do you use to decide when something should be const or not? e.g. consider this example class MyClass { string ToString(); // this one? const string& ToString(); // or this? const string& ToString() const; // or this? char* ToString(); // What about this? const ...

2d Framework c++

I'm looking for a 2d framework with such things as layers/particles/screen manager/sprite batch/parallax/etc coded in c++ out there? I'm looking for somethings that doesn't necessarily have graphics, because I want to add it on to airplay sdk. Or something I can easily rewire to do the graphics through airplay. ...