c++

Const reference to temporary

After reading this article on Herb Sutter's blog, I experimented a bit and ran into something that puzzles me. I am using Visual C++ 2005, but I would be surprised if this was implementation dependent. Here is my code: #include <iostream> using namespace std; struct Base { //Base() {} ~Base() { cout << "~Base()" << endl; } };...

Process Synchronization by detecting file open (creation)

There are two applications. The first application is remote to the machine in question (and I have NO ACESSS to it) and creates a large file via the network (LAN). I have no control over this process, nor do I know when it occurs. THIS IS WHAT I HAVE TO WORK WITH. I cannot add, change or alter this in any way. The second application is ...

C++ getters/setters coding style

Hi, I have been programming in C# for a while and now I want to brush up on my C++ skills. Having the class: class Foo { const std::string& name_; ... }; What would be the best approach (I only want to allow read access to the name_ field): use a getter method: inline const std::string& name() const { return name_; } make...

Is it legal to write to std::string?

In std::string there are only const members to fetch the data like c_str(). However I can get a reference to the first element of the string via operator[] and I can write to it. For example, if I have function: void toupper(char *first,char *last_plus_one); I can write directly to vector getting a pointer to the first element: vect...

Get Thumbnail of background window

I'm trying to get thumbnail pictures of windows that are not visible. Here's the code I have so far BOOL CALLBACK WindowProc(HWND hWnd, LPARAM lParam) { RECT WindRect; GetWindowRect(hWnd, &WindRect) CurrentScreenShot->Next = new ScreenShotList(); CurrentScreenShot = CurrentScreenShot->Next; HDC SourceDC = GetDC(hWn...

How do you "refactor" ant build.xml files ?

I'm working on a large C++ system built with ant+cpptasks. It works well enough, but the build.xml file is getting out of hand, due to standard operating procedure for adding a new library or executable target being to copy-and-paste another lib/exe's rules (which are already quite large). If this was "proper code", it'd be screaming o...

XML Serialization of DOM Portions with Xerces C++

I've been struggling quite a bit with Xerces C++ and my unfamiliarity with all that is XML, but I need to use XML for a project I'm working on. My question is how do I serialize portions of a DOM tree that I have already parsed and created of out of a XML instance document (validated against a schema I wrote) so that I can create many n...

What is the naming convention when typdef complex STL maps?

1) What is the convention used in practice when typedef'ing something like typedef std::map<SomeClass*, SomeOtherClass> [SomeStandardName>] typedef std::map<SomeClass*, std<SomeOtherClass> > <[omeStandardName] 2) Where do you usually put typedef: header files globally, local to the class? 3) Do you typedef iterators or const map<...

tool to generate xml file from xsd (for testing)

I have an xsd file and have not done much xml manipulation, parsing, etc. I want/need test xml files for my code but don't have any samples. (I am using xerces to parse) This is similar to: xml-instance-generation-from-xml-schema-xsd but I don't really want to make it a two step process. (python or java) I just want to feed xsd fi...

Converting Between Local Times and GMT/UTC in C/C++

What's the best way to convert datetimes between local time and UTC in C/C++? By "datetime", I mean some time representation that contains date and time-of-day. I'll be happy with time_t, struct tm, or any other representation that makes it possible. My platform is Linux. Here's the specific problem I'm trying to solve: I get a pair ...

error: cast from 'const prog_uchar*' to 'byte' loses precision?

The error is at this line : dataArray[iLedMatrix][iRow] |= (byte)(bufferPattern[iRow]) & (1<<7); dataArray is : byte dataArray[NUMBER_LED_MATRIX][NUMBER_ROW_PER_MATRIX]; bufferPattern is : const patternp * bufferPattern; patternp is a typedef of the type : typedef prog_uchar patternp[NUM_ROWS]; I can see in the Reference that pro...

Handling a class with a long initialization list and multiple constructors?

I have a (for me) complex object with about 20 data member, many of which are pointer to other classes. So for the constructor, I have a big long, complex initialization list. The class also has a dozen different constructors, reflecting the various ways the class can be created. Most of these initialized items are unchanged between each...

Getting Object Functionallity out of C++ code in C#

I have have a function in wrote in C++ that calls some functions in a old lib. This function creates some memory makes the calls and destroys the memory. To optimize this I would create an object that would keep the memory allocated until the object was destroyed. However I'm going to be calling this function from C# and don't believe I ...

Advice for final year CS project.

I'm in the final year of university education. Soon I'll have to start writing my bachelor dissertation, but I have no idea what software I should write for it. The ideal would be a C++ multi-threaded cross-platform (windows, linux) computer graphics related program. It's also very important to pick project I'll be able to complete - fa...

Server Design and Implementation

I've work in embedded systems and systems programming for hardware interfaces to date. For fun and personal knowledge, recently I've been trying to learn more about server programming after getting my hands wet with Erlang. I've been going back and thinking about servers from a C++/Java prospective, and now I wonder how scalable syste...

Pointer Issues.. ( C++ )

Just when I thought I had it figured out, I get an exception handling error. Problem: The problem is that the private members lose the information outside of the constructor. Here's my class definition Code: class ClassType { private: char *cPointer; int length; public: ClassType(); ...

Pointer Issues 2 [Valid C++ Syntax]

This version is working. I've made // comments throughout my code to better illustrate what I am having trouble with. The program is dependent on reading a text file. In the format of paragraphs with punctuation included. One could copy this and the above into a text file and run the program. // Word.cpp #define _CRT_SECURE_NO_WARNING...

C/C++ replacement/redefinition rules?

I am not particularly new to C/C++ but today I discovered some things that I didn't expect. This compiles in gcc: /* test.c */ #include <stddef.h> // ! typedef unsigned long int size_t; // NO ERROR typedef unsigned long int size_t; // NO ERROR int main(void) { typedef unsigned long int size_t; // NO ERROR return 0; } This doesn...

C++ friend classes

Hi, I realize that there are a lot of questions regarding friend classes in C++. My question, though, is tied to a specific scenario. Given the below code, is it appropriate to use friend in such a manner? class Software { friend class SoftwareProducer; SoftwareProducer* m_producer; int m_key; // Only producers can pro...

how we can ensure caching to reduce file-system write cycle for SQLite databases

Hello, I would like to know how we can implement cashing in sqlite database.My primary objective is write data to ram and after when cache is filled i want to flush all the data to disk database.Whether it is possible? if yes Can i get any sample codes? Thanks Aneesh ...