c++

Problems with declarations and initializations

I am trying to rewrite a code I have written earlier. The code uses cplex concert API; #include <ilcplex/ilocplex.h> using namespace std; ILOSTLBEGIN int main(){ IloEnv env; IloModel model(env); IloVarArray x(env); IloCplex cplex(model); return 0; } This code (though it doesn't do anything) w...

VS2010 C++ member template function specialization error

I have the following (minimized) code, which worked in VC2005, but no longer works in 2010. template <typename TDataType> class TSpecWrapper { public: typedef typename TDataType::parent_type index_type; public: template <bool THasTriangles> void Spec(index_type& io_index) { std::cout << "False version" << s...

Class type from pointer used as template argument

If a pointer to an user defined type is passed as template argument to a template class, is it possible to get the class type of the argument? template <class T> struct UserType { typedef T value_type; ... }; int main () { typedef std::vector<UserType<double>*> vecType vecType vec; vecType::value_type::value_type m...

auto_ptr and containers - C++

Hi. I'm currently working on a 2D game engine and I've read about auto_ptr's and how you should never put them in standard containers. My engine has this structure: StateManager -- has many --> State's. States are created and allocated in main, outside of the engine. I want the engine to store a list/vector of all the states so I can...

Pointers to statically allocated objects

I'm trying to understand how pointers to statically allocated objects work and where they can go wrong. I wrote this code: int* pinf = NULL; for (int i = 0; i<1;i++) { int inf = 4; pinf = &inf; } cout<<"inf"<< (*pinf)<<endl; I was surprised that it worked becasue I thought that inf would dissapear when the program left the b...

Set Focus to a Cocoa Window in Carbon App

Hello, I'm trying to create a Cocoa Window within an otherwise Carbon Application (it's an OpenGL API that uses AGL. Can't change it so don't comment on that). Here's a code snippit: WindowRef winref = static_cast<eq::AGLWindow*>(getOSWindow())->getCarbonWindow(); vc = [[SFAttachedViewController alloc] initWithConfig:config]; //load...

dynamic_cast an interface from a shared library which was loaded by lt_dlopen(libtool) doesn't work

This is about plugin features in my program. I need a C++ class(and object) in a plugin could be used by main module through an interface. The interface inheritance like this: typedef struct _rwd_plugin_root_t RWD_PLUGIN_ROOT_T; struct RWD_PLUGIN_API _rwd_plugin_root_t { virtual int add_ref() = 0; virtual int release() = 0; }; ...

C++ Rounding to the _nths place

Possible Duplicate: Rounding Number to 2 Decimal Places in C I'm currently learning c++ on a linux machine. I've got the following code for rounding down or up accordingly but only whole numbers. How would I change this code to round to the hundredths place or any other decimal? I wouldn't ask if I didn't try looking everywher...

pthread_mutex_lock and unlock

i have two threads, they run pretty fast, i'm using pthread_mutex_lock and pthread_mutex_unlock to access global (externed variables) data the problem is that my application takes about 15-20% of CPU running on Ubuntu Linux, the same code but with EnterCriticalSection and LeaveCriticalSection and running on Windows uses 1-2% of CPU ...

Unused friend class in C++

Is there a way to detect (for instance with compiler warning) if classes are declared friend but do not access private members, ie. when friendship is useless? ...

What to do with "This application has failed to start because myproject.dll was not found." error

Hi, I have a project A linked to a project B. B is compiled into a .dll while A is the main program and compiled into a .exe The compiling of the projects is done without any issues, but when I run the program, I get a pop-up window saying "This application has failed to start because B.dll was not found. Re-installing the application...

where is the hid.lib file in windows?

I'm doing some HiD programming and I'm trying to locate HiD.lib file to add to my .pro Qt file. However I can't find it. Below is an excerpt of said file: win32:LIBS+=-lSetupAPI.lib -L"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib" \ -lKernel32.lib -L"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib" \ -lHi...

How to use .Net System.IO; System.Net; System.Net.Sockets; from Visual Studio C++ project?

How to use .Net System.IO; System.Net; System.Net.Sockets; libs from Visual Studio C++ project? ...

Performance of C++ calls to Java code vs C# code

I am exploring a solution at my client where we have to call an API that is available in both C# and Java from our C++ application. We would like this to be a cross platform application (PC & Mac), so Java is preferred, but performance is more important. I've been trying to do some research on the performance of C++ calls to C# vs Java...

class to class conversion using constructor+inheritance in C++

Hello Every one. Here I can do conversion from emp class object to emp class object. But I can't do conversion from employee class object to emp class object - I have added comment where I am getting error - 'setEmpID' is not a member of 'employee'. what should I do to resolve this error ? ( I am just preparing for C++ exam & this is t...

c++ what is the advantage of lex and bison to a selfmade tokenizer / parser

Hi, I would like to do some parsing and tokenizing in c++ for learning purposes. Now I often times came across bison/yacc and lex when reading about this subject online. Would there be any mayor benefit of using those over for instance a tokenizer/parser written using STL or boost::regex or maybe even just C? ...

Is it possible to transate the wParam parameter into the actual message string?

I am trying to get the actual system messages that are represented by the intergers returned in the wParam property of the message. Is there anyway to do this or a function that can achieve this? ...

Is increased programming efficiency in Java or C# a myth?

A big advantage of Java or C# in increasing productivity of development is that you're supposed to lose less time with complicated language features, especially those related to memory management. But is it just an impression? I think that the learning curve for C++ is definitely more steep, but for a proficient C++ programmer, and give...

Outputting a vector of string objects to a file

I'm trying to output a vector of string objects to a file. However, my code only outputs the first two elements of each string. The piece of code below writes: 1 1 to a file. Rather then: 01-Jul-09 01-Jul-10 which is what I need. ofstream file("dates.out"); vector<string> Test(2); Test[0] = "01-Jul-09"; Test[1...

Out of Process COM Server - can't create file

I'm attempting to run the following piece of code from an Out-of-Process COM Server in its main thread, however no file is ever created. I wondered if anyone can tell me why this is? FILE *f = fopen("Log.txt", "w"); fputs("Tony", f); fputs("\n", f); fclose(f); ...