question_id
int64
25
74.7M
answer_id
int64
332
74.7M
title
stringlengths
20
150
question
stringlengths
23
4.1k
answer
stringlengths
20
4.1k
369,788
371,717
How to SetFocus to a CButton so that the border and focus dotted line are visible?
I created a simple dialog-based application, and in the default CDialog added three buttons (by drag-and-dropping them) using the Visual Studio editor. The default OK and Cancel buttons are there too. I want to set the focus to button 1 when I click button 3. I set the property Flat to true in the properties for muy b...
This draws the thick border around the button: static_cast<CButton*>(GetDlgItem(IDC_BUTTON1))->SetButtonStyle(BS_DEFPUSHBUTTON); A more elegant way to do this would be to define a CButton member variable in CbuttonfocusDlg and associate it to the IDC_BUTTON1 control, and then calling this->m_myButton.SetButtonStyle(BS...
369,948
370,172
Event-driven simulation class
I am working through some of the exercises in The C++ Programming Language by Bjarne Stroustrup. I am confused by problem 11 at the end of Chapter 12: (*5) Design and implement a library for writing event-driven simulations. Hint: <task.h>. ... An object of class task should be able to save its state and to have tha...
Hint: <task.h>. is a reference to an old cooperative multi-tasking library that shipped with early versions of CFront (you can also download at that page). If you read the paper "A Set of C++ Classes for Co-routine Style Programming" things will make a lot more sense. Adding a bit: I'm not an old enough programmer t...
370,250
370,316
How to debug COM object in Visual Studio 6.0 that is created in an ASP page?
I have an old C++ COM component which has to stay in Visual Studio 6.0 format. I can't for the life of me figure out how to debug the code in the actual COM component. I'm able to build it in debug mode, add breakpoints and attach it to the dllhost.exe process, but the Visual Studio environment will only show me the d...
If it is a VB6 based COM component, you can open the project in VB6 and run it (a DLL project cannot be run). The project properties has some option whereby it can be asked to run so that it runs & registers itself. Now, try hitting the ASP page, which makes a call to COM component. The breakpoints set in the class fil...
370,283
370,311
Why can't I have a non-integral static const member in a class?
I noticed C++ will not compile the following: class No_Good { static double const d = 1.0; }; However it will happily allow a variation where the double is changed to an int, unsigned, or any integral type: class Happy_Times { static unsigned const u = 1; }; My solution was to alter it to read: class Now_Good { ...
The problem is that with an integer, the compiler usually doesn't have to ever create a memory address for the constant. It doesn't exist at runtime, and every use of it gets inlined into the surrounding code. It can still decide to give it a memory location - if its address is ever taken (or if it's passed by const ...
370,366
370,373
Why put the constant before the variable in a comparison?
I noticed for a while now the following syntax in some of our code: if( NULL == var){ //... } or if( 0 == var){ //... } and similar things. Can someone please explain why did the person who wrote this choose this notation instead of the common var == 0 way)? Is it a matter of style, or does it somehow affect per...
It's a mechanism to avoid mistakes like this: if ( var = NULL ) { // ... } If you write it with the variable name on the right hand side the compiler will be able catch certain mistakes: if ( NULL = var ) { // not legal, won't compile // ... } Of course this won't work if variable names appear on both sides of t...
370,543
372,549
Combining two PDF files in C++
In C++ I'm generating a PDF report with libHaru. I'm looking for someway to append two pages from an existing PDF file to the end of my report. Is there any free way to do that? Thanks.
Try PoDoFo http://podofo.sourceforge.net/ You should be able to open both of the PDFs as PDFMemDocuments using PDFMemDocument.Load( filename ). Then, acquire references to the two pages you want to copy and add to the end of the document using InsertPages, or optionally, remove all but the last two pages of the sourc...
371,018
371,052
Create modified HFONT from HFONT
I using the Win32 API and C/C++. I have a HFONT and want to use it to create a new HFONT. The new font should use the exact same font metrics except that it should be bold. Something like: HFONT CreateBoldFont(HFONT hFont) { LOGFONT lf; GetLogicalFont(hFont, &lf); lf.lfWeight = FW_BOLD; return CreateFon...
You want to use the GetObject function. GetObject ( hFont, sizeof(LOGFONT), &lf );
371,465
371,828
Quadtree vs Red-Black tree for a game in C++?
I have been looking for a quadtree/quadtree node implementation on the net for ages. There is some basic stuff but nothing that I would be able to really use it a game. My purpose is to store objects in a game for processing things such as collision detection. I am not 100% certain that a quadtree is the best data stru...
Quadtrees are used when you only need to store things that are effectively on a plane. Like units in a classic RTS where they are all on the ground or just a little bit above it. Essentially each node has links to 4 children that divide the node's space up into evenly distributed quarters. Octrees do the same but in al...
371,503
374,151
Why is ++i considered an l-value, but i++ is not?
Why is ++i is l-value and i++ not?
Well as another answerer pointed out already the reason why ++i is an lvalue is to pass it to a reference. int v = 0; int const & rcv = ++v; // would work if ++v is an rvalue too int & rv = ++v; // would not work if ++v is an rvalue The reason for the second rule is to allow to initialize a reference using a literal, ...
372,094
372,827
Changing terminalinterface command after showing it on qt/kdelibs app
I have this terminal on my qt/kde application KLibFactory* factory = KLibLoader::self()->factory("libkonsolepart"); KParts::Part* p = static_cast<KParts::Part*> (factory->create(this,"terminal",QStringList() << "terminal")); assert(p); TerminalInterface* terminalInterface= qobject_cast<TerminalInterface*> (p); terminal...
Hola amigo! You can send any command to TerminalInterface prompt with terminalInterface->sendInput("/usr/bin/python\n"); I hope it's will be useful :D
372,198
372,207
Best way for interprocess communication in C++
I have two processes one will query other for data.There will be huge amount of queries in a limited time (10000 per second) and data (>100 mb) will be transferred per second.Type of data will be an integral type(double,int) My question is in which way to connect this process? Shared memory , message queue , lpc(Local...
One Word: Boost.InterProcess. If it really needs to be fast, shared memory is the way to go. You nearly have zero overhead as the operation system does the usual mapping between virtual and physical addresses and no copy is required for the data. You just have to lookout for concurrency issues. For actually sending com...
372,391
377,737
How to automatically sort a QTreeWidget column?
I'm using a QTreeWidget to display some simple items. I've set the list sortable by .setSortingEnabled(true) calling. In this way, the list is sorted only when the user press the title column, and not automatically whenever new item is inserted. Is there a way to force the automatic sorting in a specified column withou...
To do this, use QTreeView::setSortingEnabled() and QTreeView::sortByColumn. Just remember to turn this on /after/ you initially populate the widget, and turn it off again /before/ doing any bulk updates for efficiency.
372,453
372,480
Populate a vector<int> from integers in a char *
char *values = " 3 1 4 15"; vector<int> array; I want to populate the array with the values, 3,1,4,15 Is there a slick way to do it with the stl copy algorithm?
Indeed there is: std::istringstream iss(values); std::copy(std::istream_iterator<int>(iss), std::istream_iterator<int>(), std::back_inserter(array));
372,484
372,491
How do I programmatically check memory use in a fairly portable way? (C/C++)
I'm writing cross platform C++ code (Windows, Mac). Is there a way to check how much memory is in use by the current process? A very contrived snippet to illustrate: unsigned long m0 = GetMemoryInUse(); char *p = new char[ random_number ]; unsigned long m1 = GetMemoryInUse(); printf( "%d bytes used\n", (m1-m0) ); Of c...
There is no portable way to do that. For most Operating systems, there isn't even a reliable way to do it specific to that OS.
372,665
372,673
C++ Instance Initialization Syntax
Given a class like this: class Foo { public: Foo(int); Foo(const Foo&); Foo& operator=(int); private: // ... }; Are these two lines exactly equivalent, or is there a subtle difference between them? Foo f(42); Foo f = 42; Edit: I confused matters by making the Foo constructor "explicit" in the ori...
Foo f = 42; This statement will make a temporary object for the value '42'. Foo f(42); This statement will directly assign the value so one less function call.
372,695
372,922
Is there a standard C++ function object for taking apart a std::pair?
Does anyone know if there's a de-facto standard (i.e., TR1 or Boost) C++ function object for accessing the elements of a std::pair? Twice in the past 24 hours I've wished I had something like the keys function for Perl hashes. For example, it would be nice to run std::transform on a std::map object and dump all the k...
boost::bind is what you look for. boost::bind(&std::pair::second, _1); // returns the value of a pair Example: typedef std::map<std::string, int> map_type; std::vector<int> values; // will contain all values map_type map; std::transform(map.begin(), map.end(), std::back_inserter(values...
372,714
372,756
Problem with a constructor c++
So I have this code for these Constructors of the Weapon class: Weapon(const WeaponsDB * wepDB); Weapon(const WeaponsDB * wepDB_, int * weaponlist); ~Weapon(void); And I keep getting an error: 1>c:\users\owner\desktop\bosconian\code\bosconian\weapon.h(20) : error C2062: type 'int' unexpected and ensuing errors (mor...
#ifndef Weapon #define Weapon This is almost certainly going to cause weirdness; call the constant WEAPON_H instead.
372,862
372,948
C++ programming style
I'm an old (but not too old) Java programmer, that decided to learn C++. But I have seen that much of C++ programming style, is... well, just damn ugly! All that stuff of putting the class definition in a header file, and the methods in a different source file- Calling functions out of nowhere, instead of using methods...
In addition to what others have said here, there are even more important problems: 1) Large translation units lead to longer compile times and larger object file sizes. 2) Circular dependencies! And this is the big one. And it can almost always be fixed by splitting up headers and source: // Vehicle.h class Whe...
373,012
408,302
MFC Edit Box - Multiple Characters per Keystroke?
I am trying to create a simple dialog in MFC using Visual C++. My problem is that when I get the dialog on the screen and try to type in an Edit Box field, if I type the letter 'a' once, it appears in the edit box as 'aaaaaaaaaaa' (that's 12 a's). Furthermore, if I try to navigate around in the box using the arrow ke...
Are you capturing any events such as WM_KEYUP in your PreTranslateMessage() function or anywhere else in your app ? If you have overridden the default handling for keyboard events, it might cause the symptoms you are seeing.
373,462
373,502
Help with C++ List erase function
I'm trying to do a simple erase and keep getting errors. Here is the snippet of code for my erase: std::list<Mine*>::iterator iterMines = mines.begin(); for(int i = oldSizeOfMines; i >0 ; i--, iterMines++) { if(player->distanceFrom(*iterMines) < radiusOfOnScreen) { onScreen.push_back(*iterMines); ...
The problem is you are trying to use the iterator of mines as an iterator in the onScreen list. This will not work. Did you mean to call mines.erase(iterMines) instead of onScreen.erase(iterMines)?
373,662
373,782
Need a good unmanaged C++ OCX example
I need a very simple and clear example of how to create an OCX in unmanaged C++ code. Ideally, I'd like to consume it in Office, but any container (i.e. VB6, .NET WinForms) should be good. I am having trouble seeing how I can add controls to the OCX canvas... I have seen examples of opening dialogs from within the OCX'...
Have you looked at this Microsoft tutorial. It uses MFC. If you want to create a windowless control you would need to use ATL.
374,217
375,270
Convert C++ Header Files To Python
I have a C++ header that contains #define statements, Enums and Structures. I have tried using the h2py.py script that is included with Python to no avail (except giving me the #defines converted). Any help would be greatly appreciated.
I don't know h2py, but you may want to look at 'ctypes' and 'ctypeslib'. ctypes is included with python 2.5+, and is targeted at creating binary compatibility with c-structs. If you add ctypeslib, you get a sub-tool called codegen, which has a 'h2xml.py' script, and a 'xml2py.py', the combination of which will auto-ge...
374,263
374,320
Porting Application from Solaris to Linux
I am to take up the task of porting a C++ networking application code base of quite a size from Solaris to Linux platform. The code also uses third party libraries like ACE. The application when written initially was not planned for a possible porting in future. I would like to get some advice and suggestions as to ho...
"There is no such thing as a portable application only applications that have been ported" First start with using the same tools on both platforms, if you can. I.E. if the Solaris version has not been changed to use GCC and GNU make etc, I advise you to change this first and get the Solaris build working. You will find...
374,303
374,352
Getter and setter wrappers for TiXmlElement*'s
I am rewriting a project so that it uses getters and setters to reference the TiXmlElement *'s However, I quickly run into problems that seem to be related to debug mode: Ecxerpt from my class's header: TiXmlElement *_rootElement; TiXmlElement *_dialogsElement; TiXmlElement *_dialogElement; TiXmlDocument _document; voi...
Make sure that TiXmlDocument getDocument () { return this->_document; } Will not deep copy its contained TiXmlElement's. Otherwise you return a temporary, use that in the constructor to set the root node, which then will be destructed already. I haven't looked in its API, but just be aware of such pitfalls. The reas...
374,322
374,395
Being specialised and keeping up
One of the things mentioned recently maybe in the SO podcast or Joel was that the best way to succeed at business when you start out is to start specialised and concentrate on one thing only. If you say you're the jack of all trades; you're just another jack! If you say you're a specialist in - I think joels example wa...
I'd guess that most people choose a reason (interest, money) to head in a particular direction at the beginning of their careers, and the rest is largely serendipitous. I still try to keep a broad general knowledge across the technologies related to my current and imminent responsibilities (and those of my friends and ...
374,399
374,423
Why do we actually need Private or Protected inheritance in C++?
In C++, I can't think of a case in which I would like to inherit private/protected from a base class: class Base; class Derived1 : private Base; class Derived2 : protected Base; Is it really useful?
It is useful when you want to have access to some members of the base class, but without exposing them in your class interface. Private inheritance can also be seen as some kind of composition: the C++ faq-lite gives the following example to illustrate this statement class Engine { public: Engine(int numCylinders);...
374,670
375,071
Returning Japanese characters via char* in an Excel XLOPER
I am retrieving Japanese characters from a data source and I want to return this data to Excel in an XLOPER. I am using a Japanese version of Excel 2003 (hence XLOPERs and not XLOPER12s). wchar_t* pszW = OLE2W(bstrResult); //I have the data I am trying to copy in a CComBSTR ULONG ulSize = ::WideCharToMultiByte( CP_TH...
User Error! The above code is good. The problem is that Excel was using the wrong code page. I hadn't set the language for non-unicode programs to Japanese in Control Panel. The code now works for the English version of Excel too. That was a day and a half well spent...
374,715
374,916
VC++ 6.0 access violation when run in debugger
I am trying to add enhancements to a 4 year old VC++ 6.0 program. The debug build runs from the command line but not in the debugger: it crashes with an access violation inside printf(). If I skip the printf, then it crashes in malloc() (called from within fopen()) and I can't skip over that. This means I cannot run in...
You can use _CrtSetDbgFlag() to enable a bunch of useful heap debugging techniques. There's a host of other CRT debugging functions available that should help you track down where your problem is.
374,832
377,579
(QT/kdelib) how to know the end of a command in KTerminalInterface?
I have a KTerminalInterface (from kparts) in my qt/kdelib app, and I run a command within it. The problem is: how can I know if the program is terminated? I need to know it because at its end I must reset some variable. Does anyone got a similar problem?!?
It isn't possible to communicate with the process once launched via TerminalInterface in KDE 4, since KonsolePart (which implements TerminalInterface) no longer has processExited() or receivedData() signals. In KDE 4, KonsolePart is for interactive terminal sessions, not for your app to use. In KDE 4, use KProcess to ...
375,141
375,171
How to pass method result as parameter to base class constructor in C++?
I've trying to achieve something like this: class Base { public: Base(string S) { ... }; } class Derived: Base { public: int foo; string bar() { return stringof(foo); // actually, something more complex }; Derived(int f) : foo(f), Base(bar()) { }; } Now, this doesn't work as I want, be...
Yes, using a function (static class method or regular function) that takes foo as a parameter and returns a string is a good solution. You can call this same function from Derived::bar to prevent code duplication. So, your constructor would look like this: Derived(int f) : Base(stringof(f)), foo(f) {} I place the call...
375,598
375,608
Finding the owner of an STL iterator
Is there any way that I can find the container pointed to by an iterator? Specifically, I want to be able to find the std::vector pointed to by a particular std::vector::iterator so that I can check the range, without having to actually pass references to that vector around. If (as I suspect) the answer is no, why not?...
I don't believe so. If iterators had to keep a reference/pointer to their owning container, then it would be impossible for them to be optimized down to a lightweight pointer (which can be done with containers guaranteeing contiguous storage like vectors and such).
375,647
375,683
Is requiring a certain order for #includes in c++ a sign of bad library/header design?
I've used some very large scale systems and never seen a required order, but came across it recently. Does the STL or STD library or even Boost have any cases where certain includes must come in a certain order?
Does the STL or STD library or even Boost have any cases where certain includes must come in a certain order? For the standard, the answer is emphatically, no. I imagine the same is true for Boost, though I haven't looked it up. From the C standard: Standard headers may be included in any order; each may be include...
375,722
375,736
Boost.format and wide characters
Is there a way to get boost.format to use and return wide (Unicode) character strings? I'd like to be able to do things like: wcout << boost::format(L"...") % ... and wstring s = boost::str(boost::format(L"...") % ...) Is this possible?
format_fwd.hpp contains this typedef: typedef basic_format<wchar_t > wformat; I think this will get you started. This works here: std::wcout << boost::wformat(L"...") % ... Also the boost::str works using wformat.
376,136
376,172
Changing the value of stdout in a C++ program
I have a Windows C++ program that is doing something like: FILE* pf = ...; *stdout = *pf; // stdout is defined in stdio.h I'm looking for an explanation about what happens when you change the value of the stdout file handle. Is this just a way of redirecting stdout? -cr
If you change stdout by assignment instead of by using the tool designated (in C, freopen() as Adam Rosenfield said - and by extension, in C++), then you leave yourself open to all sorts of liabilities. It is not clear that cout will also be redirected. You will likely leak a file descriptor (which may not matter). Yo...
376,154
376,241
Is std::map + std::tr1::bind + standard algorithms worthwhile?
This is a follow-up to my question from yesterday. I have Scott Meyers' warning about write-only code on my mind. I like the idea in principle of using standard algorithms to access the keys or values of a std::map, but the syntax required is a little baroque IMHO. Let's say I want to dump all the keys of a map to a...
Clarity always beats clever. Do what you can read later. You're not alone in thinking that the standard code is a little obtuse. The next C++ standard will introduce lambda functions so you can write more legible code with the standard algorithms.
376,232
376,287
Forward declaration problem
I'm using C++ .NET 2.0 I have 2 forms the first one is declared as follow #include "stdafx.h" namespace myNamespace{ public ref class frmMain : public System::Windows::Forms::Form { /*... snip ...*/ public void addNewRow(String^ text){ /*... snip... */ } public void launchSubForm() { SubFo...
This is because both of these header files include "stdafx.h", and stdafx.h includes "SubForm.h" before "frmMain.h". So, in "SubForm.h", the compiler wants to define SubForm before frmMain has been defined, leading to the error. The proper way to solve this problem is to keep all of the code for your classes in the app...
376,296
4,634,756
Building both DLL and static libs from the same project
I have a number of native C++ libraries (Win32, without MFC) compiling under Visual Studio 2005, and used in a number of solutions. I'd like to be able to choose to compile and link them as either static libraries or DLLs, depending on the needs of the particular solution in which I'm using them. What's the best way ...
I may have missed something, but why can't you define the DLL project with no files, and just have it link the lib created by the other project? And, with respect to settings, you can factor them out in vsprop files...
376,335
376,409
Are data structures an appropriate place for shared_ptr?
I'm in the process of implementing a binary tree in C++. Traditionally, I'd have a pointer to left and a pointer to right, but manual memory management typically ends in tears. Which leads me to my question... Are data structures an appropriate place to use shared_ptr?
I think it depends on where you'd be using them. I'm assuming that what you're thinking of doing is something like this: template <class T> class BinaryTreeNode { //public interface ignored for this example private: shared_ptr<BinaryTreeNode<T> > left; shared_ptr<BinaryTreeNode<T> > right; ...
376,698
378,379
How to load default settings with KConfig on kdelib?
I've a question about KConfig usage. I'm able to write and read settings in my .kde4/share/config/_appname_rc configuration file like that KConfig basicconf; KConfigGroup conf = KConfigGroup(basicconf.group("Settings")); conf.writeEntry("filepath",QString("/path/")); basicconf.sync(); But I don't understand how to...
First, this: KConfigGroup conf = KConfigGroup(basicconf.group("Settings")); can be written more clearly, at least imho, as: KConfigGroup conf(&basicconf, "Settings"); Also note that "General" is the most common "generic" group name used. Anyways... You can install a default config file with your application; install it...
376,966
377,049
Using C/C++ static libraries from iPhone ObjectiveC Apps
Is it possible to have a C static library API, which uses C++ internally and hide this from users of the library? I have writen a portable C++ library I wish to statically link to an iPhone application. I have created an Xcode project using the Max OS X 'static library' template, and copied the source across, as well a...
It's too hard to do this in comments, so I'm just going to demonstrate for you quickly what the linking issues are that you're having. When Xcode encounters files, it uses build rules based on the suffix to decide which compiler to use. By default, gcc links the files to the standard C library, but does not link with t...
377,094
410,051
GDI+ Dithering Problem
I have a C++ application that uses the Win32 API for Windows, and I'm having a problem with GDI+ dithering, when I don't know why it should be. I have a custom control (custom window). When I receive the WM_PAINT message, I draw some Polygons using FillPolygon on a Graphics device. This Graphics device was created usin...
Hmm... The filling capabilities are determined by the target device. When working over remote desktop, AFAIK Windows substitutes the display driver, so that can change the supported features of the display. when drawing on wm_paint, you actually draw directly on the screen surface, while .net usually uses double buffe...
377,178
377,208
What does the C++ new operator do other than allocation and a ctor call?
What are all the other things the new operator does other than allocating memory and calling a constructor?
The C++ standard has this to say about the single object form (the form usually used) of the new operator from the <new> header: Required behavior: Return a nonnull pointer to suitably aligned storage (3.7.3), or else throw a bad_alloc exception. This requirement is binding on a replacement version of this function...
377,322
377,325
Can someone explain the c++ FAILED function?
I've seen a lot of example c++ code that wraps function calls in a FAILED() function/method/macro. Could someone explain to me how this works? And if possible does anyone know a c# equivalent?
It generally checks COM function errors. But checking any function that returns a HRESULT is what it's meant for, specifically. FAILED returns a true value if the HRESULT value is negative, which means that the function failed ("error" or "warning" severity). Both S_OK and S_FALSE are >= 0 and so they are not used to c...
377,973
377,984
Does anybody have any experience with SSEPlus?
SSEPlus is an open source library from AMD for unified handling of SSE processor extensions. I'm considering to use this library for my next small project and would like to know, if anybody have experience with it? Can I use it on Intel machines? Any performance issues in comparison to direct SSE calls? Any issues on 6...
Yes, you can use it on Intel machines too. Performance should not differ except that it adds the checks about supported processor features which might cost a little.
378,207
378,235
C++ How can I iterate till the end of a dynamic array?
suppose I declare a dynamic array like int *dynArray = new int [1]; which is initialized with an unknown amount of int values at some point. How would I iterate till the end of my array of unknown size? Also, if it read a blank space would its corresponding position in the array end up junked? Copying Input From users...
No portable way of doing this. Either pass the size together with the array, or, better, use a standard container such as std::vector
378,213
378,290
Debugging GUI Applications in C++
Background: I'm currently debugging an application written over a custom-built GUI framework in C++. I've managed to pin down most bugs, but the bugs I'm having the most trouble with tend to have a common theme. All of them seem to be to do with the screen refreshing, redrawing or updating to match provided data. This ...
I agree with dual monitors or even remote debugging to reduce interfering with the messages. I also highly recommend Spy utilities. These let you see what messages are being sent in the system. One such program is Winspector. http://www.windows-spy.com/
378,296
379,059
Why is my WM_UNICHAR handler never called?
I have an ATL control that I want to be Unicode-aware. I added a message handler for WM_UNICHAR: MESSAGE_HANDLER( WM_UNICHAR, OnUniChar ) But, for some reason, the OnUniChar handler is never called. According to the documentation, the handler should first be called with "UNICODE_NOCHAR", on which the handler should re...
What are you doing that you think should generate a WM_UNICHAR message? If your code (or the ATL code) ultimately calls CreateWindowW, then your window is already Unicode aware, and WM_CHAR messages will be UTF-16 format. The documentation is far from clear on when, exactly, a WM_UNICHAR message gets generated, but fro...
378,380
378,399
How can I debug a win32 process that unexpectedly terminates silently?
I have a Windows application written in C++ that occasionally evaporates. I use the word evaporate because there is nothing left behind: no "we're sorry" message from Windows, no crash dump from the Dr. Watson facility... On the one occasion the crash occurred under the debugger, the debugger did not break---it showed...
You could try using the adplus utility in the windows debugging tool package. adplus -crash -p yourprocessid The auto dump tool provides mini dumps for exceptions and a full dump if the application crashes.
378,515
378,576
What's the deal with boost.asio and file i/o?
I've noticed that boost.asio has a lot of examples involving sockets, serial ports, and all sorts of non-file examples. Google hasn't really turned up a lot for me that mentions if asio is a good or valid approach for doing asynchronous file i/o. I've got gobs of data i'd like to write to disk asynchronously. This can ...
Has boost.asio any kind of file support? Starting with (I think) Boost 1.36 (which contains Asio 1.2.0) you can use [boost::asio::]windows::stream_handle or windows::random_access_handle to wrap a HANDLE and perform asynchronous read and write methods on it that use the OVERLAPPED structure internally. User Lazin also ...
378,630
378,751
Specify ordinals of C++ exported functions in a DLL
I am writing a DLL with mixed C/C++ code. I want to specify the ordinals of the functions I'm exporting. So I created a .DEF file that looks like this LIBRARY LEONMATH EXPORTS sca_alloc @1 vec_alloc @2 mat_alloc @3 sca_free @4 vec_free @5 mat_free @6 ... I would like to s...
Well, I don't have experience with ordinals (which look like some ugly, compiler-specific thing), but I can help you with making C++/C code compatible. Suppose, in C++, that your header file looks like this: class MyClass { void foo(int); int bar(int); double bar(double); void baz(MyClass); }; You can ...
378,808
378,962
How do you change an IP address in C++?
I need to do a number of network-related things in C++ that I would normally do with ifconfig in Linux, but I'd like to do it without parsing the output of a group of system calls. Which C or C++ libraries can I use to tell if a network adapter is up or down, read or change an adapter's IP address and netmask, and cha...
Basically you need to make a bunch of ioctl calls using a socket handle (SIOCGIFADDR, SIOCADDRT). You can find sample programs that use it in the Linux kernel source under Documentation/networking. Some other links that might be helpful: Network Interface operations on AIX XBMC's implementation (check out CNetworkInte...
378,876
378,913
C++ namespaces: cross-usage
Consider the following example. It consists of two header files, declaring two different namespaces: // a1.h #pragma once #include "a2.h" namespace a1 { const int x = 10; typedef a2::C B; } and the second one is // a2.h #pragma once #include "a1.h" namespace a2 { class C { public: int say() { ...
You need to use a forward declaration in your header files because you have a circular reference. Something like this: // a1.h #pragma once namespace a2 { class C; } namespace a1 { const int x = 10; typedef a2::C B; }
379,136
379,970
Can I extend lisp with c++?
Can I call a function from lisp from a library written in c or c++? How can I extend lisp? This is useful when you want to do some system calls or stuff like that.
It is unusual to call non-lisp code from lisp, and rarely necessary. CLX (the X11 client implementation for CL) doesn't link to the Xlib implementation but "speaks" X11 directly. On any system, your CL implementation is likely to already have excellent operating system hooks rendering this unnecessary. That said, the a...
379,172
379,189
To GOTO or not to GOTO?
Currently I am working on a project where goto statements are heavely used. The main purpose of goto statements is to have one cleanup section in a routine rather than multiple return statements. Like below: BOOL foo() { BOOL bRetVal = FALSE; int *p = NULL; p = new int; if (p == NULL) { cout<<" OOM...
I am not sure what do you mean by clean up code but in C++ there is a concept called "resource acquisition is initialization" and it should be the responsibility of your destructors to clean up stuff. (Note that in C# and Java, this is usually solved by try/finally) For more info check out this page: http://www.researc...
379,238
380,857
C++ and SOAP -> how to start well
My project is about to introduce SOAP. It's going to be used for C++ <-> Java and C++ <-> Flex communication. I'm responsible for refactoring our apps to take advantage of Java business rules engine and new Flex gui. What resources are must read for C++ SOAP? I've read W3 materials. We're probably be using gSOAP on Sol...
There are some reasonably good books on SOAP, like Programming Web Services with SOAP by Snell, Tidwell, and Kulchenko; I've given that to people to introduce them to SOAP on projects in the past. I don't know of a C++-specific book, but the gSOAP site has pretty decent documentation. I think the really key thing is p...
379,380
379,443
Avoiding Inheritance Madness
So, I have an API that I need to implement in to an existing framework. This API manages interactions with an external server. I've been charged with coming up with a way to create an easily repeatable "pattern," so that if people are working on new projects in the given framework they have a simple solution for inte...
If your boss is hostile to inheritance, try aggregation. (Has-a relationships rather than inheritance's is-a relationship.) Assuming you interface with the API in question via an object, maybe you can just keep that object in a property of your framework 'main' class, so you'd interact with it like main->whateverapi-...
379,383
379,507
Finding gaps in sequence of numbers
I have a std::vector containing a handful of numbers, which are not in any particular order, and may or may not have gaps between the numbers - for example, I may have { 1,2,3, 6 } or { 2,8,4,6 } or { 1, 9, 5, 2 }, etc. I'd like a simple way to look at this vector and say 'give me the lowest number >= 1 which does not ...
The checked answer uses < for comparison. != is much simpler: int find_gap(std::vector<int> vec) { std::sort(vec.begin(), vec.end()); int next = 1; for (std::vector<int>::iterator it = vec.begin(); it != vec.end(); ++it) { if (*it != next) return next; ++next; } return next; } find_g...
379,442
379,589
How much slower is a wxWidget written in Python versus C++?
I'm looking into writing a wxWidget that displays a graphical node network, and therefore does a lot of drawing operations. I know that using Python to do it is going to be slower, but I'd rather get it working and port it later when its functional. Ideally, if the performance hit isn't too great, I'd prefer to keep ...
IMHO, main bottleneck will be the data structures you are going to use for representing the network graph. I have coded a similar application for tracing dependencies between various component versions in a system and graphics was the last thing I had to worry about and I was certainly drawing more than 500 objects wit...
379,581
379,663
How to diagnose Access Violation on application exit
I have an application that I'm trying to debug a crash in. However, it is difficult to detect the problem for a few reasons: The crash happens at shutdown, meaning the offending code isn't on the stack The crash only happens in release builds, meaning symbols aren't available By crash, I mean the following exception:...
You can make the symbol files even for the release build. Do that, run your program, attach the debugger, close it, and see the cause of the crash in the debugger.
379,916
379,951
How to implement One Definition Rule
This post reference to the One Definition Rule. Wikipedia is pretty bad on explaining how to implement it Where can I find good ressources about guidelines to follow in C++ .NET?
The one definition rule basically means that a variable/function can only be located at one place in address space of the compiled executable. One way to think of it is while you compile, there is an array of memory to be used in the compiled program (object code), and a lookup table to reference variable/function loca...
380,442
380,447
What is the point of pointer types in C++?
Let's say I have some pointers called: char * pChar; int * pInt; I know they both simply hold memory addresses that point to some other location, and that the types declare how big the memory location is pointed to by the particular pointer. So for example, a char might be the size of a byte on a system, while an int ...
"++" is just another name for X = X + 1; For pointers it doesn't matter if you increment by 1 or by N. Anyway, sizeof(type)*N is used. In the case of 1 it will be just sizeof(type). So, when you increment by 2 (your second case): for char is 2*sizeof(char)=2*1=2 bytes, for int will be 2*sizeof(int)=2*4=8 bytes.
380,529
380,553
Multiple Inheritance
#include<iostream> using namespace std; class A { int a; int b; public: void eat() { cout<<"A::eat()"<<endl; } }; class B: public A { public: void eat() { cout<<"B::eat()"<<endl; } }; class C: public A { public: void eat() { cout<<"C::eat()"<<endl; ...
Inheriting twice With double inheritance you have an ambiguity - the compiler cannot know which of the two A bases do you want to use. If you want to have two A bases (sometimes you may want to do this), you may select between them by casting to B or C. The most appropriate from default casts here is the static_cast (a...
380,559
381,019
Using .NET class from native C++ using C++/CLI as a 'middleware'
I have to use a class/assembly made in C# .NET from native C++ application. I suppose I need to make a wrapper class in C++/CLI, that would expose native methods in header files, but use .NET class as needed. Thing that's unclear to me is how to convert data types from .NET to standard C++ types. Does anybody have som...
Yes you need to build a wrapper with C++/CLI around your managed assembly. For mixing native and managed types you may want to check this article for sample codes. Primitive types has int, float, byte are converted for you. But other types has String must be done yourself. For example, if you have a native pointer on...
381,161
383,217
Do XCode projects need special settings to use pre-compiled boost libraries?
I have just installed boost for the first time on my Intel Mac, and it works fine in general, as long as I use only boost's header files. But when I try to use a lib, in my case the regex lib, my app links and launches fine, but then it soon crashes in a regex related destructor. This even happens with the simple test ...
Answer to self: While it's still not clear what causes this problem, there is a workaround: Instead of using the libs that the boost installer process builds, add the source code for the lib (in boost-main-folder/libs/libname/src/) to your Xcode project instead, having Xcode compile the sources for you.
381,164
382,077
friend AND inline method, what's the point ?
I see in a header that I didn't write myself the following: class MonitorObjectString: public MonitorObject { // some other declarations friend inline bool operator==(MonitorObjectString& lhs, MonitorObjectString& rhs) { return(lhs.fVal==rhs.fVal); } I can't understand why this method is declared as friend. I t...
friend inline bool operator==(MonitorObjectString& lhs, MonitorObjectString& rhs) { return(lhs.fVal==rhs.fVal); } is sometimes called friend definition, because it is a friend declaration that also defines the function. It will define the function as a non-member function of the namespace surrounding the class i...
381,267
381,577
Looped push_back against resize() + iterator
Simple question; what's better and why? out.resize( in.size() ); T1::iterator outit = out.begin(); for( inIt = in.begin() to end, ++inIt, ++outIt ) *outit = *inIt OR out.erase(); for( inIt = in.begin() to end, ++inIt ) out.push_back( inIt ); I'm assuming the memory assignment im...
The second, and if you're concerned about multiple extensions use out.reserve(). The right answer to adding to a vector is almost always push_back or back_inserter, which avoid some possible problems (exception guarantees, constructors, writing past the end, for example) that you'd have to pay attention to with other ...
381,324
381,352
An operator == whose parameters are non-const references
I this post, I've seen this: class MonitorObjectString: public MonitorObject { // some other declarations friend inline bool operator==(/*const*/ MonitorObjectString& lhs, /*const*/ MonitorObjectString& rhs) { return lhs.fVal==rhs.fVal; } } Before we can continue, THIS IS...
Perhaps the classes use a form of lazy initialization. When the data is accessed, proper initialization must occur, and the data must be fetched. This may change class members. However, lazy initialization can be formed so that modification to the class isn't necessary. This can be accomplished by using the Pimpl id...
381,363
381,412
lightweight boost::bind
I'm so sick of the pass-callback-data-as-void*-struct anti-pattern. Boost bind solves it nicely, but is an unacceptable dependency. What's a lightweight alternative? How would I write it myself as simply as possible?
I'm not familiar with boost:bind, but is it something like this? #include <iostream> void foo (int const& x) { std::cout << "x = " << x << std::endl; } void bar (std::string const& s) { std::cout << "s = " << s << std::endl; } template<class T> void relay (void (*f)(T const&), T const& a) { f(a); } int ...
381,621
381,656
Using arrays or std::vectors in C++, what's the performance gap?
In our C++ course they suggest not to use C++ arrays on new projects anymore. As far as I know Stroustroup himself suggests not to use arrays. But are there significant performance differences?
Using C++ arrays with new (that is, using dynamic arrays) should be avoided. There is the problem that you have to keep track of the size, and you need to delete them manually and do all sorts of housekeeping. Using arrays on the stack is also discouraged because you don't have range checking, and passing the array aro...
381,695
381,704
Best base type to deal with linear algebra
I'm writing a small and inadequate linear algebra library in C++ for a project (I'm sorry). I'm implementing matrices and operations using double precision numbers. I'm doing right? Should I implement a template class instead? Is there a more precise type around?
I've written a C++ linear algebra library using templates. My thought was that we might want to use complex numbers or extended precision numbers some day. That was maybe seven years ago, and we haven't done it yet. We almost always use doubles as the template type, and we have typedefs to make that easy. A few ti...
381,718
381,749
Check for pointer definedness in C++
How do I check if a variable, specifically a pointer, is defined in C++? Suppose I have a class: class MyClass { public: MyClass(); ~MyClass() { delete pointer; // if defined! } initializePointer() { pointer = new OtherClass(); } private: OtherClass* pointer; };
Why worry about checking for the pointers value? Just initialize it to a null pointer value and then just call delete on it. delete on a null pointer does nothing (the standard guarantees it). class MyClass { public: MyClass():pointer(0) { } ~MyClass() { delete pointer; pointer = 0; } ...
381,968
392,777
Play an mp3 on a Pocket PC with VSC++ code
Does anyone know of some mp3 playing code for the pocket PC. I have 3 mp3s that I want to play when my application loads up, depending on how you log in. I've used VS2005 C++ to code what I've got now. I think code to play mp3 for the desk might do the job. But I might not have access to the library, that's why I've...
You can use DirectShow. Here is an example (it plays a video file, but exactly the same code will work for audio). Unfortunately, Windows Mobile lacks a suitable splitter to decode plain .mp3 files, but there is a workaround: you can add a RIFF header to your MP3s (producing MPEG-compressed WAV files).
382,166
382,177
smart pointers + "this" considered harmful?
In a C++ project that uses smart pointers, such as boost::shared_ptr, what is a good design philosophy regarding use of "this"? Consider that: It's dangerous to store the raw pointer contained in any smart pointer for later use. You've given up control of object deletion and trust the smart pointer to do it at the ri...
While i don't have a general answer or some idiom, there is boost::enable_shared_from_this . It allows you to get a shared_ptr managing an object that is already managed by shared_ptr. Since in a member function you have no reference to those managing shared_ptr's, enable_shared_ptr does allow you to get a shared_ptr i...
382,272
382,288
Safe to use the compiler generated assignment operator?
I'm using the CPoint class from MFC. There is no explicitly defined assignment operator or copy constructor (AFAIK). Yet, this works: CPoint p1(1, 2), p2; p2 = p1; // p2 now is equal to p1 I'm assuming this is working automagically because of a compiler generated assignment operator. Correct? If so, can I be confiden...
This is safe - if an assignment operator wasn't meant to be supplied then the MFC designers could have made sure it wasn't available (by making it private for example). IIRC the compiler will perform a member-by-member copy, so for a class containing POD like this, you won't have a problem. It can get messy if you hav...
382,480
382,586
C++ experts: is the offset of a member variable to its class constant under these conditions?
Given a variable foo of type FooClass* and a member variable in that class named bar, is the distance between foo and &(foo->bar) the same in any situation with some constraints: FooClass is a non-POD type. We know that foo will always point to an instance of FooClass, and not some subtype of it. We only care about be...
After you have compiled your program, Yes*. The offset will remain constant. There is one very important restriction, however: foo must be pointing specifically to a FooClass object. Not a class derived from FooClass, or anything else for that matter. The reason that C++ makes the POD distinction regarding member off...
382,822
382,825
Destructor C++: type '***' argument given to 'delete', expected pointer
I declared a private variable vector<SomeClass> theVector; someplace inside my SomeClass class. Why can't I say: delete theVector inside my SomeClass destructor? The compiler error says: type `class Vector<SomeClass>' argument given to `delete', expected pointer What expected pointer?
If new and delete go hand in hand. To delete something you need to create it via new (which gives you a pointer). You can then delete the pointer. The way you are declaring the vector it is being created on the stack (not the heap) and will be deallocated when it goes out of scope. int main() { vector<SomeClass> th...
383,016
383,084
How do stl containers get deleted?
How does container object like vector in stl get destroyed even though they are created in heap? EDIT If the container holds pointers then how to destroy those pointer objects
An STL container of pointer will NOT clean up the data pointed at. It will only clean up the space holding the pointer. If you want the vector to clean up pointer data you need to use some kind of smart pointer implementation: { std::vector<SomeClass*> v1; v1.push_back(new SomeClass()); std::vector<boost::...
383,173
384,115
QX11EmbedContainer and QProcess problem
I've been trying to put a QX11EmbedContainer in my app, and I need to start a terminal within it (because with konsolepart I can practically do nothing). QX11EmbedContainer* container = new QX11EmbedContainer(this); // with or without "this" I got the same result container->show(); QProcess process(container); QString...
The QProcess is allocated on the stack and will deleted as soon as it goes out of scope. This is likely to happen before the the "xterm" child process quits (hence the output). Try allocating the QProcess in the heap instead: QProcess * process = new QProcess(container); ... process->start(executable, arguments); You ...
383,371
383,385
What is the best way to implement a cross-platform, multi-threaded server in C/C++?
Part of the development team I work with has been given the challenge of writing a server for integration with our product. We have some low-level sensor devices that provide a C SDK, and we want to share them over a network for use by people collecting data. Sounds simple, right? Someone would connect a sensor device ...
I've used Boost.Thread & Boost.Asio to build a multi-threaded server on Windows & Linux systems. The tutorials made it easy to get started.
383,973
383,976
Is args[0] guaranteed to be the path of execution?
This is a fundamental question, but an important one none the less... When starting a C++ program whose main method has the following common signature: int main(int argc, char* args[]) { //Magic! return 0; } is args[0] always guaranteed to be the path to the currently running program? What about cross platform...
It is not always. It's the value that you gave the program by the Operation System. For example when starting a program using exec you can set that to an arbitrary value: int execve(const char *filename, char *const argv[], char *const envp[]); The first parameter is the file to start, and argv will contain...
384,036
384,485
c++ continuous integration with performance metrics
I want to set up a continuous integration and test framework for my open source C++ project. The desired features are: 1. check out the source code 2. run all the unit and other tests 3. run performance tests (these measure the software quality - for example how long does it take the system to complete the test) 4. pro...
I am using CruiseControl and UnitTest++ today for exactly this task. UnitTest++ is really nice although I feel sometimes limited by it around the corner. At least it is 10 times better than cppunit. Still haven't tried the google testing framework, it will be for my next project. I have been extremely disappointed by C...
384,110
384,708
Smart pointers for Windows Mobile 6 SDK
I cannot get std::tr1::shared_ptr for my WinMobile project since the STL for WinCE is maintained by a different team at Microsoft :( aarrgh... Anyone worked with another thread-safe, reference counting smart pointers? I'm actually using yasper which seems to be good. Thank you very much.
I'd also recommend boost::shared_ptr. You can do what I did for a library, and use a #define to switch between std::tr1::shared_ptr and boost::shared_ptr, depending on the capabilities of the compiler. That way your code doesn't need to be modified [much] if/when the CE team add tr1 support. Just my 2c.
384,159
384,169
Can't assign a member which is a pointer to a templatized class
My problem is that in my "Widget" class i've the following declaration: MouseEvent* X; In a member function I initialize the pointer with an address the normal way: X = new MouseEvent; Ok, this last line makes the compiler stop at: error C2166: l-value specifies const object All right, a MouseEvent is declared as ...
Likely, the member function where you are initializing X is marked as const - something like this. class Foo { int *Bar; public: void AssignAndDoStuff() const { Bar = new int; // Can't assign to a const object. // other code } } The solution here is either to Assign to Bar in a separate non...
384,200
384,211
C++ Operator Ambiguity
Forgive me, for I am fairly new to C++, but I am having some trouble regarding operator ambiguity. I think it is compiler-specific, for the code compiled on my desktop. However, it fails to compile on my laptop. I think I know what's going wrong, but I don't see an elegant way around it. Please let me know if I am maki...
This is explained in the book "C++ Templates - The Complete Guide". It's because your operator[] takes size_t, but you pass a different type which first has to undergo an implicit conversion to size_t. On the other side, the conversion operator can be chosen too, and then the returned pointer can be subscript. So there...
384,431
384,434
C++ Header files - Confused!
game.h needs: - packet.h - socket.h server.h needs: - socket.h socket.h needs: - game.h The problem comes when I try to include socket.h into game.h, because socket.h has game.h included already. How do I solve these kind of problems?
The usual way, use #ifdef and #define in your header files inside game.h: #ifndef GAME_H #define GAME_H .. rest of your header file here #endif This way, the contents will be read multiple times, but only defined once. Edit: Removed underscores at start and end of identifier per comments.
384,886
384,936
How to make warnings persist in visual studio
Suppose I have files a.cpp and b.cpp and I get warnings in a.cpp and an error in b.cpp. I fix the error in b.cpp and recompile -- since Visual Studio doesn't have to recompile a.cpp, it doesn't remind me of the warnings it found before. I'd like to somehow have the warnings persist; however, I don't want it to treat wa...
Essentially, you're out of luck. The C++ compilation will discard all of the errors and warnings. Because it only recompiles .CPP files that have a missing .OBJ file (i.e. the ones that had errors and failed last time), you'll only see the errors. You have a few options. Off the top of my head: Write a macro that resp...
384,913
384,924
Problems using EnterCriticalSection
I need to work with array from several threads, so I use CRITICAL SECTION to give it an exclusive access to the data. Here is my template: #include "stdafx.h" #ifndef SHAREDVECTOR_H #define SHAREDVECTOR_H #include <vector> #include <windows.h> template<class T> class SharedVector { std::vector<T> vect; CRITIC...
Just declare cs as: mutable CRITICAL_SECTION cs; or else remove the const clause on size() Entering a critical section modifies the CRITICAL_SECTION, and leaving modifies it again. Since entering and leaving a critical section doesn't make the size() method call logically non-const, I'd say leave it declared const, a...
385,039
385,076
Are there cases where a "finally" construct would be useful in C++?
Bjarne Stroustrup writes in his C++ Style and Technique FAQ, emphasis mine: Because C++ supports an alternative that is almost always better: The "resource acquisition is initialization" technique (TC++PL3 section 14.4). The basic idea is to represent a resource by a local object, so that the local object's destructor...
The only reason I can think of that a finally block would be "better" is when it takes less code to accomplish the same thing. For example, if you have a resource that, for some reason doesn't use RAII, you would either need to write a class to wrap the resource and free it in the destructor, or use a finally block (if...
385,060
385,071
How do I do lots of processing without gobbling cpu?
I know the question title isn't the best. Let me explain. I do a TON of text processing which converts natural language to xml. These text files get uploaded fairly fast and thrown into a queue. From there they are pulled one-by-one into a background worker that calls our parser (using boost spirit) to transform the te...
I would buy a couple of cheap computers and do the text processing on those. As Jeff says in his latest post, "Always try to spend your way out of a performance problem first by throwing faster hardware at it."
385,370
385,373
User Breakpoint from nowhere
I have some code in MS VC++ 6.0 that I am debugging. For some reason, at this certain point where I am trying to delete some dynamically allocated memory, it breaks and I get a pop up message box saying "User Breakpoint called from code at blah blah".. then the Disassembly window pops up and I see *memory address* int...
You're probably hitting code in the debug heap routines that have found heap corruption. What does the call stack look like when you've hit the Int 3? Edit: Based on the stack trace in your comments, the routine _CrtIsValidHeapPointer() is saying that the pointer being freed is bad. Here's the snippet of code from MSV...
385,556
385,568
How does C++ pick which overloaded function to call?
Say I have three classes: class X{}; class Y{}; class Both : public X, public Y {}; I mean to say I have two classes, and then a third class which extends both (multiple-inheritance). Now say I have a function defined in another class: void doIt(X *arg) { } void doIt(Y *arg) { } and I call this function with an insta...
Simple: if it's ambiguous, then the compiler gives you an error, forcing you to choose. In your snippet, you'll get a different error, because the type of new Both() is a pointer to Both, whereas both overloads of doIt() accept their parameters by value (i.e. they do not accept pointers). If you changed doIt() to tak...
385,629
385,643
Draw Order in OpenGL
I am rendering an OpenGL scene that include some bitmap text. It is my understanding the order I draw things in will determine which items are on top. However, my bitmap text, even though I draw it last, is not on top! For instance, I am drawing: 1) Background 2) Buttons 3) Text All at the same z depth. Buttons are a...
You can simply disable the z-test via glDisable (GL_DEPTH_TEST); // or something related.. If you do so the Z of your text-primitives will be ignored. Primitives are drawn in the same order as your call the gl-functions. Another way would be to set some constant z-offset via glPolygonOffset (not recommended) or se...
385,660
387,017
How do I setup a callback mechanism for RichEdit in win32
In win32, how do I setup a callback mechanism for RichEdit I have not created myself? PART 1 I'm reading from a textedit field in another application's GUI. This works just fine now, except after the first read I'd like to fetch only new or modified lines. In GTK+ or Qt I'd just install a callback on some signal the fi...
Win32 controls don't work on message-specific callbacks that you can subscribe to. They just send messages to their parent window when something happens, in this case EN_UPDATE, EN_CHANGE and all that. Even these events don't tell you what text changed. They only tell you that it did change. You could subclass the pare...
386,252
386,263
operator ThisClass() causing stack overflow
I want to keep the class simple and not defined a constructor so i can do Pt data = {0, 5}; so i figured the best way convert Pt_t from a short to long or vice versa is to do something like this. template <class T> struct Pt_t { T x, y; template <class T2> operator Pt_t<T2>() { Pt_t pt = {x, y}; return pt; } };...
I'm pretty sure the unqualified Pt_t in your functions body is Pt_t<T>, but don't you want it to be Pt_t<T2>? You'll need to explicitly qualify it.
386,345
386,365
C++ classes - constructor declaration in derived class
Socket has a constructor that takes a winsock SOCKET as parameter and stores it in a private variable: Socket::Socket(SOCKET s) { this->s = s; } I'm trying to make a class "GameSocket" that will parse data from my Socket class: class GameSocket : public Socket { protected: void ParseData(unsigned char* data,...
Add in a constructor for GameSocket class GameSocket : public Socket { public: // you need to add GameSocket(SOCKET s) : Socket(s) {} protected: void ParseData(unsigned char* data, int size); };
386,379
418,190
DirectShow - How to overlay video with text
I am writing an application for Windows Mobile where I want to display some text over the video preview on the screen. Does anyone know how this could be done or if there's any good tutorial about it? Thanks!
Try this: http://www.codeguru.com/cpp/g-m/directx/article.php/c1229 Not sure if it applies to Windows Mobile, though.
386,438
386,478
Boolean operations on rectangle polygons
Avast there fellow programmers! I have the following problem: I have two rectangles overlapping like shown on the picture below. I want to figure out the polygon consisting of point ABCDEF. Alternate christmas description: The red cookie cutter is cutting away a bit of the black cookie. I want to calculate the black c...
This is a special case of general 2D polygon clipping. A good place to start is the Weiler-Atherton algorithm. Wikipedia has a summary and links to the original paper. The algorithm seems to match the data structure you've described pretty well. Note that it's quite possible you'll end up with a rectangle with a hol...
386,517
386,596
Need a c++ compiler to work with libraries (boost, ...)
Currently I`m using Visual Studio for writing code in C++. But it seems so weighty that I decided to switch for another one, preferably free, not so strict to system resources (I mean memory, of course) as VS to learn libraries, such as Boost and Qt. What compiler do you suggest?
Code::blocks is exactly what you are after. You can can download it here: http://www.codeblocks.org/downloads/5 Choose the version with the mingw compiler bundled with it (Windows port of GCC). You can switch between that and the VC++ compiler as and when you like. Code::Blocks has all the stuff you want, debugger inte...
386,559
386,565
How to delete a file from a C++ app without console window in Windows?
I need to delete a temporary file from my C++ windows application (developed in Borland C++ Builder). Currently I use a simple: system("del tempfile.tmp"); This causes a console window to flash in front of my app and it doesn't look very professional. How do I do this without the console window?
It sounds like you need the Win32 function DeleteFile(). You will need to #include <windows.h> to use it.
387,092
390,758
Hand Coded GUI Versus Qt Designer GUI
I'm spending these holidays learning to write Qt applications. I was reading about Qt Designer just a few hours ago, which made me wonder : what do people writing real world applications in Qt use to design their GUIs? In fact, how do people design GUIs in general? I, for one, found that writing the code by hand was co...
Our experience with Designer started in Qt3. Qt3 At that point, Designer was useful mainly to generate code that you would then compile into your application. We started using for that purpose but with all generated code, once you edit it, you can no longer go back and regenerate it without losing your edits. We ended ...