c++

How can I assign to an instance variable in C++ when a local variable has same name?

I have a class defined like this: class MyClass { int x; public: MyClass(int x); }; MyClass::MyClass(int x) { //Assign x here } However, I can't initialize x in the constructor because it has the same name as an instance variable. Is there any way around this(other than changing the name of the argument)? ...

where to store .properties file for use in c++ dll

Hi, I created a .properties file that contains a few simple key = value pairs. I tried it out from a sample c++ console application, using imported java classes, and I was able to access it, no problem. Now, I am trying to use it in the same way, from a C++ dll, which is being called by another (unmanaged) c++ project. For some reason...

How to avoid successive deallocations/allocations in C++?

Consider the following code: class A { B* b; // an A object owns a B object A() : b(NULL) { } // we don't know what b will be when constructing A void calledVeryOften(…) { if (b) delete b; b = new B(param1, param2, param3, param4); } }; My goal: I need to maximize performance, which, ...

What is the best technique to create a thread in C++ while passing the class and an index?

I am creating a data-parallel program using pthreads and C++. From http://stackoverflow.com/questions/1151582/pthread-function-from-a-class, I found out how to supply pthread_create with a function pointer to a static C++ function(and supply it a this argument). However, I also need to supply the thread with an index, so it knows what d...

How do I use a COM DLL with LoadLibrary in C++

First, COM is like black magic for me. But I need to use COM dll in one project I'm working on. So, I have a DLL I am developing and I need some functionalities that are available in a separate COM DLL. When I look to the COM DLL with Depends.exe I see methods like DllGetClassObject() and other functions but none of the functions I'm i...

Why is this code slower even if the function is inlined?

I have a method like this : bool MyFunction(int& i) { switch(m_step) { case 1: if (AComplexCondition) { i = m_i; return true; } case 2: // some code case 3: // some code } } Since there are lots of case statements (more than 3) and the function is becoming large, ...

c and c++ operators help

can someone explain to me why the following results in b = 13? int a, b, c; a = 1|2|4; b = 8; c = 2; b |= a; b&= ~c; ...

How can I use a std::valarray to store/manipulate a contiguous 2D array?

How can I use a std::valarray to store/manipulate a 2D array? I'd like to see an example of a 2D array with elements accessed by row/column indices. Something like this pseudo code: matrix(i,j) = 42; An example of how to initialize such an array would also be nice. N.B.: I'm already aware of Boost.MultiArray, Boost.uBlas, and Blitz++...

C++ containers behavior

Hello. My question is simple. When I use STL containers, do they copy the value I store there (by using copy constructor) or not? What if I give them array of characters (char *) instead of string instance? How do they behave? Is guaranteed that information will be stored in heap instead of system stack? Thanks for answers. ...

X-Macros Redefinition

when I include the "xmacro.h" in header file which is used by multiple header files i get linking error: Error LNK2005: "char const * * iD_Strings" (?iD_Strings@@3PAPBDA) already defined in header_file.obj 1.//"xmacro.h" 2. 3.// (1) Define code generating macro 4. 5. #ifndef XMACRO_H 6. #define XMACRO_H 7. 8. #define GENERATE_IDS...

Winsocks - Why the Socket wont bind to server ?

Ok I know the few rules of Sockets 1. Open ports ... Now how would i go about port forwarding in C++ to open the port to use for my application? ...

ICU Unicode Normal vs Fullwidth

I am somewhat new to unicode and unicode strings. I'm trying to determine the difference between "fullwidth" symbol and a normal one. Take these two for example: Normal: http://www.fileformat.info/info/unicode/char/20a9/index.htm Fullwidth: http://www.fileformat.info/info/unicode/char/ffe6/index.htm I notice that the fullwidth is def...

C++ calling managed COM object can't find dependent assemblies

I've created and registered a managed COM library in C# on my development machine. I've successfully registered it and created a .tlb file with regasm, and successfully imported the tlb into a c++ console app used for testing. My COM assembly is called "efcAPI.dll" and it references another assembly that has not been set up for COM or r...

glGetTexImage() doesnt work properly on ATI cards? fails when miplevel > 0

I use that function to get my texture from the graphics card, but for some reason it doesnt return anything on some cards if miplevel > 0 Here is the code im using to get image: glGetTexImage(GL_TEXTURE_2D, miplevel, GL_RGB, GL_UNSIGNED_BYTE, data); here is the code i use to check which method to use for mipmapping: ext = (char*)gl...

Static library inspector for windows?

I know there are tools like PE Explorer for inspecting the contents of DLLs on windows (exported symbols, etc). Is there something similar for static libraries? I'm linking against a third party library that's generating some linking errors, and I want to double check that the symbols I expect are indeed being provided. ...

C++ How to use and pass a 3-dimensional char array?

I'm trying to build a char array for storing the return value of a function. In the following function the data is stored in ***valv. How to build a extern variable to access the data? int credis_lrange(REDIS rhnd, const char *key, int start, int end, char ***valv) { int rc; if ((rc = cr_sendfandreceive(rhnd, ...

Is fastcall really faster?

Hi, Is the fastcall calling convention really faster than other calling conventions, such as cdecl? Are there any benchmarks out there that show how performance is affected by calling convention? ...

A method of creating simple game GUI

I have been able to find a lot of information on actual logic development for games. I would really like to make a card game, but I just dont understand how, based on the mouse position, an object can be selected (or atleast the proper way) First I thought of bounding box checking but not all my bitmaps are rectangles. Then I thought f m...

linking <iostream.h> in linux using gcc

I'm trying to run my very first c++ program in linux (linux mint 8). I use either gcc or g++, both with the same problem: the compiler does not find the library I am trying to import. I suspect something like I should either copy the iostream.h file (which I don't know where to look for) in the working folder, move my file to compile ...

Vista-Eclipse (Galileo) CDT w/ MinGW and MinGW's GDB fails to output cerr output.

I installed Eclipse and I can get g++ to compile the code correctly; however, when I start the debugger none of the "cerr >>" outputs are ever displayed in the Eclipse console. I tried to run GDB manually and it, too, does not display the cerr output. Is anyone else experiencing this?? I am running the GDB 5.3-something that is available...