c++

Get attribute using XPath with TinyXPath & TinyXML

I'm trying to write a function that will get me the attribute of a set of XML nodes in a document using XPath with the TinyXPath library, but I cannot seem to figure it out. I find the documentation on TinyXPath is not very enlightening either. Can someone assist me? std::string XMLDocument::GetXPathAttribute(const std::string& attrib...

What are the security implications of using boost/format?

I am starting to use boost/format. When coding with boost/format, what should I pay attention to with regard to security? Can I do the following without being concerned about security? std::cout << boost::format("Hello %2%! Do you want to %1%?") % user_supplied_str1 % user_supplied_str2 << std::endl; What are situations where ...

Finding max_element of a vector where a member is used to decide if its the maximum.

Consider a class A having a member x and a std::vector< A >. Now its a common task to search for the maximal x among all elements inside the vector. Clearly I can only use std::max_element if there is an iterator on the x's. But I must write one by my own, or I just make a simple for loop. maxSoFar = -std::numeric_limits< double >::max(...

Why can we delete arrays, but not know the length in C/C++?

Possible Duplicate: C programming : How does free know how much to free? How is is that it is possible for us to delete dynamically allocated arrays, but we can't find out how many elements they have? Can't we just divide the size of the memory location by the size of each object? ...

GCC 4.2 Template strange error.

Hello, i have the following code compiled with GCC 4.2 / XCode. template <typename T> class irrProcessBufferAllocator { public: T* allocate(size_t cnt) { return allocProcessBufferOfType<T>(cnt); } void deallocate(T* ptr) { if (ptr) { releaseProcessBuffer(ptr); } } ...

How to document overridden/implemented functions without Doxygens @copydoc?

How can I document an overridden method or an implemented virtual method of a sub class? Should I use @copydoc? class A { /** * A detailed description........ */ virtual int foo(int i); } class B : public A { /** {I won't write the same description again.} */ int foo(int i); } ...

Make a GUI Interface

Hi I have made a game and I have used OpenGL for its graphics.the OS is ubuntu 10.04. The only thing left is to make a user interface so as to directly receive the requisite inputs from the user rather than from the terminal. Can sm1 please tell me any good links to go to !!!!or any software that can ease my work ! thnx. ...

Calculating a Random for C++

This is probably a super easy question, but I just wanted to make 10000% sure before I did it. Basically Im doing a formula for a program, it takes some certain values and does things when them.....etc.. Anyways Lets say I have some values called: N Links_Retrieved True_Links True_Retrieved. I also have a % "scalar" ill call it, for ...

Constructing associative containers

I was convinced (until I just tried it a moment ago) that it was possible to instantiate an associative container with array style notation. For example, std::set< int > _set = { 2, 3, 5 }; This isn't the case but I am wondering if there is any other way of bulk initialising a container in the constructor like this? ...

C++ call back system. Pointers to member functions.

Hi, Im trying to create a call back by passing a pointer to member functions but am running into all types of issues. How can i go about implementing such a thing template<class T> class A{ void (T::*callBackFunction)(int); public: void addCallBack(void (T::*callBackFunction)(int)){ void (T::*callBackFunction...

problem with simple function

I wana define a simple function in my program so I added this prototype in .h file: double TimeCalculation (Ptr <Node> mynode,Ptr <Node> nb_node, Ptr <Ipv4> nbipv4, Ptr <Ipv4> myipv4 ); then i wrote this function: double TimeCalculation (Ptr <Node> mynode, Ptr <Node> nb_node, Ptr <Ipv4> nbipv4, Ptr <Ipv4> myipv4) { ...

how to handle optimizations in code

I am currently writing various optimizations for some code. Each of theses optimizations has a big impact on the code efficiency (hopefully) but also on the source code. However I want to keep the possibility to enable and disable any of them for benchmarking purpose. I traditionally use the #ifdef OPTIM_X_ENABLE/#else/#endif method, b...

Instantiate object of a class before main() executes

Is it possible to instantiate an object of a class even before main() executes? If yes, how do I do so? ...

SDL_SetVideoMode problems

I'm using SDL_Image to display a JPEG on screen and having some issues with the resolution it's being displayed at. I understand that if I pass 0 to width, height and bits when calling SDL_SetVideoMode that SDL takes the current modes values, however these seem to be wrong in my case. I'm running this on an embedded linux system with a...

Test for Low bandwidth Networks

Hi I have made a game and I have used OpenGL for its graphics.the OS is ubuntu 10.04. The game is multiplayer.For its testing I am unable to find any tool/software for low bandwidth and high latency.I mean I want to find the appropriate network conditions so as to run my game ! Can sm1 please tell me any good links to go to !!!!or any s...

Is FC++ used by any open source projects?

The FC++ library provides an interesting approach to supporting functional programming concepts in C++. A short example from the FAQ: take (5, map (odd, enumFrom(1))) FC++ seems to take a lot of inspiration from Haskell, to the extent of reusing many function names from the Haskell prelude. I've seen a recent article about it, and i...

Socket re-connection failure

System Background: Its basically a client/server application. Server is an embedded device and Client is a windows app developed in C++. Issue: After a runtime of about a week, communication breaks between client/server, because of this the server is not able to connect back to the client and needs a restart to recover. Looks like Syst...

cpp file #include causing errors, @class not

In an iPad app im using a thirdParty cpp file that acts as a controller for some UI functionality; its wired up with IB and a @class definition is all i need. However now I'm trying to set a delegate on the cpp file and therefore have to include it in the implementation of my viewController. including the cpp header in my implementatio...

Array and struct initialize in C++

I would like to initilize some elements of an struct and array in C++. In C you can do: unsigned char array[30] = {[1] = 4, [20] = 4}; struct mystruct { int i; int j; } struct mystruct e = {.j = 2}; But I cannot do it in C++. Is there any way to implement this kind of designated initializers? ...

Templates :Function template specializations:Template argument deduction: -->can any one tell some more examples for this statement?

This is the statement from ISO C++ Standard 14.8.2.4 / 3rd :Deducing template arguments from a type A given type P can be composed from a number of other types, templates, and non-type values: — A function type includes the types of each of the function parameters and the return type. — A pointer to member type inc...