c++

C++ fancy template code problem

Hi! I try to get a (for me) rather complex construct of templated code to work. what i have: a class shaderProperty of generic type class IShaderProperty { public: virtual ~IShaderProperty() {} }; struct IShaderMatth; //forward declaration template<typename ShadeType> struct ShaderMatth;//forward declaration template <typename T> c...

Resize a file (down)

I'm attempting to shrink a file in place. I'm replacing the contents of one file with those of another and when I'm done I want to make sure if the source file is smaller than the dest file, the dest file shrinks correctly. (Why: because the dest file is a backup and writing to the media is very expensive, so I only write the deltas to ...

thread synchronization

let's say i have a blocking method , let's call in Block(). as i don't want my main thread to block i might create a worker thread, that instead will call Block. however, i have another condition. i want the call to block to return in 5 seconds top, otherwise, i want to let the main thread know the call to Block failed and to exit the...

Add mfc to a project?

I have already started a project and would like to add forms to it with MFC. How do you do this? I tried setting it to use mfc but it still doesn't allow me to add mfc classes(it says it isn't an mfc project). Also is there any GUI library that works sorta like .net? Maybe it is because I haven't used MFC too much but I don't care for h...

Would VS2008 c++ compiler optimize the following if statement?

if (false == x) { ...} as opposed to: if (!x) { ... } and if (false == f1()) { ...} as opposed to: if (!f1()) { ... } I think the if(false == ... version is more readable. Do you agree, or have another trick you can propose? Will it be just as fast? Thanks. This is why I do not like !x: if (25 == a->function1(12345, 6789) &&...

Use of a Union to avoid Dynamic Allocation Headaches

I'm curious if it's a good idea to use a union when accessing Win32 APIs that return variable length structures, to avoid manually managing the allocated memory. Consider the following: void displayServices(std::wostream& log, std::tr1::shared_ptr<void> manager, LPENUM_SERVICE_STATUS currentServiceToDisplay, DWORD number, bool whitelis...

C++ problem with std::pair and forward declarations

Hi! Unfortunately I still got a problem with my templated code from here: http://stackoverflow.com/questions/1911434/c-fancy-template-code-problem on line 49 in the file 'utility': error C2440: 'Initializing': cannot convert from 'const int' to 'IntersectionData *' error C2439: 'std::pair<_Ty1,_Ty2>::second': member could not be in...

Using istream_iterator and reading from standard input or file

Hi, I'm writing in Microsoft Visual C++ and I'd like my program to either read from standard input or a file using the istream_iterator. Googling the internets hasn't shown how simple I think it must be. So for example, I can write this pretty easily and read from standard input: #include <iostream> #include <string> #include <iterator>...

How to customize windows default right click pop-up menu

Hi! I have two questions. My first one is, that how can i "put" something into the default windows right click pop-up menu? I mean, if i click with the right mouse button on an .exe, then the default things appers(like cut, copy, send to, run as...), but how can i put there one extra line, like "MyApp", which will start my application? ...

Difference between a program that crashes and program that hangs

What is the difference (or causes) between a program that crashes and a program that hangs (becomes unresponsive) in C++? For sure, accessing invalid memory causes a program to crash. Deadlock in threads may cause a program to hang. What are the other causes? Does exhausting all memory causes a program to hang? or crash? I'm a bit conf...

VisualStudio C++ Linker problem with template classes

I still can't get it to work.. After I had to separate implementation from definition of one of my generic classes because of a forward declaration, i now get Linker errors when trying to build. IShader.h: template <typename ShadeType> class IShader { public: template <typename T> bool getProperty(const std::string& propertyName, Sh...

Nominal case first vs. Positive boolean expressions

As the topic states, sometimes these issues conflict. For example... In this case, the nominal case is first, but the expression is negative. if ( !foo.IsDead() ) { DoThis(); } else { DoThat(); } In this case, the expression is positive, but the nominal case is last. if ( foo.IsDead() ) { DoThat(); } else { DoThis(); } Of ...

Best/worst examples of undefined behavior in C or C++?

Possible Duplicates: Whats the worst example of undefined behaviour actually possible? What are all the common undefined behaviour that c++ programmer should know about? What are the common undefined behaviours that Java Programmers should know about There are lots of parts of the C and C++ standards that are not completely ...

Better random algorithm?

I'm making a game in c++ and it involves filling tiles with random booleans (either yes or no) whether it is yes or no is decided by rand() % 1. It doesnt feel very random. I'm using srand with ctime at startup, but it seems like the same patterns are coming up. Are there any algorithms that will create very random numbers? Or any sugges...

Homework: Need guidance on creating an OO non-graphical/text adventure game

Okay... I'll try to describe it. It's a text adventure game where you have items you pick up and encounter monsters in rooms (they can be hard-coded in). All my pickups are going to do damage, and the player and the monsters have hitpoints, a name and damage (so the pickups just add to the player's damage when you use them). We have to...

segfault when copying an array to a vector in Linux

Hi, I'm trying to debug a legacy code written for Linux. Sometimes the application gets a segfault when it reaches the memcpy call in the following method: std::vector<uint8> _storage; size_t _wpos; void append(const uint8 *src, size_t cnt) { if (!cnt) return; if (_storage.size() < _wpos + cnt) _storage.resize(_wpos + cnt); ...

Anyone knows of a good addressbook implementation?

I am looking to add an address book to one of my programs. For that purpose, I want to have something that is flexible and customizable to the point of allowing me to hook up additional metadata to contacts in it from third parties. I don't mind paying for a solution as long as I get something that is usable for me. My requirements: ...

Making PNG|jpeg from LaTeX in C or C++

I'm looking for a library (or a cleverer solution) in C or C++ that would make an image file (PNG|jpeg) from LaTeX code. The use of packages is a prerequisite. For now I'm thinking of compiling a .tex file into a .dvi and using dvipng to get a .PNG. There's also the possibility of compiling a .tex file into a .ps file and then convert...

Learning about C++ 0x features.

What is a good place to learn about the new C++ 0x features? I understand that they may not have been fully finalized yet but it would be nice to get a head start. Also, what compilers currently support them? ...

Replacement for vector accepting non standard constructable and not assignable types

I have a class test which isn't standard constructable nor assignable due to certain reasons. However it is copy constructable - on may say it behaves a bit like a reference. Unfortunately I needed a dynamic array of these elements and realized that vector<test> isn't the right choice because the elements of a vector must be standard co...