c++

Conditional typedefs

If I have a little peice o' code as such... template <typename _T> class Foo { public: typedef const T& ParamType; void DoStuff(ParamType thingy); }; This can be non-optimal if sizeof(_T) <= sizeof(_T*). Therefore, I want to have a conditional typedef. If the size of _T is less than or equal to that of a pointer, just pass it...

C++: binary search compile error

Hi: I have the following lines of code: if(std::binary_search(face_verts.begin(), face_verts.end(), left_right_vert[0]) && std::binary_search(face_verts.begin(), face_verts.end(), left_right_vert[1])) And when I compile my code, I get the following errors: In file included from /usr/include/c++/4.4/algorithm:62, ...

TInyOS 1.x Generating an error when compiling BLINK

root@everton-laptop:/opt/tinyos-1.x/apps/Blink# make pc compiling Blink to a pc binary ncc -o build/pc/main.exe -g -O0 -board=micasb -pthread -target=pc -Wall -Wshadow -DDEF_TOS_AM_GROUP=0x7d -Wnesc-all -fnesc-nido-tosnodes=1000 -fnesc-cfile=build/pc/app.c Blink.nc -lm In file included from /opt/tinyos-1.x/tos/platform/pc/packet_...

Can I do pointer arithmetic on an STL::vector::iterator

This seems to me a simple question but I can't find the answer. Currently I use an iterator to search through a vector and test its elements. I access the elements using std::vector<int>::iterator it; if(*it==0); Can I use the same pointer arithmetic style logic to also test the next element (without altering my iterator)? I first n...

Modelling a network with a vector of vectors

I am trying to model a network using C++. I have a struct called NetworkConnection: struct NetworkConnection { int i, j, weight; } and I have a class called Network class Network { public: std::vector<NetworkConnection> connections_for(int i) { return connections[i]; } void connect(int i, int j, int weight) { ...

How to create a radio button and see if it's checked?

How to create a radio button and see if it's checked? Windows Vista Dev-C++ Win32 API WM styles ...

the difference between the program in C++ developed under windows and linux

I would like to know what's the difference between the program developed in C++ under windows and linux. Can anybody tell me why the program developed under Windows in C++ can't be used under linux? ...

How can overloading operator "function call" in C++ be useful?

I recently discovered that in C++ you can overload the "function call" operator, in a strange way in which you have to write two pair of parenthesis to do so: class A { private: int n; public: void operator ()() const; }; And then use it this way: A a; a() ; In what case can this be consider useful ? ...

Why is there no boost::copy_on_write_ptr?

I just saw this nice copy-on-write pointer implementation. It looks pretty generic and useful, so my question is: Is such a class contained in any of the C++ toolkits (boost, loki, etc.)? If not, I'd really like to know why because it is a really useful idiom and apparently a generic implementation seems doable (like the one I linked to)...

Is it worth cutting down a 540 byte class into smaller chunks? (C++)

So I've been developing a UI toolkit for the past year, and my Window class has gotten to a point where the size of the class (through sizeof) is 540 bytes). I was thinking, that since not all windows have children, I might split parts of the code that handles having children (its alignment etc) into a separate class and have a pointer ...

C++ - Verifying correct input type

I've got the following piece of code: ... int x = 0; int y = 0; cin >> x >> y; if (x == -1 && y == -1) { cout << "exit!"; } else { doSomething(); } ... And it works, but only if I enter 2 numbers. If I were to enter a letter, like 'n', the program gets thrown into an infinite loop. How do I check to make sure the user entered ...

Variables after the colon in a constructor

I am still learning C++ and trying to understand it. I was looking through some code and saw: point3(float X, float Y, floatZ) : x(X), y(Y), z(Z) // <----- what is this used for { } What is the meaning of the "x(X), y(Y), z(Z)" sitting beside the constructor's parameters? ...

Template class, function specialization

I want to have a template class that looks something like what I have down below. Then, I want a function in it with a template specialization depending on a CLASS template parameter. How do I make this work? I realize the code I provided is wrong on many levels, but it's just to illustrate the concept. template <typename _T, size_t num...

How do I programmatically send email w/attachment to a known recipient using MAPI in C++? MAPISendMail()

This question is similar, but does not show how to add a recipient. How do I do both? We'd like the widest support possible for as many Windows platforms as possible (from XP and greater) We're using visual studio 2008 Essentially we want to send an email with: pre-filled destination address file attachment subject line from our...

How could I do frequency analysis on a string without using a switch.

I am working a school project to implement a Huffman code on text. The first part of course requires a frequency analysis on the text. Is there a better way aside from a giant switch and an array of counters to do it? ie: int[] counters for(int i = 0; i <inString.length(); i++) { switch(inString[i]) case 'A': counters[0]++; ...

Difference in performance between map and unordered_map in c++

I have a simple requirement, i need a map of type . however i need fastest theoretically possible retrieval time. i used both map and the new proposed unordered_map from tr1 i found that at least while parsing a file and creating the map, by inserting an element at at time. map took only 2 minutes while unordered_map took 5 mins. As...

Various ways to get month name from inbuilt C library

What are the various ways to get the name of the month corresponding to an integer value [say 0 for Jan,1 for February ,...,11 for December] from inbuilt C/C++ library, I am familiar to strftime.Any other means to do the same ? ...

C++ How to assign / retrieve base class?

Suppose I have: class Foo { ... }; class Bar : public Foo { ... }; Foo foo; Bar bar; Is there anyway to do the following: foo_part_of_bar(bar) = foo; foo = foo_part_of_bar(bar); ? Thanks! ...

Problem with D3D & COM

all the D3D interfaces are derived from COM's IUnknown interface, so I though I'd take an easy route for releasing D3D objects and use something like this: __inline BOOL SafeRelease(IUnknown*& pUnknown) { if(pUnknown != NULL && FAILED(pUnknown->Release())) return FALSE; pUnknown = NULL; return TRUE; } this doesn't...

In what situation do you use a semaphore over a mutex in C++?

Throughout the resources I've read about multithreading, mutex is more often used and discussed compared to a semaphore. My question is when do you use a semaphore over a mutex? I don't see semaphores in Boost thread. Does that mean semaphores no longer used much these days? As far as I've understand, semaphores allow a resource to be s...