c++

How do I get non-global objects to interact from within a function?

I'm trying to create a Breakout clone using C++, and so have several objects (like ball, paddle, powerupicon, block, etc). I understand that it's bad practice to have them at global scope, so they're initialized inside main(). The problem comes in with needing to do stuff with those objects from inside other functions (like redraw(), or ...

stricmp doesn't work

i'm having a problem using stricmp in a specific function, in other functions it works perfectly, except this one. the problem is that even if it compares the same string (char*) it doesn't return 0. what might be the problem? (sorry for the mess, i'll try formatting it) that's the code: Employee* CityCouncil::FindEmp(list<Employee*> *l...

Finding the median value of an array?

Hello, I was wondering if it was possible to find the median value of an array? For example, suppose I have an array of size nine. Would it possible to find the middle slot of this array? ...

Inheritance in C++ internals

Hi, Can some one explain me how inheritance is implemented in C++ ? Does the base class gets actually copied to that location or just refers to that location ? What happens if a function in base class is overridden in derived class ? Does it replace it with the new function or copies it in other location in derived class memory ? ...

C++ native Vs C++/Cli Performance ( for OpenCV project)

We're developing a project that uses OpenCV library to track hand gestures and motion sensing. I'm confused whether to go for native c++ program or to use C++/CLI provided in .NET (VC++). Performance is of utmost importance and heavy image processing is required. since we're planning to use the OpenCV extensive methods and the project r...

Named parameter string formatting in C++

I'm wondering if there is a library like Boost Format, but which supports named parameters rather than positional ones. This is a common idiom in e.g. Python, where you have a context to format strings with that may or may not use all available arguments, e.g. mouse_state = dict(button=0, x=50, y=30) "You clicked %(button)s at %(x)d,%(y...

It is possible to get functionality similar to .NET's LINQ in C++?

It is possible to get functionality similar to .NET's LINQ in C++? Would this require language extensions or could it be done using some very clever macros? Or even through a tool like Qt's moc (meta-object compiler)? Are there any existing LINQ implementations for C++ and if so, what are they? ...

C++ - What is the purpose of function template specialization? When to use it?

Learning C++, came upon function templates. The chapter mentioned template specialization. template <> void foo<int>(int); void foo( int ); Why specialize when you can use the second? I thought templates were suppose to generalize. What's the point of specializing a function for a specific data type when you can just use a regular fu...

What is the best way for starting graphical interfaces programming in C?

I have some knowledge in C/C++ but only using the Console. I'd like to start programming some graphical interfaces, but I don't have the minimal idea where to start. I've heard of GUI applications and DirectX applications. I'd like to know which is the best for start programming? Which libraries also is good to use and some tutorials...

Problems with getting glyph outline with appendBezierPathWithGlyphs

I'm working with Objective-C++. I'm trying to get the path outline of a text using NSBezierPaths appendBezierPathWithGlyphs. The problem is: the output is rather nonsense :( What I've written: String str = Ascii8("test string"); int length = str.getLength(); NSFont* font = [NSFont fontWithDescriptor: [NSFontDescriptor fontDesc...

return() versus pthread_exit() in pthread start functions

The following program shows that we can use return() or pthread_exit() to return a void* variable that is available to pthread_join()'s status variable. (1) Should there be a preference for using one over the other? (2) Why does using return() work? Normally we think of return putting a value on the stack but since the thread is comple...

Fastest 128 bit integer library

I am working on a CPU-heavy numerical computation app. Without going into many details, it's a computational math research project that involves computing a certain function f(x) for large integer x. Right now everything is implemented in C++ in x64 mode, using native 64-bit ints. That limits me to x<2^64~1.8*10^19. I want to go furthe...

design problem - inheritance with static variables

Hi. I have the following hierarchy: Graduate.cpp (abstract) College.cpp (abstract) Ecollege.cpp University.cpp (abstract) Tuniversity.cpp Huniversity.cpp class Huniversity for example represents a student that graduated from H university. each non-abstract class has to implement the following method which i...

Help with Diamond Square algorithm implementation

I'm trying to implement the Diamond-square algorithm, but the problem is only part of the bitmap is being filled and I'm not sure what's wrong. I'm doing it recursively: GLuint CreateDsquare() { std::vector<GLubyte> pdata(256 * 256 * 4); vector2i loc; vector2i sz; GLubyte val; sz.x = 25...

C++ Coprimes Problem. Optimize code.

Hi i want to optimize the following code. It tries to find all coprimes in a given range by comparing them to n. But i want to make it run faster... any ideas? #include <iostream> using namespace std; int GCD(int a, int b) { while( 1 ) { a = a % b; if( a == 0 ) return b; b = b % a; if( b == 0 ) retur...

Floating point versus fixed point: what are the pros/cons ?

Floating point type represents a number by storing its significant digits and its exponent separately on separate binary words so it fits in 16, 32, 64 or 128 bits. Fixed point type stores numbers with 2 words, one representing the integer part, another representing the part past the radix, in negative exponents, 2^-1, 2^-2, 2^-3, etc. ...

capturing openCV video in windows forms

When I try to capture video from webcam using OpenCV, it opens a new window and the video is shown there. Instead of showing in a separate window, I want the video to be shown in a windows form element like picturebox. I am using visual c++ 2008 for developing windows forms. Plz help me. ...

Get typedef of current class

Hi there, I'm currently using boost::intrusive_ptr together with my GUI classes. Although this is more or less a convenience question, is there a proper way to get the typename of the current class? The reason I'm asking is that I have a macro for typedef'ing the different pointer types: #define INTRUSIVE_PTR_TYPEDEFS(CLASSNAME) typede...

API Hook on a COM object function?

Greetings StackOverflowians, As discovered here, Windows 7 features a bug in which the DISPID_BEFORENAVIGATE2 event does not fire for Windows Explorer instances. This event allows shell extensions to be notified when a navigation is about to take place, and (most importantly for me) have the opportunity to cancel the navigation. I've ...

Simple user request for filename for output and input question

How can I request the user to input the filename that my program needs to read from and have it output the name with ".out" instead? Example: char fileName[256]; cout << "What is the file name that should be processed?"; cin >> fileName; inFile.open(fileName); outFile.open(fileName); But I need it to save the file as a filename.out ...