c++

C# data allocation problem

Hello, I have the following problem. I have a C++ dll, containing the function void cpp_send (void *data_, size_t size_, free_fn *ffn_) { //sends data } then I have C# dll that has a class public class CS_dll : IDisposable { void cs_send (void *data) { IntPtr ptr = Marshal.AllocHGlobal (data.Length); Marshal...

using of std::accumulate

Need prettier solution of below example but with std::accumulate. #include <algorithm> #include <vector> #include <iostream> class Object { public: Object( double a, double b ): a_( a ), b_( b ) {} double GetA() const { return a_; } double GetB() const { return b_; } // other methods private: do...

A proper way to create a matrix in c++

I want to create an adjacency matrix for a graph. Since I read it is not safe to use arrays of the form matrix[x][y] because they don't check for range, I decided to use the vector template class of the stl. All I need to store in the matrix are boolean values. So my question is, if using std::vector<std::vector<bool>* >* produces too mu...

Registering each C/C++ source file to create a runtime list of used sources

For a debugging and logging library, I want to be able to find, at runtime, a list of all of the source files that the project has compiled and linked. I assume I'll be including some kind of header in each source file, and the preprocessor __FILE__ macro can give me a character constant for that file, so I just need to somehow "broadcas...

openGL glDrawElements with interleaved buffers

Thus far i have only used glDrawArrays and would like to move over to using an index buffer and indexed triangles. I am drawing a somewhat complicated object with texture coords, normals and vertex coords. All this data is gathered into a single interleaved vertex buffer and drawn using calls similar to ( Assuming all the serup is done c...

How can I make my own C++ compiler understand templates, nested classes, etc. strong features of C++?

It is a university task in my group to write a compiler of C-like language. Of course I am going to implement a small part of our beloved C++. The exact task is absolutely stupid, and the lecturer told us it need to be self-compilable (should be able to compile itself) - so, he meant not to use libraries such as Boost and STL. He also do...

How can I make networking work in my WinCE app without launching IE first?

I have a simple WinCE network application (in C, Win32 APIs). I find that networking doesn't seem to work unless I launch IE (or another network app) first. I assume that IE is setting up my network interface in some way. How can I do this for myself? Might I need to display a list of available interfaces to the user (eg. WiFi/Ethernet...

Qt for Delphi developers

Does someone know of a book or tutorial explaining Qt for Delphi / C++ Builder / VCL developers? What would be the best approach for a developer with that background to learn Qt? I'm particulary interested in how to accomplish things that I know how to do in Delphi with Qt. For example, what is the Qt equivalent to Delphi Frames? What...

Macro to replace C++ operator new

Is it possible to create macros to replace all forms of operator new with overloads that include additional args...say __FILE__ and __LINE__? The trouble appears to be that operator new can either be coded with or without parentheses, therefore: object-like macros: #define new new(__FILE__, __LINE__) will replace declarations like:...

Debugging multithreaded applications

I have an application written in C++ and MFC which is multithreaded running on windows. Occasionally I do get some complaints such as deadlocks or an unhandled exception which is caused because of these threads. Normally I use visual studio (if the problem is reproducible) or else use the WinDbg to analyse the dump files generated. Is th...

Do the parentheses after the type name make a difference with new?

If 'Test' is an ordinary class, is there any difference between: Test* test = new Test; //and Test* test = new Test(); ...

Why do C++ templates let me circumvent incomplete types (forward declarations)?

I tried three iterations of the following simple program. This is a highly simplified attempt to write a container-and-iterator pair of classes, but I was running into issues with incomplete types (forward declarations). I discovered that this was in fact possible once I templatized everything - but only if I actually used the template...

How to detect PowerPoint 2007 from a C++ addin?

I need to detect if my addin is in PowerPoint 2007 via my C++ addin. The PowerPoint object model exposes Application.Version, which should work, but I do not know enough about how to use this with IDispatch. How to detect PowerPoint 2007 from a C++ addin? ...

difference between a pointer and reference parameter?

Are these the same: int foo(bar* p) { return p->someInt(); } and int foo(bar& r) { return r.someInt(); } Ignore the null pointer potential. Are these two functions functionally identical no matter if someInt is virtual or if they are passed a bar or a subclass of bar? Does this slice anything: bar& ref = *ptr_to_bar; -cory ...

Screen ratio distorted in Windows MFC application in VMware

I have a C++ MFC application that uses DPtoLP to calculate logical coordinates from device coordinates. Normally this works fine. I have a screen with square pixels. It is 1280x1024. My VMware runs W2K, with a resolution set to 800x480. In the program the MapMode is MM_LOMETRIC. My OnDraw code: void CMyView::OnDraw(CDC* pDC) { // TE...

C++: Rotating a vector around a certain point

Hi All, I have a very simple question. I am trying to rotate a vector around a certain point on the vector(in C++): 1 2 3 4 5 6 7 8 9 rotated around the point (1,1) (which is the "5") 90 degrees would result in: 7 4 1 8 5 2 9 6 3 Right now I am using: x = (x * cos(90)) - (y * sin(90)) y =(y * cos(90)) + (x * sin(90)) But I do...

Compiling C++ program on Windows XP

I have a problem running a simple Hello-world program in C++ on my Windows XP. I have written a post here: Using the g++ C++ compiler from cygwin where I stated the problem and I received many helpful replies, which solved some things. However, I still cannot run my hello-world program. Please, have a look at the post, I have inclu...

Function-wide exception handling in c++ - is it a bad style?

There is a try-catch thing about functions, which I think sometimes may be quite useful: bool function() try { //do something } catch(exception_type & t) { //do something } So the first part of the question: is this style considered bad in general case? And the concrete example I used this approach in: We had project with q...

How do I create an array of pointers?

I am trying to create an array of pointers. These pointers will point to a Student object that I created. How do I do it? What I have now is: Student * db = new Student[5]; But each element in that array is the student object, not a pointer to the student object. Thanks. ...

How to put assert into release builds in C/C++

I need to only run ship build and I need to assert on certain condition in release build to see if the problem is fixed. How do I do it? ...