c++

Is it possible to use (some) AOP concepts in existing C++ programs without complete refactoring?

I am reading on AOP now and would like to use (some) AOP ideas and approaches in my code. I don't have any third-party extensions, just MSVS 2005 environment. So, is it possible to benefit from AOP concepts in my day-to-day work without complete refactoring of the existing code (2-year old project x 5 programmers)? ...

How to copy the contents of std::vector to c-style static array,safely ?

I need to manipulate data in fixed array involving mid insertion. Rather than using memcpy,etc. I want to use vector. I have problem when I want to copy the vector elements back to the c-style array. Here's the code: void tryvector() { using namespace std; const int MAX_SIZE=16; BYTE myarr[MAX_SIZE]={0xb0,0x45,0x47,0xba,0x11...

Declaring class objects in a header file

Greetings everyone. I seem to be snagging on a fundimental but I cant find the solution anywhere. Anywho, will go ahead and explain. I have a program consisting of three files; main.ccp, add.h, add.cpp. I declare the class 'SA' in add.h and have all my functions defined in add.cpp additional.h class SA { ... public int x; } ...

Shouldn't Gdiplus::Image::GetWidth() and a bunch of other getters be "const"?

Why aren't they const? I believe that's flawed API design. Or am I missing something? UINT GetWidth(); UINT GetHeight(); ... vs. UINT GetWidth() const; UINT GetHeight() const; ... ...

Algorithm for Counting Sorted Strings (Homebrew "uniq -c")

Hi all, I have the following already sorted data: AAA AAA TCG TTT TTT TTT I want to count the occurrence of each string yielding AAA 2 TCG 1 TTT 3 I know I can do that with "uniq -c", but here I need to do extra processing on the overall C++ code I have. I am stuck with this construct (modified according to 'pgras' suggestion) #...

std::copy to std::cout for std::pair

I have next code: #include <iostream> #include <algorithm> #include <map> #include <iterator> //namespace std //{ std::ostream& operator << ( std::ostream& out, const std::pair< size_t, size_t >& rhs ) { out << rhs.first << ", " << rhs.second; return out; } //} int main() { std::map < size_t, size_t > some_map; ...

Complete solution for writing Mac OS X application in C++

I am looking for alternatives for my current box and Mac OS X seems very appealing. My main area of interest is C++ programming. Currently I'm using Eclipse + CDT and g++ for creating my software; sometimes it is KDevelop. I know that primary IDE for Mac is Xcode and primary language is Objective-C. I would like to avoid learning Objec...

How can I extract frames from videos (using DirectShow)?

I have to extract the frames from any video file that can be played using the standard windows media player into separate images. Can you provide me some info on how to proceed, what documentation/books to read, etc? The language is C/C++. Also, don't recommend any solution which involves GPL code, the software I have to work on is pro...

Non-static const member, can't use default assignment operator

A program I'm expanding uses std::pair<> a lot. There is a point in my code at which the compiler throws a rather large: Non-static const member, 'const Ptr<double, double> std::pair<const Ptr<double, double>, const double*>::first' can't use default assignment operator I'm not really sure what this is referring to? Which methods are...

Converting indexed polygons to unindexed ones. Several problems have cropped up.

Yet again I have some questions regarding polygon algorithms. I'll try to explain my problem: I am using a subset of a third party library called Geometric Tools(GT) to perform boolean operations on my polygons. To accomplish this I have to convert my internal polygon format to the format GT uses. Our internal polygon format consists...

C++ Header files - put them in one directory or merged in a tree structure?

I have a substantial body of source code (OOFILE) which I'm finally putting up on Sourceforge. I need to decide if I should go with a monolithic include directory or keep the header files with the source tree. I want to make this decision before pushing to the svn repo on SourceForge. I expect a lot of people who use it after that move...

C++ OpenSource project for beginner programmer?

I`m a beginner C++ programmer. And I want to pursue my career in system- and driver-programming. Can you suggest me an opensource projects to I improve my skills in low-level development? I am looking for a project with the following characteristic: - on C\C++ language based - a small project with a small amount of code, yet - UNIX-ba...

A good bank of solved recursion problems in C/C++/Java/C#

I saw this question, but the answers there are not very relevant. A friend needs a bank of solved recursion problems to help him study for a test tomorrow. He learned the issue theoretically, but is having problems grasping how to actually solve recursion problems. Do you know a good source of solved recursion problems (preferably in C,...

Turn off XP Theme in VS2008 compiled MFC App

We've just recently switched our C++ MFC Application from VS2005 to VS2008. Unfortunately in doing so our UI has appearance problems, with things like group boxes appearing blue rather than black, properties dialogs having a white background etc. I presume that in VS2008, MFC has been changed to respect the OS theme (in my case XP defaul...

Best Language for String Manipulation?

I am about to begin writing an app that handles adding new users/repostories to my subversion server, so that I don't have to repeatedly open vi and edit conf files and execute shell commands. Most of my experience centers around C, C++, Objective-C and Java. Java seems decent for string manipulations with its tokenizer class, however I...

How do I call a member function pointer using a pointer to a constant object?

Here is an example of what I want to accomplish and how: class MyClass { public: void Dummy() const{} }; typedef void (MyClass::*MemFunc)(); void (const MyClass * instance) { MemFunc func=&MyClass::Dummy; // (instance->*func)(); //gives an error (const_cast<MyClass *>instance->*func)(); // works } ...

Simple Thread Synchronization

I need a simple "one at a time" lock on a section of code. Consider the function func which can be run from multiple threads: void func() { // locking/mutex statement goes here operation1(); operation2(); // corresponding unlock goes here operation3(); } I need to make sure that operation1 and operation2 alwa...

What is the best way to declare a global variable?

In C++, say you want to declare a global variable to be used by many. How do you do it? I commonly use declare and define in cpp file, and then use extern in other cpp file (and not headers). I don't like this approach, and I am considering something along these lines: In a header file: some_file.h Class MYGlobalClass { }; MyGl...

How to find a method in assembly code

From a memory leak log I have the following info: TestApp.exe! + 2238ch Let us say this means that method at offset '2238c' (hex value) is leaking. How can I locate the corresponding method in my source code? I have the linker map (testapp.map) but not sure how to use it. This is a C++ application compiled in VS2008. ...

Why does my Boost.Regex search report only one match iteration?

I am trying to find out how many regex matches are in a string. I'm using an iterator to iterate the matches, and and integer to record how many there were. long int before = GetTickCount(); string text; boost::regex re("^(\\d{5})\\s(\\d{8})\\s(.*)\\s(.*)\\s(.*)\\s(\\d{8})\\s(.{1})$"); char * buffer; long length; long count; ifstream ...