c++

how to get type of variable?

Hi all! example: template<typename T> struct type_of { typedef boost::mpl::if_<boost::is_pointer<T>, typename boost::remove_pointer<T>::type, T >::type type; }; int main() { int* ip; type_of<ip>::type iv = 3; // error: 'ip' cannot appear in a constant-expression } thenks! ...

How do Boost Bind, Boost Function, Boost Signals and C++ function pointers all relate to each other?

As the title might convey, I'm having problems seeing how Boost Bind, Boost Function, Boost Signals and C++ function pointers all play together. From my understanding, Boost Bind and Boost Function in conjunction work like Signals while Signals is an abstraction above Bind and Function. Also, compared to standard C++ function pointers...

How to pass variable number of parameters from one function to another?

Is there any way to directly pass a variable number of arguments from one function to another? I'd like to achieve a minimal solution like the following: int func1(string param1, ...){ int status = STATUS_1; func2(status, param1, ...); } I know I can do this using something like the following, but this code is going to be duplica...

Converting UTF-8 Characters to Upper/Lower case C++

Hello All, I have a string that contains UTF-8 Characters, and I have a method that is supposed to convert every character to either upper or lower case, this is easily done with characters that overlap with ASCII, and obviously some characters cannot be converted, e.g. any Chinese character. However is there a good way to detect and co...

How to anchor pushButton to the widget ??

Hi, I'm QT beginner. I've created very simple window with one button on it. My button id 10 pixels from right edge of the window and 10 from the bottom. I'd like to keep this position even when the window will get resized. That means, still 10 from the right and 10 from the bottom. How to do this ?? Thanks zalkap ...

Get Photoshop's action list using Objective-C

I'm writing an application for OSX using C++ and Obj-C that interacts with Photoshop. I've been using NSAppleScript with dynamically built AppleScripts to drive Photoshop (yes, it's a little scary...) I would love to be able to drive Photoshop a different way, so if anyone knows a better way, I'm open to it! Unfortunately, I can't use S...

What good C++ Mail library would you recommend?

Hi, I'm looking for a good Mail library (both open source and commercial) for C++ with the following features: Support SMTP, POP3, and IMAP Support MIME and SMIME Support Proxy Support SSL ...

Is there a inbuilt mechanism so that bytes writen to the pipe can overwrite earlier bytes if buffer is not enough?

Pretty much like a queue,when the queue is full an new member wants to come in,just remove the first member at the head of the queue. Is there such a default mechanism in windows? If yes how can I do that in c/c++? ...

Bullet algorithm having trouble with rotation on the X

Here is what I'm trying to do. I'm trying to make a bullet out of the center of the screen. I have an x and y rotation angle. The problem is the Y (which is modified by rotation on the x) is really not working as intended. Here is what I have. float yrotrad, xrotrad; yrotrad = (Camera.roty / 180.0f * 3.141592654f); xrotrad = (...

Why is C++ a mid-level language?

Why is C++ a mid-level language? It can almost do everything and the worlds most widely used operating system is written in it. [Note: SO C++ Info page quotes Wikipedia citing C++ The Complete Reference Third Edition, by Herbert Schildt, It is regarded as a "middle-level" language, as it comprises a combination of both high-level an...

Anonymous Namespace Ambiguity

Consider the following snippet: void Foo() // 1 { } namespace { void Foo() // 2 { } } int main() { Foo(); // Ambiguous. ::Foo(); // Calls the Foo in the global namespace (Foo #1). // I'm trying to call the `Foo` that's defined in the anonymous namespace (Foo #2). } How can I refer to something inside an anonymous namesp...

Dynamic menu using mfc

I would like to add a menu item to my main menu and then populate it with items at run time. How would I do this? And besides adding items how would I have a message map entry for them since I do not know the id? Thanks and sorry for my english. ...

How do you get info for an arbitrary time zone in Linux / posix?

Ideally, what I'd like to be able to do is take the name of a time zone and call a function to ask for its corresponding time zone info (offset from UTC, DST offset, dates for DST switch, etc.) in Linux. However, I can't find any way to do this. The information exists in /usr/share/zoneinfo/ in the various binary files there, but I don't...

Anonymous Namespace

A recent thread on SO triggerred this. An anonymous namespace is considered to be equivalent to namespace unique { /* empty body */ } using namespace unique; namespace unique { namespace-body } I fail to recollect the exact reason as to why it is not equivalent to namespace unique { namespace-body } using namespace uniq...

Peek the next element in STL container

is it possible to peek next element in a container which the iterator currently points to without changing the iterator? For example in std::set, int myArray[]= {1,2,3,4}; set <int> mySet(myArray, myArray+4); set <int>::iterator iter = mySet.begin(); //peek the next element in set without changing iterator. mySet.erase(iter); //erase...

C++ template metaprogramming to create a boost::variant from a shared_ptr and a boost::static_visitor

As a personal exercise, I want to implement the visitor pattern using shared_ptr. I am familiar with Robert Martin's acyclic visitor paper but find the intrusive nature of the virtual accept() and necessary creation of an {X}Visitor class for each {X} class unpleasant. I like the boost::static_visitor class as it encapsulates all the l...

Need for out of class definition of static variable?

My question: What exactly is the out of class definition of k doing under the hood to make sure it's address is available? #include <iostream> using namespace std; class A { public: static const float k = 7.7; }; //const float A::k; --> without this line compiler error int main() { cout << &A::k; } ...

What is difference between instantiating an object using new vs. without

In C++, Aside from dynamic memory allocation, is there a functional difference between the following two lines of code: Time t (12, 0, 0); //t is a Time object Time* t = new Time(12, 0, 0);//t is a pointer to a dynamically allocated Time object I am assuming of course that a Time(int, int, int) ctor has been defined. I also realize ...

wxWidgets display bitmap from an 8 bit array

I have a function generating an array that I need to draw to the screen. The array is in the form of an 8 bit grayscale image. How can I draw the array to the screen properly? I have a working version of this app in with win32 code which uses StretchDIBits to draw the image. My question is, can I/how can I do something similar in wxWidge...

Is std::array<T, S> guaranteed to be POD if T is POD?

I'm currently writing a C++ memory editing library and for the read/write APIs I use type traits (std::is_pod, std::is_same) and boost::enable_if to provide 3 overloads: POD types. e.g. MyMem.Read(SomeAddress); String types. e.g. MyMem.Read>(SomeAddress); (This doesn't actually read out a C++ string, it reads out a C-style string and c...