c++

valgrind report memory leak when assign a value to a string

Valgrind report memory leak when assign a value to a string I used this simple code to test an memory leak reported by valgrind. /****************************************** * FILE: t3.c * Compiled using : g++ -g t3.c -o t3 * * $ g++ -v * Reading specs from /usr/lib/gcc/i686-pc-linux-gnu/3.4.6/specs * Configured with: ./configure --pre...

Min and Max values for integer variable at compile time in C++

Is there a simple, clean way of determining at compile time the max and min values for a variable of some (otherwise unknown at the moment) integer variable or type? Using templates? For example: // Somewhere in a large project is: typedef unsigned long XType; typedef char YType; // ... // Somewhere else XType a; YType b; LON...

C++ Data Timeout with Blocking Call

I have a main loop which is fully data-driven: it has a blocking call to receive data and stores it as the 'most recent' (accessed elsewhere). Each piece of data has an associated lifespan, after which the data timesout and can no longer be considered valid. Each time I receive data I reset the timeout. Unfortunately I can currently onl...

Implicit invocation of operator [C++]

Hi, I defined two classes: class Token_ { public: virtual char operator*()const = 0;//this fnc cannot run implicitly protected: Token_() { } Token_(const Token_&); Token_& operator=(const Token_&); }; and second: class Operator : public Token_ { public: Operator(const char ch):my_data_(token_cast<Opera...

SSE2 - "The system cannot execute the specified program"

I recently developed a Visual C++ console application which uses inline SSE2 instructions. It works fine on my computer, but when I tried it on another, it returns the following error: The system cannot execute the specified program Note that the program worked on the other computer before introducing the SSE2 code. Any suggestions? ...

Does the visual studio 2008 profiler work with unmanaged C++?

I know that VS 2008 Team Edition has a profiler, but I'm also aware of the recent trend they have at Microsoft of completely ignoring unmanaged languages (what's the last time unmanaged C++ got something cool in the IDE?!).. For example I know for a fact that the IDE "Unit Tests" and "Code Metrics" features don't work with unmanaged code...

problem sorting using member function as comparator

trying to compile the following code I get this compile error, what can I do? ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. class MyClass { int * arr; // other member variables MyClass() { arr = new int[someSize]; } doCompa...

All users path?

In C# I can do the following: DirectoryInfo di = new DirectoryInfo(System.Environment.GetEnvironmentVariable("ALLUSERSPROFILE")); Which will get me the path to the all users profile. In C++ I can use the SHGetFolderPath, but it does not seem to have a CSLID for all users. Is there an equlivant function that I can blow the %ALLUSERSPR...

Is there a better way to bring names into class scope other than to typedef them?!

I keep running into this issue: class CCreateShortcutTask : public CTask { public: CCreateShortcutTask( CFilename filename, // shortcut to create (or overwrite) Toolbox::Windows::CShellLinkInfo definition // shortcut definition ) ... Having to spell out Toolbox::Windows::CShellLinkInfo...

c++ Namespace headaches...

Okay, this question has evolved a bit, and I want to try to start (over) with the basic goals I'm shooting for: Create library code that wrappers legacy C-language entities in C++ resource acquisition is initialization and also provides basic or better exception guarantee. Enable clients of this code to use it in a very natural C++ fas...

expand file names that have environment variables in their path

What's the best way to expand ${MyPath}/filename.txt to /home/user/filename.txt or %MyPath%/filename.txt to c:\Documents and settings\user\filename.txt with out traversing the path string looking for environement variables directly? I see that wxWidgets has a wxExpandEnvVars function. I can't use wxWidgets in this case, so I was...

checking whether a particular element exists or not in a c++ STL vector

I wanted to check whether an element exist at a particular vector location, say i, before accessing it like v[i]. Could you let me know how can I do that? Thank you. ...

What shall I do while waiting in a thread.

I have a main program which creates a collection of N child threads to perform some calculations. Each child is going to be fully occupied on their tasks from the moment their threads are created till the moment they have finished. The main program will also create a special (N+1)th thread which has some intermittent tasks to perform. Wh...

C++ template specialization of constructor

I have a templated class A<T, int> and two typedefs A<string, 20> and A<string, 30>. How do I override the constructor for A<string, 20> ? The following does not work: template <typename T, int M> class A; typedef A<std::string, 20> one_type; typedef A<std::string, 30> second_type; template <typename T, int M> class A { public: A(...

resize versus push_back in std::vector : does it avoid an unnecessary copy assignment?

Hello people. When invoking the method push_back from std::vector, its size is incremented by one, implying in the creation of a new instance, and then the parameter you pass will be copied into this recently created element, right? Example: myVector.push_back(MyVectorElement()); Well then, if I want to increase the size of the vecto...

How to make CFileDialog synchronize the displayed filename with the selected extension?

We have a class that derives from CFileDialog that overrides the OnTypeChange() method to allow it to change the filename to keep it in synch with the selected extension whenever the user selects a new extension from the filter combobox. (Our filters are set to contain only one extension per filter entry.) Unfortunately, the way we are d...

MSVC - Any way to check if function is actually inlined?

Hi, I have to check whether a function is being inlined by the compiler. Is there any way to do this without looking at assembly (which I don't read). I have no choice in figuring this out, so I would prefer if we could not discuss the wisdom of doing this. Thanks! ...

Why not call FreeLibrary from entry point function?

I'm writing a DLL that needs to call a separated DLL dynamically multiple times. I would like to keep the callee loaded and then just unload it when my DLL is unloaded. But according to Microsoft, that's a bad idea. The entry point function should only perform simple initialization tasks and should not call any other DLL loadin...

Inheriting from a virtual template class in C++

How do I inherit from a virtual template class, in this code: // test.h class Base { public: virtual std::string Foo() = 0; virtual std::string Bar() = 0; }; template <typename T> class Derived : public Base { public: Derived(const T& data) : data_(data) { } virtual std::string Foo(); virtual std::string Bar(); T data()...

Wrapping a PropertySheet; how to handle callbacks?

I'm writing an (unmanaged) C++ class to wrap the Windows PropertySheet. Essentially, something like this: class PropSheet { PROPSHEETHEADER d_header; public: PropSheet(/* parameters */); INT_PTR show(); private: static int CALLBACK *propSheetProc(HWND hwnd, UINT msg, LPARAM lParam); }; The constructor just i...