c++

Force initialization of singleton in c++ before main()

I am using singletons as follows: // Foo.hpp class Foo { static Foo* instance() { static Foo* foo = new Foo(); return foo; } } Now, my singleton is initialized the first time Foo::instance() is called. I want to make sure this is before main executes (my code is multi threaded, I want all singletons initialized before pThr...

C++ struct alignment and STL vectors

I have a legacy data structure that's 672 bytes long. These structs are stored in a file, sequentially, and I need to read them in. While I can read them in one-by-one, it would be nice to do this: // I know in advance how many structs to read in vector<MyStruct> bunchOfStructs; bunchOfStructs.resize(numberOfStructs); ifstream ifs; if...

LibGD library is not working: crash when saving image

I've been seeking for JPG saving library for long time for c++, but i cant seem to get anything to work. Now i am trying use LibGD: What im doing wrong ? It seems to work, but the saving crashes. Code: ... #pragma comment(lib, "bgd.lib") #include <gd/gd.h> ... void save_test(){ gdImagePtr im; FILE *jpegout; int black; ...

Which has been the most reliable, fastest Windows C++ profiler that you have used?

I need to profile a real time C++ app on Windows. Most of the available profilers are either terribly expensive, total overkill, or both. I don't need any .NET stuff. Since it is a real time app, I need the profiler to be as fast as possible. It would be excellent if it integrated in some way with Visual Studio 2005/2008, but that's not ...

Exporting a C++ class from a .SO ( linux )

How can I export whole class to shared library? Is it posible to use THIS library by other languages? ( pascal ) ...

Floating Point Exception Caused By rand() In c++

I have an issue that I can't seem to solve. I am randomly generating numbers in order to determine if my numbers are relativity prime. Here is the function that gives me a Floating Point Exception: bool modularExponentiationTest(unsigned long long exponent, unsigned long long modulus) { short index = 0; unsigned long long base;...

cURL - "hanging" socket connection on Linux

...

Efficiency of Bitwise XOR in c++ in comparison to more readable methods

I've recently been writing some code for a research project that I'm working on, where efficiency is very important. I've been considering scraping some of the regular methods I do things in and using bitwise XORs instead. What I'm wondering is if this will make if a difference (if I'm performing this operation say several million times)...

how do i make this so everything can use it? C++

im somewhat new to c++ so i don't know how to do this but my main point in recoding this is to incress the speed of my program, i have been coding a project and my code is: HWND hWnd = FindWindow(NULL, L"*window's name*"); DWORD th32ProcId; HANDLE hProc; GetWindowThreadProcessId(hWnd, &th32ProcId); hProc = OpenProcess(PROCESS_VM_OPERA...

pointers vs. references vs. a regular pass by value c++

Please read before answering. I dont want you to state the obvious for me. THANKS :D I am trying to differentiate between pointers and passing by value. And I think I understand them but one thing the source I was reading wasnt clear on is what is the difference between passing a pointer and passing by value. consider the following... ...

How do I define a function inside of a class using C++?

How do I define a function inside of a class using C++? ...

Operator Overloading working but giving stack overflow and crashing in C++

I wrote this Node class and = operator overload function and this is the only way I could get it to compile and run but it just overflows and bomb my program. Can someone please fix it so it works. I don't have a lot of experience with overloading operator in C++. I just want to set a Node object equal to another Node object. Thanks in a...

Open default browser as standard user (C++)

I'm currently using ShellExecute "open" to open a URL in the user's browser, but running into a bit of trouble in Win7 and Vista because the program runs elevated as a service. When ShellExecute opens the browser, it seems to read the "Local Admin" profile instead of the user's. So for example, if the user at the keyboard has Firefox a...

Accomplish this task in C++; Migration from AS3.0

I've got way too much information to work with, so for now I'll consider this question answered until I can sort it all out and decide on the final implementation! Thanks a ton gf and Simon Buchan. I wish I could accept both of your answers, since they're both definite possibilities! Additional / Revised Conceptual Information as sugges...

C++ How to read in a text file and reverse the lines so it reads from bottom up

Please help I'm new to C++ Using stacks Implementation I should read a sample text file containing: text file begining to end return text And return a text file reading: return text begining to end test file This is the sample code to test the implementation: #include <iostream> #include <fstream> #include <string> #include "sta...

how to define a class for stock using c++

how to define a "class" for "stock" using c++ language? The class should include the method of "meanvalue" and "variance", meanwhile it should also contain "trading volume" and some historical data. Thank you very much. ...

Different ways of constructing an object in C++.

I want to construct an object in the stack, using C++. Do you know what is the difference between these to ways of calling the constructor (with and without parenthesis): a) MyClass object ; b) MyClass object() ; I am using MFC and when constructing the global variable for the main app, if I use the latter way, I get an exception, I...

Question about COM Release() method

I am learning about COM and reading about this code: STDMETHODIMP_ (ULONG) ComCar::Release() { if(--m_refCount==0) delete this; return m_refCount; } My question is, if the m_refCount==0 and the object is deleted, how could the instance member variable *m_refCount* still exist and be returned? Please forgive me if my questio...

What is the difference between a static variable in C++ vs. C#?

Do static variables have the same or similar functionality in C# as they do in C++? Edit: With C++ you can use static variables in many different contexts - such as: 1) Global variables, 2) Local function variables, 3) Class members - Would similar usages in C# behave similar to that of C++? ...

Substring recursive algorithm not working

I'm a programming student in my first C++ class, and recently we were encouraged to write a simple recursive function to find the first occurrence of a substring in a given string. If found, it returns the index. If the substring is not found, the index_of() function should return -1. We are encouraged to use a helper function that ta...