c++

How to fix heap corruption

I've tried to build a very minimalistic memory read library to read some unsigned ints out of it. However, I run into a "HEAP CORRUPTION DETECTED" error message when the ReadUnsignedInt method wants to return. HEAP CORRUPTION DETECTED. CRT detected that the application wrote to memory after end of buffer. As I have read, this may b...

How to fix a C1010 error without turning off precompiled headers?

So, I have to use precompiled headers in my VS 2005 project. Now I have a shared source file that does not have a #include "stdafx.h"... How can I include the shared source file in my project without adding stdafx.h to the top of the source file and without turning off precompiled headers?? ...

Inheritance and templates in C++ - why are methods invisible?

When a template publicly inherits from another template, aren't the base public methods supposed to be accessible? template <int a> class Test { public: Test() {} int MyMethod1() { return a; } }; template <int b> class Another : public Test<b> { public: Another() {} void MyMethod2() { MyMethod1(); } }; int ...

Linking error: Missing symbol but symbol exported (in exp and lib)

Hi all! I have a dynamic library (plugin) that uses another dynamic library (dependency). I use the dependency in two ways: a. by instantiating object from classes defined in the dependency b. by inheriting from classes defined in the dependency When doing a., there are no linking errors. But when doing b., I have a linking error stati...

Why is the compiler not selecting my function-template overload in the following example?

Given the following function templates: #include <vector> #include <utility> struct Base { }; struct Derived : Base { }; // #1 template <typename T1, typename T2> void f(const T1& a, const T2& b) { }; // #2 template <typename T1, typename T2> void f(const std::vector<std::pair<T1, T2> >& v, Base* p) { }; Why is it that the followin...

Passing template classes as arguments to methods...

I have a class method with a signature like this: // someheader.h class Blah { ... void DoSomeWork(class Screen& p); .. }; The Screen class however is supposed to turn into a template now, something like... template <int width, int height> class Screen { ... So my question is, how should I change the method's prototype in somehea...

Visual Studio 2008 (C++) memory leak detection not showing file/method location - how to get that to work?

I am using the instructions found here to try to find memory leaks in a Win32 application. As described, I put the #define _CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h> Lines at the top of a file (the cpp file that contains WINAPI _tWinMain) and then at the exit point of winmain I added _CrtDumpMemoryLeaks(); Unfortu...

C++ Parent class method call

I'm creating a new class that inherits queue from the STL library. The only addition to the class is a vector. This vector will have the same size of the queue and it will store some integer values that will correspond to each objects in the queue. Now, I want to override pop() and push(), but I simply want to add more functionality to ...

'operater new': redefinition, different linkage (using _dllspec on redefined new operator)

I am using __declspec(dllimport/export) on a debug version of new as such: #ifdef _DEBUG DECLSPECCORE extern void* operator new(unsigned int size, const char* file, int line); extern void* operator new[](unsigned int size, const char* file, int line); extern void operator delete(void* address, const char* file, int line); extern v...

Would like to make a php get_include_files() enhancements

I am interested in making an application that can automatically determine what files are included in php. What I'm getting at is that I would like to make either a C/C++ or a C# application that runs in the background and as you're developing on your local machine, it can display included files by php as you launch pages running on you...

Test::operator new

Hi everybody: I tried to implement this: namespace Test { void* operator new(size_t s) { return malloc(s); } } But g++ (4.3.1) says: void* Test::operator new(size_t)’ may not be declared within a namespace Am I doing something wrong? If yes, is there anyway to overload the operator new to be used in my classes...

Under what conditions will you get unresolved external symbol for __declspec(dllimport)?

I am converting an application to use .dlls and I'm riddled with linker errors stating unersolved external symbol"__declspec(dllimport) public: void __thiscall Rail::SetNextrail(class Rail *)" There is more gibberish at the end of this error message. Why should this happen and how do you fix it? __declspec(dllimport) is be...

Convert RGB IplImage to 3 arrays

I need some C++/pointer help. When I create an RGB IplImage and I want to access i,j I use the following C++ class taken from: http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html template<class T> class Image { private: IplImage* imgp; public: Image(IplImage* img=0) {imgp=img;} ~Image(){imgp=0;} ...

Should I implement my own TCP/IP socket timeouts?

The software I'm working on needs to be able to connect to many servers in a short period of time, using TCP/IP. The software runs under Win32. If a server does not respond, I want to be able to quickly continue with the next server in the list. Sometimes when a remote server does not respond, I get a connection timeout error after roug...

How to make gcc or ld report undefined symbols but not fail?

If you compile a shared library with GCC and pass the "-z defs" flag (which I think just gets passed blindly on to ld) then you get a nice report of what symbols are not defined, and ld fails (no .so file is created). On the other hand, if you don't specify "-z defs" or explicitly specify "-z nodefs" (the default), then a .so will be pro...

How to convert Euler angles to directional vector?

So I have a pitch, roll, and yaw angles... I want to convert these to a directional vector. Bonus points if you can give me a quaternion and/or matrix representation of this! Thanks! ...

What are some rules with included headers?

I keep running into problems the larger my program gets. For instance, I get the following error: In file included from WidgetText.h:8, from LCDText.h:17, from WidgetText.cpp:13: Generic.h:21: error: expected class-name before ',' token Here are those lines: #include "Generic.h" // WidgetText.h:8 #i...

How to define (non-method) functions in header libraries

When writing a header library (like Boost), can one define free-floating (non-method) functions without (1) bloating the generated binary and (2) incurring "unused" warnings? When I define a function in a header that's included by multiple source files which in turn is linked into the same binary, the linker complains about redefinition...

Why isn't the gcc 4.x.x series compilers installed by MinGW by default?

Currently, MinGW's only installs the 3.x.x series of the gcc compiler by default. However, it looks like the 4.x.x series of compilers have been out for some time, and as others have mentioned, it seems to work just fine. Is there any reason why it hasn't moved to the 4.x.x versions yet, and any reason why I shouldn't use the newer ver...

Getting directory structure in windwos mobile

Is there a way to get the directory structure in windows mobile in C++? There is no folder browse dialog in MFC or in win32 for the windows mobile so I searched for a way to get the directory structure inside the code and even this seems difficult to find. These operations are very easy to perform in .NET compact framework but the appl...