c++

What is the Visual studio equivalent to GNU ld option --whole-archive

When linking a static library against an executable, unreferenced symbols are normally discarded. In my case some otherwise unused objects are used to register their respective classes into a factory and if the object are discarded, this registration fails. Under Unix where we use gcc, I can pass the flag --whole-archive to the linker l...

Can the 'type' of a lambda expression be expressed?

Thinking of lambda expressions as 'syntactic sugar' for callable objects, can the unnamed underlying type be expressed? An example: struct gt { bool operator() (int l, int r) { return l > r; } } ; Now, [](int l, int r) { return l > r; } is an elegant replacement for the above code (plus the necessary creation of c...

What's a good reference for creating and updating Performance Counters in unmanaged code?

I have several apps that need to create and write to Performance Counters. One of them is written in C++. Currently, upgrading that app to .NET is not an option. Where is a good resource for accessing Performance Counters using unmanaged code? Thanks! ...

Generic structs in unions

I'm trying to make a generic vector class. While I can do something like this: struct vector3 { union { struct { float x; float y; float z; }; float v[3]; }; }; I cannot do this: template<int N, typename S, typename T = double> class vec { union { T data[N]; S; }; }; struct...

How to combine BrowserNavConstants in c++?

I am trying to use BrowserNavConstants for .Navigate2 flags, but I dont know how to combine more than one in the same variant for c++. On VB i would use navNoHistory + navNoReadFromCache + navNoWriteToCache or Flags := NavNoHistory or NavNoReadFromCache or NavNoWriteToCache or NavAllowAutosearch; for delphi, but how should I do it...

When to use __gc for classes and structs?

I am updating some old c++ code and am finding that many of the classes are defined as: public __gc class NameOfClass{ } I found a little bit of information about __gc here, but it seems to only come up with information for VS 2003. The MSDN documentation that came with my copy of VS 2005 indicates that __gc may not be in use anymor...

Is there any setfill() alternative for C?

In C++: int main() { cout << setfill('#') << setw(10) << 5 << endl; return 0; } Outputs: #########5 Is there any setfill() alternative for C? Or how to do this in C without manually creating the string? Thanks in advance. ...

Has anyone gotten windows c++ to talk to project voldemort?

Good afternoon all, I'm interested in trying to use Voldemort from a windows C++ application. The example provided only works on Linux. ...

Count character occurrences in a string

How can I count the number of "_" in a string like "bla_bla_blabla_bla"? ...

Why is my program slow ? How can I improve its efficiency ?

I've a program that does Block Nested loop join (link text). Basically what it does is, it reads contents from a file (say 10GB file) into buffer1 (say 400MB), puts it into a hash table. Now read contents of the second file (say 10GB file) into buffer 2 (say 100MB) and see if the elements in buffer2 are present in the hash. Outputting th...

Trying to compile a working irrlicht application on a mac with plain g++ or Xcode

Ok, here it goes: I managed to compile the .xcodeproj provided with the last zip achive into a .a library file (a static library then). I failed to build a working application that uses irrlicht as a 3D engine with Xcode, I don't really know to do it since I'm sort of unable to use an IDE. I tried to link a simple program with this li...

My Sieve of Eratosthenes takes too long

I have implemented "sieve of eratosthenes" to solve an SPOJ problem. Though the output is fine, my submission exceeds the time limit. How can I reduce the run time? int main() { vector<int> prime_list; prime_list.push_back(2); vector<int>::iterator c; bool flag=true; unsigned int m,n; for(int i=3; i<=32000;i+=2) { flag...

Does an approximation of C++'s "const methods" exist for Objective-C?

Wondering if there's any accepted practice for approximating C++'s 'const methods' in Objective-C. (new to the language from a C/C++ background) For instance: class Foo { public: void canChangeMemberVars(void); char* asString(void) const; }; "asString()" gets a const this pointer, so even if you go rogue and decide to mu...

string reverse in c++

Why does this piece of code throw an exception when I try to change a character in the string void reverseString(char *s) { int e = strlen(s) - 1; int b = 0; char t1,t2; while(b < e) { t1 = s[b]; t2 = s[e]; s[b] = t2; s[e] = t1; b++; e--; } } ...

Is a std::vector pointer reliable?

Say I have this: Object *myObject; std::vector<Object> objects(99); .... myObject = &objects[4]; Would it be safe to assume that myObject's pointer will always be valid no matter how big objects[] gets and if I remove some, as long as I do not ever erase() the actual object pointed to by myObject? Or does it work differently? If the ...

Error: Expected constructor, destructor, or type conversion before '<' token

I have been trying for the last 20 minutes figuring out why it is throwing this error.. #include <GL/glut.h> #include <vector> // global width and height int GW; int GH; // current mouse position in pixel coordinate int x; int y; typedef struct myTriangle { float tx; float ty; } myTriangle; vector<myTriangle> container; The ...

c++ member function specialisation of a class that has a template as a parameter

I am working on a template class Array, which accepts another template TRAITS as a parameter. template <typename BASE, typename STRUCT> class Traits { public: typedef BASE BaseType; typedef STRUCT Struct; // .. More here }; template <class TRAITS> class Array { public: typedef TRAI...

Visual Studio Breakpoint Macro to modify a value?

I'm debugging an application (C++), and I've found a point in the code where I want to change a value (via the debugger). So right now, I've got a breakpoint set, whereupon I do: Debugger reaches breakpoint I modify the variable I want to change I hit F5 to continue running lather, rinse, repeat It's hitting this breakpoint a lot, s...

A question on pointers

Take this piece of code: int a; int *pointer = &a; int **b = &(&(*pointer)); Would the above set b to the address of pointer or not? The reason I ask is because *pointer gives the value of a, and the reference of that is the address of a. Is this treated as just the address of a, or is it also treated as pointer. Does this make sen...

How do i print a file in my c++ program with words taken out?

I'm writing a program in c++ and I need to ask the user for a file name, print the file and then reprint it with every 5th word missing. I've gotten as far as to asking them file name, checking for errors and printing out the file, I'm just completely lost on how to reprint it with every 5th word missing, any help? #include <iostream> #...