c++

Qt Should I derive from QDataStream?

I'm currently using QDataStream to serialize my classes. I have quite a few number of my own classes that I serialize often. Should I derive QDataStream to create my own DataStream class? Or is there a better pattern than this? Note that these custom classes are used by many of our projects, so maybe doing so will make coding easier. An...

Why is creating a ring buffer shared by different processes so hard (in C++), what I am doing wrong?

I am being especially dense about this but it seems I'm missing an important, basic point or something, since what I want to do should be common: I need to create a fixed-size ring buffer object from a manager process (Process M). This object has write() and read() methods to write/read from the buffer. The read/write methods will be ca...

Handwritten linked list is segfaulting and I don't understand why

Hi I was working on a bit of fun, making an interface to run gnuplot from within c++, and for some reason the my linked list implementation fails. The code below fails on the line plots->append(int> and ll<char*> but for some reason it fails as ll<Plot*>. Could youp please help me figure out why it fails? and perhaps help me understand...

How can I tell if an ADODB::_RecordsetPtr has already been created?

I am trying to write a class that uses ADO to retrieve SQL records. The intent is for the class to maintain one private recordset an other methods move forward, retrieve fields, etc. This is a basic example of my class: class SqlADO { private: ADODB::_RecordsetPtr _recordset; public: void Open(); //open the connection vo...

How to implement pure virtual function in C++

Hi, I think the implementation of virtual function is talked about a lot. My question is what about pure virtual function? However it is implemented? In virtual table, how to tell it is a pure or non-pure? What the difference between pure virtual function and virtual function with implementation? ...

Why the size of a pointer is 4bytes in C++

Hi On the 32-bit machine, why the size of a pointer is 32-bit? Why not 16-bit or 64-bit? What's the cons and pros? ...

Creating CMFCDesktopAlertWnd Control in Visual C++

Hello, MSDN contains an example for creating a desktop alert window: http://msdn.microsoft.com/en-us/library/bb983515.aspx The sample code starts with the following declaration. CMFCDesktopAlertWnd* pPopup = new CMFCDesktopAlertWnd; When I use it in my code, the compiler complains 'CMFCDesktopAlertWnd' : no appropriate default cons...

How to declare a pointer to a variable as a parameter of a function in C++?

I have a function that takes a const D3DVECTOR3 *pos, but I have no reason to declare this beforehand. The most logical solution to me was using new: Function( //other parameters, new D3DXVECTOR3(x, y, 0)); but I don't know how I would go about deleting it, beign intitialized in a function. My next thought was to use the & o...

Can't write a binary file

I have the following piece of code in C++. int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; ofstream output("Sample.txt", ios::out | ios::binary); for(int i = 0; i < 10; i++) { output<<arr[i]; } Now the Sample.txt is like this: 12345678910 Isn't the "Sample.txt" supposed to be in binary? Why doesn't it convert everything into binary...

Best way to create an application-icon in visual studio c++

In Visual studio I can draw 13 different application-icons in different resolutions and color depths. But do I have to do this, or is there a way to automatically produce all low-res icons from one single hi-res icon? ...

C++ freeing static variables

Hi all, I would like my class to have a static pointer to a dynamically allocated region of memory. I understand how to initialize it - in my case I will initialize it when the first object needs it. However, I don't know when/where in the code to free it. I'd like to free it when the program terminates. I might be able to free the ...

Converting QXmlItem to QtDomElement or similar?

Hello everyone. I'm parsing a fairly complicated XML file of the following structure: <root> ... ... <item> <subitem id="1"/> <text> text1 </text> </item> <item> <subitem id="2"/> <text> text2 </text> </item> ... <item> ... </item> ...</root> It's pretty c...

How do I parse end-of-line with boost::spirit::qi?

Shouldn't a simple eol do the trick? #include <algorithm> #include <boost/spirit/include/qi.hpp> #include <iostream> #include <string> using boost::spirit::ascii::space; using boost::spirit::lit; using boost::spirit::qi::eol; using boost::spirit::qi::phrase_parse; struct fix : std::unary_function<char, void> { fix(std::string &result...

C++ Managing Shared Object's Handle issues

Is there best practice for managing Object shared by 2 or more others Object. Even when running on different thread? For example A is created and a pointer to it is given to B and C. ObjA A = new ObjA(); B->GiveObj(A); C->GiveObj(A); Now how can I delete objA? So far what I though about is A monitor how many ref there are to it and w...

Passing values through files in C++

Hey everyone, I'm still pretty new to C++, and I've been making progress in making my programs not look like a cluster-bleep of confusion. I finally got rid of the various error messages, but right now the application is crashing, and I have no idea where to start. The debugger is just throwing a random hex location. Thank you in a...

Windows service and mingw

Is there possibility to compile windows service using only mingw c++ compiler and library? I assume that it is possible to use compiler with Visual Studio standard library and means, but want to do to this almost fully opensourced. Any experience? ...

Is having two precompiled headers in the same C++/CLI project a good idea on Visual Studio 2010?

I.e. we use stdafxmanaged.h for all managed source files and stdafx.h for normale Win32 files. The reason I ask is that we have done this with success in VS.NET 2008, but when we upgraded to VS.NET 2010, the compiler always want to delete the PCH files and recompile everything all the time. ...

novice question file read

while(getline(fileIn,line)) { fileOut <<line<<endl; } while(getline(fileIn,line)) { if(fileIn.eof()) break; fileOut <<line<<endl; } i have tried both piece of code and it still reads past and does not break. can anyone tell me why? I am just reading from file and writing to it. thank ...

One template specialization for multiple classes

Let's assume we have a template function "foo": template<class T> void foo(T arg) { ... } I can make specialization for some particular type, e.g. template<> void foo(int arg) { ... } If I wanted to use the same specialization for all builtin numeric types (int, float, double etc.) I would write those lines many times. I know that ...

Is stdin limited in length?

Are there any stdin input length limitations (in amount of input or input speed)? ...