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
3,117,654
3,119,638
Update Qt4 statusbar from glwidget
I've got a window containing a QGLWidget and a QStatusBar. I calculate the fps inside a timerEvent call, but I don't know the 'correct' way to update the statusbar on every frame. fps is a member variable of GLWidget: void GLWidget::timerEvent(QTimerEvent* event){ updateGL(); // Calculate FPS. prevTime = ...
What you probably want is a custom signal on the GLWidget that you connect to a slot. Make the connection on the widget containing both the GLWidget and the status bar: connect(&glWidgetInstance, SIGNAL(updateFPSSignal(int)), this, SLOT(updateFPSSlot(int))); The slot function would look something like this: void upda...
3,117,848
3,118,453
How is called a C/C++ program without end?
I mean a program based on events, a "static" program that don't just do a task but waits for events, etc. and doesn't end until the user manually close it. EDIT: I have answered below, for example the programs we use every day and are based in Windows, like Microsoft Word, Firefox, etc. What is this type of program cal...
Simply put, it's called an "Event-driven Program".
3,118,039
3,118,514
typeid result across different dll's
I have two dlls which both declare a templated type, let's call A. If the declaration of A is sufficiently intricate, it happens that the result of typeid(A).name() is different when called in functions in two different dll's. example: DLL1: struct MyType: public A< TEMPLATE_LIST_OF_A >{} void f(){ std::string name1 ...
Not only is there no way to guarantee that typeid().name() is the same in different DLLs, the standard makes almost no guarantees about the string returned at all. Specifically, it is not guaranteed to be a) meaningful, b) unique for different types, c) the same for identical types. As a quality of implementation iss...
3,118,165
3,118,188
When do I use fabs and when is it sufficient to use std::abs?
I assume that abs and fabs are behaving different when using math.h. But when I use just cmath and std::abs, do I have to use std::fabs or fabs? Or isn't this defined?
In C++, it's always sufficient to use std::abs; it's overloaded for all the numerical types. In C, abs only works on integers, and you need fabs for floating point values. These are available in C++ (along with all of the C library), but there's no need to use them.
3,118,300
3,118,672
How to get Driver Name?
how can I get the driver's name of a device to use with CreateFile? handle = CreateFile( DRIVER_NAME_HERE, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); thanks!
It's depend on what you want. A typical examples are \\.\C: \\.\Tcp \\.\PhysicalDrive0 \\?\usbstor#disk&ven_sandisk&prod_cruzer&rev_8.01#1740030578903736&0#{53f56307-b6bf-11d0-94f2-00a0c91efb8b} \\.\CON (see http://msdn.microsoft.com/en-us/library/aa363858(VS.85).aspx). I recommend you to also to use WinObj (see http:...
3,118,430
3,118,482
Applying a function to 2 stl vectors
I'm currently trying to learn how to effectively use the STL part of c++. Say there are 2 vectors of the same type of equal length that need to be transformed into another vector of the same length by applying some operator, is there a good way to do this using the functionality of the STL? Here's some pseudocode for w...
You may need to do some checking on sizes, but generally you can use std::transform. E.g. (for + - <functional> contains class templates for function objects for this and other binary operators) std::transform( a.begin(), a.end(), b.begin(), result.begin(), std::plus<T>() ); You need to ensure that b.size() >= a.size(...
3,118,543
3,118,581
Need help deciphering gprof output
I am pretty sure this has something to do with a vector of void function pointers, but I can't really make anything out of it. Can someone break this down for me? __gnu_cxx::__normal_iterator<unsigned long long const*, std::vector<unsigned long long, std::allocator<unsigned long long> > >::difference_type __gnu_cxx::op...
If I am correct, this could be roughly translated to: // Typedef for brevity typedef vector<unsigned long long>::iterator uv_iter; // Actual function uv_iter::difference_type operator-(const uv_iter &, const uv_iter &); So, probably it is referring to the function that computes the difference (=distance) between two i...
3,118,552
3,118,922
Using DLL import/Declare in VB.NET with parameter types not used by .NET
I am working on a project where I have to import a DLL file into a VB project that was created a few years back. The DLL was created in C++, and looks like: void CoordinateConversionService::convert( SourceOrTarget::Enum sourceDirection, SourceOrTarget::Enum targetDirection, CoordinateTuple* sourceCoordinates, Accuracy...
In VB you say either Public Function Whatever (params) As ReturnType (which is the same as public ReturnType Whatever(params) in C#) or Public Sub Whatever (params) which is for things that don't return anything (return void in C++/C#). If your function/sub takes custom types you will need to declare .NET equivalents t...
3,118,582
3,118,775
How do I find the current system timezone?
On Linux, I need to find the currently configured timezone as an Olson location. I want my (C or C++) code to be portable to as many Linux systems as possible. For example. I live in London, so my current Olson location is "Europe/London". I'm not interested in timezone IDs like "BST", "EST" or whatever. Debian and Ubu...
It's hard to get a reliable answer. Relying on things like /etc/timezone may be the best bet. (The variable tzname and the tm_zone member of struct tm, as suggested in other answers, typically contains an abbreviation such as GMT/BST etc, rather than the Olson time string as requested in the question). On Debian-based...
3,118,600
3,118,739
Better compression algorithm for vector data?
I need to compress some spatially correlated data records. Currently I am getting 1.2x-1.5x compression with zlib, but I figure it should be possible to get more like 2x. The data records have various fields, but for example, zlib seems to have trouble compressing lists of points. The points represent a road network. T...
You'll likely get much better results if you try to compress the data yourself based on your knowledge of its structure. General-purpose compression algorithms just treat your data as a bitstream. They look for commonly-used sequences of bits, and replace them with a shorter dictionary indices. But the duplicate data d...
3,118,659
3,119,260
How to avoid HDD thrashing
I am developing a large program which uses a lot of memory. The program is quite experimental and I add and remove big chunks of code all the time. Sometimes I will add a routine that is rather too memory hungry and the HDD drive will start thrashing and the program (and the whole system) will slow to a snails pace. It...
You could consider using SetProcessWorkingSetSize . This would be useful in debugging, because your app will crash with a fatal exception when it runs out of memory instead of dragging your machine into a thrashing situation. http://msdn.microsoft.com/en-us/library/ms686234%28VS.85%29.aspx Similar SO question Set Windo...
3,118,661
3,152,442
Preventing SQL injection in C++ OTL, DTL, or SOCI libraries
I've been looking at all three of these database libraries, and I'm wondering if they do anything to prevent SQL injection. I'm most likely going to be building a lib on top of one of them, and injection is a top concern I have in picking one. Anybody know?
Got with the author of the OTL library. A parameterized query written in "OTL Dialect," as I'm calling it, will be passed to the underlying DB APIs as a parameterized query. So parameterized queries would be as injection safe as the underlying APIs make them. Go to this other SO post for his full e-mail explanation: ...
3,118,741
3,121,382
memory leak: unable to break on a memory allocation number
I'm trying to locate a memory leak issue. My project is an ATL based dialog project, that uses DirectShow and the standard library. I get a total of 45 memory leaks in my program, all 24 bytes each. I've #define'd _CRTDBG_MAP_ALLOC etc in my stdafx.h, along with DEBUG_NEW to get the file and line numbers for each of th...
Two suggestions. Firstly, what gets constructed before main (or equivalent) starts gets destroyed after main finishes. Calling _CrtDumpMemoryLeaks at the end of main can give you false positives. (Or are they false negatives?) Global objects' destructors have yet to run, and atexit callbacks have yet to run, so the lea...
3,118,920
3,119,182
Building a project with CMake including other libraries which uses different build systems
I am working on an open source project which uses C for libraries, C++ for GUI and Cmake for managing build. This project is just started and have only couple of files. I can successfully generate makefiles on my linux development environment and on windows I can generate Visual Studio project files using CMake. All wo...
I'm using this CMakeLists.txt: #/**********************************************************\ #Original Author: Richard Bateman (taxilian) # #Created: Nov 20, 2009 #License: Dual license model; choose one of two: # New BSD License # http://www.opensource.org/licenses/bsd-license.php # ...
3,118,927
3,120,026
C++ Integer overflow problem when casting from double to unsigned int
I need to convert time from one format to another in C++ and it must be cross-platform compatible. I have created a structure as my time container. The structure fields must also be unsigned int as specified by legacy code. struct time{ unsigned int timeInteger; unsigned int timeFraction; } time1, time2; Mathem...
Just a guess, but are you assuming that 2e32 == 2^32? This assumption would make sense if you're trying to scale the result into a 32 bit integer. In fact 2e32 == 2 * 10^32
3,119,206
3,168,539
Weird unresolved external errors in linked objects
Using Visual Studio 10 C++, I'm having weird link error. For some reason references to a global object won't link to that global object. It is telling me a symbol is undefined yet when I have it view the .cod file the symbol is right there plain as day. The error: FTShell.lib(ftcommodule.obj) : error LNK2001: unresolve...
Strangely enough, the error was the result of setting the ImpLib property to a bad value. The property sheet said: <ImpLib>$(OneOfMyPathVars)\%(Filename).lib</Implib>. Since %(Filename) was empty during the link stage "C:\foo.lib" causes no ImpLib to be created. And that caused the unresolved externals from functions d...
3,119,222
3,119,262
casting LPCWSTR to LPCSTR
got this code from a website that helped me in creating buttons and stuff. the buttons work but for some reason im getting an compiler error with the creating a static. cannot convert from 'const wchar_t [5]' to 'char' cannot convert parameter 3 from 'char' to 'LPCWSTR' is there a simply way to fix this? i tried casti...
Try this instead: static TCHAR *lyrics = TEXT("Dood"); With the compiler settings you appear to have, TCHAR will be converted to wchar_t.
3,119,238
3,119,261
Whats wrong with this c++ reverse string function
void reverse (char s[]){ int len = strlen(s); int j = len - 1; for (int i = 0; i < j; i++,j--){ cout << s[i]; char ch = s[i]; s[i] = s[j]; //error line - giving exception, cannot write to the memory s[j] = ch; } } I am using Visual Studion 2008 and i can't understand whats the problem here .. :s .....
The problem is that it uses C-style strings instead of C++ style strings. In particular, you are apparently trying to write to a constant string literal: char const* str = "I cannot be written to"; C++ allows to omit the const here for backwards compatibility but the literal is still constant. Finally, C++ already has...
3,119,275
3,127,790
Custom draw CTreeCtrl: how to add font strike through?
I have implemented custom draw for an CTreeCtrl in my MFC Smart Device program. I have successfully changed the color of specific nodes of the CTreeCtrl. I am now trying to understand how to get the default font used to draw text in the control so I can add a strike-through to the font for certain nodes. How would I...
Use GetFont() to get the font of the control. Strike-through can't be done with ::DrawText AFAIK, but it's easy to just add a GoTo()/LineTo(). You can use GetTextExtent() to get the size of the bounding rectangle and derive the left/right of the strike through line from that.
3,119,405
3,119,451
Variable and loops convertion from VB.NET to C++?
Is there any available tool for converting variable and loops declarations from VB.NET to C++?
If you're talking about C++/CLI then you may consider using Reflector.NET to convert VB.NET to C++/CLI. If you're talking about managed/unmanaged bridge then .net framework does that for you (marshalling).
3,119,431
3,119,512
c++ rvalue passed to a const reference
I'm trying to understand exact C++ (pre C++0x) behavior with regards to references and rvalues. Is the following valid? void someFunc ( const MyType & val ) { //do a lot of stuff doSthWithValue ( val); } MyType creatorFunc ( ) { return MyType ( "some initialization value" ); } int main () { som...
The return value has the lifetime of a temporary. In C++ that means the complete expression that created the type, so the destructor of MyType shouldn't be called until after the call to someFunc returns. I'm curious at your 'is overwritten/freed'. Certainly calling delete on this object is not OK; it lives on the stac...
3,119,441
3,119,458
How can i make a text box that changes input constantly?
So I want to create a text box "static if possible" that when my user interacts with the story game the text inside changes to accommodate his action. so im guessing i want a pointer to the char variable, but it seems that i cant figure out how to do this... can someone help me please. im thinking create the static b...
To change the content of a standard Win32 textbox, you simply send the WM_SETTEXT message.
3,119,578
3,149,503
AIX 6.1 linker error
I'm trying to compile my application on AIX. It builds fine on Linux, Solaris x86 and Windows but this is the first time we've tried to build on AIX. I've managed to get to the point of linking all of the libraries together and I get the error message: Linking... ld: 0711-101 FATAL ERROR: Allocation of 96864 bytes fai...
The problem turned out to be the ulimit on the data seg size. Apparently that was still set quite small. Making it bigger like: ulimit -d 1048575 allows the linker to get further. Now to just figure out what I do about all of these undefined symbols.
3,119,650
3,119,742
How to set a zmq socket timeout
I've got client and server applications using zmq in the ZMQ_REQ context. What I'm experiencing is that when the server component goes down or is unavailable, the client will wait until it is available to send its message. Is there a way to set a max wait time or timeout at the client level?
I would guess you can use the zmq_poll(3) with a timeout greater then zero.
3,119,694
3,120,784
Compare matrices multiplication
I must multiply a matrix by itself until the matrix in some degree would not be equal to one of the preceding matrices. Then I need to get the values of degrees in which the matrices are equal. The number of rows and columns are equal. The matrix is stored in a two-dimensional array. Values are 0 or 1. What is the best...
If you can use boost, look at the boost Matrix class: It seems to be missing an == operator, but it's easy to add: #include <iostream> #include <boost/numeric/ublas/matrix.hpp> #include <boost/numeric/ublas/io.hpp> using namespace boost::numeric::ublas; template<typename T> bool operator==(const matrix<T>& m, const m...
3,119,714
3,119,774
Skipping Incompatible Libraries at compile
When I try to compile a copy of my project on my local machine, I get an error stating that it 's skipping over incompatible libraries. This isn't the case when I'm messing around with the live version hosted on the server at work [it makes perfectly there]. Various other sites have lead me to believe that this might ...
That message isn't actually an error - it's just a warning that the file in question isn't of the right architecture (e.g. 32-bit vs 64-bit, wrong CPU architecture). The linker will keep looking for a library of the right type. Of course, if you're also getting an error along the lines of can't find lPI-Http then you h...
3,119,842
3,119,978
Having difficulty in storing a QImage and then recovering it
Ok well I'm trying implement something similar to the 'undo' function in many image drawing programs .. The problem I'm having is this: I'm trying to make a backup copy of a QImage object in a QVector (which stores upto 10 latest QImage copies for backup purposes), and then try to retrieve these backups in another func...
It may has something to do with how you created image. If you use one of the constructors that takes a uchar * buffer (const or not), you have to make sure the buffer is valid through out the life of the QImage and its copies: http://doc.trolltech.com/latest/qimage.html#QImage-5 If at the time of your restoring of the ...
3,119,923
3,120,332
Creating an OS close button? (WinAPI)
I want to create a button that is basically Windows' close button. How could I do this? I want to avoid drawing this myself because I want it to look like that version of Windows' close button. Firefox's tabs do something like this. Thanks
You can get at Windows XP+ theme specific UI elements via the DrawThemeBackground API. Use WP_CLOSEBUTTON for the window X button (and one of CBS_NORMAL/HOT/PUSHED/DISABLED for its state) and you can draw one wherever you like.
3,119,929
3,120,537
Forwarding all constructors in C++0x
What is the correct way to forward all of the parent's constructors in C++0x? I have been doing this: class X: public Super { template<typename... Args> X(Args&&... args): Super(args...) {} };
There is a better way in C++0x for this class X: public Super { using Super::Super; }; If you declare a perfect-forwarding template, your type will behave badly in overload resolution. Imagine your base class is convertible from int and there exist two functions to print out classes class Base { public: Base(int n...
3,120,340
3,121,012
Visual Studio Addin "Exclude From Build" Property
I am currently trying to create an addin for Visual Studio 2008 that will list all files which are not excluded from the current build configuration. I currently have test C++ console application that has 10 files, 2 of which are "Excluded From Build". This is a property that will allow a specific file to be excluded ...
I'm not familiar with the Visual Studio object model, but in the documentation for VS2005 the following objects have an ExcludedFromBuild property: VCFileConfiguration VCFileConfigurationProperties VCPreBuildEventTool VCPreLinkEventTool VCPostBuildEventTool VCWebDeploymentTool Hopefully this will lead...
3,120,461
3,120,573
Should I learn Java or should I learn C++?
I have a pretty good non-OOP background. I've done lots of Visual Basic coding, and a little SQL. I want to widen my skillset and be more marketable. Most of my experience has been working with scientific companies, and I've been supporting scientists a lot. I want to take some online classes from my local community co...
I am a recent Computer Science graduate and from my job search I have to say that there are many more people wanting Java programmers than C++. I also saw a great deal of people looking for C# programmers. C++ is not being used as much outside of the academic and scientific field right now. Java and C# are also similar...
3,120,483
3,120,999
strange garbage data when opening a previously truncated file
In my program, I've redirected stdout to print to a file 'console.txt'. A function writes to that file like this: void printToConsole(const std::string& text, const TCODColor& fc, const TCODColor& bc) { // write the string cout << text << "@"; // write the two color values cout << ...
The routine that is writing is not resetting it's file position before rewriting to the file. As a result it starts off at an offset into the target file. I believe a cout.seekp(0) after performing the write will reset the write pointer, thus restarting the write at the start of the file. You're probably going to have ...
3,120,571
3,120,608
eclipse C++ add reference undefined reference to method error
I'm new to C++ and ecplice and they are definitely giving my a hard time :) I'm tring to write simple application that includes main project with refernces to other project i wrote the following file in shared project: #ifndef MANAGEDLOG_H_ #define MANAGEDLOG_H_ #include string #include iostream #include f...
You're not building ManagedLog.cpp. Your compile sequence should look something like this example (simplified for clarity): compile RunLog.c into RunLog.o compile ManagedLog.c into ManagedLog.o link RunLog.o and ManagedLog.o into RunLog.exe Steps 1 & 2 could be in the other order if you like.
3,120,951
3,120,974
g++ template problem
I'm porting my c++ windows code (msvc & intel) to Linux (g++). The code uses lots of templates (I like metaprogramming ;-). But I can't compile this code: template <class TA> struct A { template <class TAB> struct B; }; template <class TC> struct C {}; template <class TD> struct D { template <class TTD> cla...
You need the template keyword template<class TA> template<class TBA> struct A<TA>::B : C<typename D<TA>::template T<TBA> > { int foo; }; GCC is correct to give a diagnostic here. This is because T cannot be looked up in the dependent scope D<TA>. The meaning of the < after it depends on whether T is a templat...
3,121,308
3,121,395
Ensuring fields are only added to the end of a struct?
I have a rather odd problem: I need to maintain a chunk of code which involves structs. These structs need to be modified by adding fields to them from time to time. Adding to the end of a struct is what you are supposed to do, and any time you add a field to the middle of a struct, you've broken the code in a non-t...
you should probably use a form of struct inheritence (c -style) to make this a little easier for everyone to figure out basically you would have the struct you dont want modified //DO not modify this structure!!! struct Foo { int *Bar; int Baz; }; and a FooExtensions (or whatever) struct that people can modify w...
3,121,344
3,121,376
Why is only one implicit conversion allowed to resolve the parameters to a function in C++?
This works: #include<cstdio> class A{ public: A(int a):var(a){} int var; }; int f(A obj) { return obj.var; } int main() { std::cout<<f(23); // output: 23 return 0; } while this doesn't: #include<cstdio> class A{ public: A(int a, int b):var1(a), var2(b){} int var1, var2; }; int f(A obj...
The direct answer is that the C++ grammar does not combine function arguments into aggregates under any circumstances. In no case will a call to f(a, b) be treated as a call to f(c) where c is a value constructed from some combination of a and b. That's just not how the language works. Each argument is always treated s...
3,121,362
3,121,537
How to write modern Windows software in C++?
I am very interested in how modern Windows software is written in C++ nowadays. I asked my friend who had worked on Windows software and he told that last things he worked with were MFC and then WTL. He said that MFC is no longer anything modern but WTL is still used but he didn't know much more. He also said that WTL ...
From what I've seen over the past several years: WTL is on a lifeline. Abandoned by Microsoft, picked up by fans and there were several very dedicated followers. Very clean, but the learning curve is steep and the fan base dwindling. The Yahoo group is not very active. I can't recommend it. MFC got another lease o...
3,121,378
3,122,968
A tricky counter - just a int, but he won't work as requested
I'm near the end of a program I had got to code for my university courses, but I got into a last trouble: formatting the output! It's nothing about code: this is just cosmetics (but I need to fix that cause my output's got to respect some standards). Basically, my program will read a .csv file and process that by divid...
Notice that the number is always the row number of the row right before it appears. This suggests that counter++ is always executing. And sure enough, it is. Perhaps you meant to compare the values of the first elements of each cluster, instead of the iterator addresses? Based on the subsequent mapping you establish, ...
3,121,454
3,122,720
Is there a good library c/c++/java to generate video with special effects , transitions from a set of images?
I need to develop a video generator that takes in a set of images, music files and outputs mp4 videos. The platform is linux. Was wondering if there are any existing libraries that can do this job ? Thanks
I believe Processing can do what you want.
3,121,491
3,121,775
What to do with proxy class copy-assignment operator?
Consider the following proxy class: class VertexProxy { public: VertexProxy(double* x, double* y, double* z) : x_(x), y_(y), z_(z) {} VertexProxy(const VertexProxy& rhs) : x_(rhs.x_), y_(rhs.y_), z_(rhs.z_) {} // Coordinate getters double x() const {return *x_;} double y() const {return *y...
It's pretty simple. Do you want VertexProxy to act like a pointer, or a value? If you'd rather it acted like a pointer, then copy the pointers, if you'd rather it acted like a value, copy the values. Nobody can tell you that your class is a pointer or a value (especially since you seem to have something somewhat unusua...
3,121,523
3,121,544
C++: Construct subclass from base class instance?
I have three structs, one of which inherits from the other two: typedef struct _abc { int A; int B; int C; } ABC; typedef struct _def { int D; int E; int F; } DEF; typedef struct _abcdef : ABC, DEF { } ABCDEF; (I want the third struct to contain all the members of the first two. Is there a b...
This is C++. Those typedefs aren't needed. And you have constructors: struct abc { int A; int B; int C; abc(int a, int b, int c) : A(a), B(b), C(c) {} }; struct def { int D; int E; int F; def(int d, int e, int f) : D(d), E(e), F(f) {} }; struct abcdef : abc, def { abcdef(const abc& ...
3,121,716
3,121,888
Generating Java binding to a Qt based library
I'm writing a Qt based (QtCore) C++ library and would like to have access to it from Java and Python. Python is not a problem because of PySide and SIP. But I can't seem to find any information about doing the same with Java. The fact that Java bindings exist for Qt makes me hopefuly that there is a way to create bindi...
Qt Jambi included a generator that you could use on your own Qt classes. However, Nokia discontinued support for Jambi after v4.5. For technical details, see http://doc.qt.nokia.com/qtjambi-4.5.0_01/com/trolltech/qt/qtjambi-generator.html . Also, there's an early white paper still at http://www.sra.co.jp/qt/relation...
3,121,781
3,121,824
Assigning value passed by reference to a member variable (in C++)
I am trying to wrap my head about scope in C++. Please consider the following: class C { int i_; public: C() { i_ = 0;} C(int i) { i_ = i; } C(const C &c) { i_ = c.i_; cout << "C is being copied: " << i_ << endl; } int getI() { return i_; } ~C() {cout << "dstr: " << i_ << end...
Your code is fine as it stands right now. D::c_ is of type C rather than C &. Your SetC takes a reference to a C, and assigns the value referred to by that reference to C::c_, so what you have is an entirely separate C object that has the same value. Since you created d with automatic storage duration in main, it and c...
3,121,799
3,121,834
Automated testing of C++ console app in Visual Studio by sending text files to stdin?
I am going to take part in a coding contest my University is organizining next week. I am only allowed to use C or C++ and I would prefer to use the latter one using Visual Studio 2010. For every task there is a text input provided as plaintext to stdin, for example: 200 100 10 2 11 I need a tool which would assis...
You can do essentially the same thing with the Visual Studio compiler and the Windows command line: cl /EHsc mycode.cpp mycode.exe <test1.in >result1.out fc result1.out test1.out Though you might want a better diff tool than fc. You can also code up your code so the routine that does the real work is called with strea...
3,121,843
3,121,874
C++ template argument inference and string literals
I have a "set" data type: template <class V> struct Set { void add(const V& value) {} }; I want to write a top-level function version of Set::add. template <class V> void add(const Set<V>& set, const V& value) {} This doesn't quite work with string literals: Set<const char*> set; const char* val = "a"; set.add(val...
The problem is that V gets one type for the left parameter, and another type for the right one. I suspect you also want to be able to say add(setOfLong, 0) - but with that template you couldn't. I recommend to add a separate template parameter to solve this template <class SetV, class V> void add(const Set<SetV>& set, ...
3,122,155
3,122,261
std::map assignment of read only location
I have a static std::map<std::string, CreateGUIFunc> in a class that basically holds strings identifying gui types, and CreateGUIFunc is a reference to a factory function. In my constructor I have if ( m_factoryRef.size() == 0 ) { m_factoryRef["image"] = &CreateGUI<Image>; m_factoryRef["button"] = &CreateGUI<Button...
In C++, typedef GUI* CreateGUIFunc(); isn't a function with unspecified parameters, it's a function with NO parameters. So none of your functions match that type. What you want is typedef GUI* (*CreateGUIFunc)( std::string &filepath, int x, int y ); Next, try using the insert member function of the map instead of the...
3,122,284
3,122,361
In which case is if(a=b) a good idea?
Possible Duplicate: Inadvertent use of = instead of == C++ compilers let you know via warnings that you wrote, if( a = b ) { //... And that it might be a mistake that you certainly wanted to write: if( a == b ) { //... But is there a case where the warning should be ignored, because it's a good way to use this "fe...
Two possible reasons: Assign & Check The = operator (when not overriden) normally returns the value that it assigned. This is to allow statements such as a=b=c=3. In the context of your question, it also allows you to do something like this: bool global;//a global variable //a function int foo(bool x){ //assign t...
3,122,344
3,122,369
Boost C++ regex - how to get multiple matches
If I have a simple regex pattern like "ab." and I have a string that has multiple matches like "abc abd". If I do the following... boost::match_flag_type flags = boost::match_default; boost::cmatch mcMatch; boost::regex_search("abc abd", mcMatch, "ab.", flags) Then mcMatch contains just the first "abc" result. H...
You can use the boost::sregex_token_iterator like in this short example: #include <boost/regex.hpp> #include <iostream> #include <string> int main() { std::string text("abc abd"); boost::regex regex("ab."); boost::sregex_token_iterator iter(text.begin(), text.end(), regex, 0); boost::sregex_token_iter...
3,122,382
3,122,393
Using volatile long as an atomic
If I have something like this... volatile long something_global = 0; long some_public_func() { return something_global++; } Would it be reasonable to expect this code to not break (race condition) when accessed with multiple threads? If it's not standard, could it still be done as a reasonable assumption about mo...
No - volatile does not mean synchronized. It just means that every access will return the most up-to-date value (as opposed to a copy cached locally in the thread). Post-increment is not an atomic operation, it is a memory access followed by a memory write. Interleaving two can mean that the value is actually increme...
3,122,440
3,122,483
What do you call a single header whose purpose is to include other header files?
I've seen this done before in various C++ libraries - namely Qt (QtCore, QtGui, etc.) and Irrlicht (irrlicht.h): // file - mylibrary.h #include "someclass1.h" #include "someclass2.h" #include "someclass3.h" // and so on... Obviously this exists for convenience - a programmer wishing to use the library only has to inc...
That's a nice question :) I've found some sources that call it master header file, e.g: Apple Official Documentation An MSDN blog When it is used to host headers for the header precompiler, it could be called precompiler global header: http://www.rfoinc.com/docs/qnx/watcom/compiler-tools/cpheader.html However I don...
3,122,475
3,129,280
How do I get the giomm-2.4 package?
I am trying to build a GTK application (c++) using NetBeans. After including the gtkmm.h file I had to use the pkg-config tool to determine what it's dependencies where. I then added them to the included folders. Netbean complains that it cannot find 'giomm-2.4'. This package does not exist in /usr/lib and I cannot see...
Try this package: libglibmm-2.4-dev.
3,122,530
3,122,563
understanding Functors in STL
quoting from "The C++ Standard Library" by N M Jousttis, Section 5.9 #include < iostream> #include < list> #include < algorithm> using namespace std; //function object that adds the value with which it is initialized class AddValue { private: int the Value; //the value to add public: //construc...
The expression AddValue(*coll. begin()) creates one temporary object of class AddValue. That temporary is then passed to the for_each function. for_each then calls the object's function call operator - that is, operator() - once for each element from coll.begin() to coll.end(). Technically, for_each takes the functor p...
3,122,600
3,122,624
Radio style instead of MF_CHECKED for menu item?
I noticed some applications have a blue circular instead of a checkmark which MF_CHECKED produces. Which style produces this circular one? Thanks
Check out the MFT_RADIOCHECK menu type flag...
3,122,619
3,123,707
Migrating to Xcode and now having lots of "is not member of std" and some other header problems
I am migrating to OS X and now trying to use Xcode. There is a project that was compiling and running normally on a g++ linux distro, now on mac it is returning a thousand of errors. I guess that the linux std files, somehow included others files needed and now they are not this connected in the std of Mac OS X. How ca...
It looks like you're missing #include <string>.
3,122,667
3,129,740
Construct OpenCV element type in runtime
In OpenCV, when I need to create a cv::Mat, I will need to do something along the line of cv::Mat new_mat(width, height, CV_32FC3) What happens if I only know that I need the elements to be either float or double + whether I need 1/2/3 channels in runtime? In other words, given the element type (float) and number of c...
Read the source for cxtypes.h. It contains lines like the following: #define CV_32FC1 CV_MAKETYPE(CV_32F,1) #define CV_32FC2 CV_MAKETYPE(CV_32F,2) #define CV_32FC3 CV_MAKETYPE(CV_32F,3) #define CV_32FC4 CV_MAKETYPE(CV_32F,4) #define CV_32FC(n) CV_MAKETYPE(CV_32F,(n)) #define CV_64FC1 CV_MAKETYPE(CV_64F,1) #define CV_6...
3,122,678
3,122,689
how can a pixel in a bitmap can be deleted?
i m decreasing the resolution of a bitmap. i found a method on a site which is as follows Average the values of all surrounding pixels, store that value in the choosen pixel location, then delete all the surrounding pixels.so a 4*6 matrix becomes a 4 x 3 matrix. i am accessing pixels by this code for(int y = 0; y < bmp...
You can't really delete a pixel, a bitmap is a matrix of pixels. Rather, you should make a new bitmap of the intended size, and copy pixels into that.
3,122,695
3,122,743
What is an efficient way to wrap HWNDs in objects in C++?
I have been working with C++ and Win32 (non MFC/ATL) I am playing around with writing my own class library to wrap certain Win32 objects (HWNDs in particular). When it comes to creating windows, I find the "RegisterClassEx / CreateWindowEx" method very awkward. This design makes it hard to write simple class wrappers ...
ATL's CWindow and CWindowImpl are your friends. CWindowImpl makes takes care of the RegisterClass/CreateWindow awkwardness that you speak of. CWindow is a basic "wrapper" class for an HWND with all the win32 functions abstracted out. The reason I prefer ATL over MFC. ATL is a very lightweight set of classes with all t...
3,122,901
3,123,355
non-copying istringstream
So istringstream copies the contents of a string when initialised, e.g string moo("one two three four"); istringstream iss(moo.c_str()); I was wondering if there's a way to make std::istringstream use the given c_str as its buffer without copying things. This way, it won't have to copy large bits of memory before pass...
It's fairly trivial to write a basic std::streambuf class that reads from a given memory area. You can then construct an istream from this and read from that. initializing a C++ std::istringstream from an in memory buffer? Note that the lifetime of the buffer pointed to be c_str() is very limited, though, and there's n...
3,123,196
3,123,516
need help in contrast stretching
i have found this formula and its description on a site l(x,y)=(l(x,y)-min)(no of intensity levels/(max-min)) + initial intensity level where, I( x,y ) represents the images, on the left side it represents the output image, while on the right side it represents the xth pixel in the yth column in the input image. In th...
This is my attempt to code the formula. Based on the formula from Fisher et al. Note that you will still run into artificial looking images unless you use the cutoff fraction described in Fisher's article, but that is your own homework ;-) I didn't test this with real images, debugging it is also your homework. Refere...
3,123,328
3,123,517
Delete a Binary Tree with a Stack
I'm still working on my binary trees, and the insertion, lookup, maximum, minimum functions are all working great so far. So I want to do a deletion function next. I included a Stack which saves- ah hell, I'll just show the code: class Tree { private: int value_; Tree *root_; Tree *left_; Tree *right_; ...
You're crashing in deque because the stack contains one of those. If you look at the stack trace after the crash, then you can find out what your code was doing when it happened. It looks like the final snippet of code is putting the wrong node on the stack; surely it should be the newly created node, not the insertion...
3,123,340
3,123,528
PyS60 vs Symbian C++
I'm planning some Symbian related development on S60 3.1 platform. It seems like generally available language options are Python and C++. However Nokia's official forum seems very much tilted towards C++. I want to know what are the advantages and disadvantages of using Python for S60 over Symbian C++? And is it even p...
PyS60 is good when you need to prototype something simple fast. If you try to develop a full application with it though, you'll most likely find yourself sooner or later wanting to use features that are available in Symbian C++ but not in PyS60 without writing bindings (in C++) for it. Also you'll need to deal with the...
3,123,479
3,123,584
How do I fit a variable sized char array in a struct?
I don't understand how the reallocation of memory for a struct allows me to insert a larger char array into my struct. Struct definition: typedef struct props { char northTexture[1]; char southTexture[1]; char eastTexture[1]; char westTexture[1]; char floorTexture[1]; char ceilingTexture[1]; } P...
Is this C or C++? The code you've posted is C, but if it's actually C++ (as the tag implies) then use std::string. If it's C, then there are two options. If (as you say) you must store the strings in the structure itself, then you can't resize them. C structures simply don't allow that. That "array of size 1" trick is ...
3,123,699
3,123,780
C++ multiple operator overloads for the same operator
I know I can answer this question easily for myself by generatin the code and see if it compiles. But since I couldn't find a similar question, I thought it's knowledge worth sharing. Say I am overloading the + operator for MyClass. Can I overload it multiple times. Different overload for different types. Like this: c...
The canonical form of implementing operator+() is a free function based on operator+=(), which your users will expect when you have +. += changes its left-hand argument and should thus be a member. The + treats its arguments symmetrically, and should thus be a free function. Something like this should do: //Beware, br...
3,123,939
3,123,972
Thread Local Storage
When you allocate some TLS for thread A in a slot, can you then access that same slot from Thread B? Is it internally synchronized or how does that work?
The local variables of a function are unique to each thread that runs the function. This can be accomplished with help of TLS which as already mentioned is local for each thread. If you want to share some data between threads there are several options starting from using global or static variables up to memory mapped ...
3,123,980
3,123,991
Explanation of ambiguity in function overloading for this example in C++
I'm reading Stroustrup's book, the section on overloading and related ambiguities. There's an example as follows: void f1(char); void f1(long); void k(int i) { f1(i); //ambiguous: f1(char) or f1(long) } As the comment states, the call is ambiguous. Why? The previous section in the book stated 5 rules based on ...
Anything goint from int above isn't a promotion anymore. Anything going less than int to int is a promotion (except for rare cases - see below) So if you change to the following it becomes non-ambiguous, choosing the first one void f1(int); void f1(long); void k(unsigned short i) { f1(i); } Notice that this is on...
3,124,015
3,124,027
Weird auto-initialization behavior
I learned that auto-variables aren't initialized to zero. So the following code will behave correctly and prints random numbers on the screen: #include <iostream> using std::cout; using std::endl; void doSomething() { int i; cout << i << endl; } int main() { doSomething(); } But why won't this snipped behave i...
Using an uninitialized variable is undefined behaviour. It's likely you wouldn't get the same behaviour on another compiler. The only 'why' is to be found inside the source code to your specific C++ compiler.
3,124,066
3,124,077
Is it safe if a virtual function refers to variable in a derived class in C++?
When derived is cast back into base. By safe, I mean it works properly for known c++ compiler. It seems to be working for VIsual C++ 2008. E.g class zero { virtual int v()=0; } class a: public zero { public: int value; a(int vin) { value =vin; } int v() { return value; } } zero *e1=...
It is safe and fully correct behaviour. That is the reason why you have virtual or pure virtual methods. Most of the time you will want to hide implementation details and manipulate objects through their interface (or pure virtual class). That is standard and all C++ compilers must support it.
3,124,082
3,124,111
How can I pass a variable from class element to class element? (C++)
My question might not be too correct... What I mean is: class MyClass { public: MyClass() { } virtual void Event() { } }; class FirstClass : public MyClass { string a; // I'm not even sure where to declare this... public: FirstClass() { } virtual void Event() { ...
What you need to do is make SecondClass inherit from FirstClass and declare _This as protected. class FirstClass : public MyClass { protected: string _This; public: and class SecondClass : public FirstClass What you got doesn't make sense because classes can only see members and functions from their parents (MyC...
3,124,094
3,124,158
Do rvalue references allow implicit conversions?
Is the following code legal? std::string&& x = "hello world"; g++ 4.5.0 compiles this code without any problems.
This is discussed on usenet currently. See Rvalue reference example in 8.5/3 correct or wrong?. It's not legal.
3,124,307
3,124,320
Inlined constructors? Explain this behavior[C++]
Consider this code #include <iostream> #include <cstdio> using namespace std; class Dummy { public: Dummy(); }; inline Dummy::Dummy() { printf("Wow! :Dummy rocks\n"); } int main() { Dummy d; } All is good here! Now I do this modification. I move the declaration of Dummy to "dummy.h". class Dummy { publ...
You have to put all inline functions (including methods and constructors/destructors) in a header file, where they are declared. Though this code should work either way, with main() calling the constructor as if the inline keyword was not there. Are you sure you are passing object files from both compilation units to t...
3,124,328
3,124,336
C++ : iterating the vector
I'm very new to C++ and I'm trying to learn the vector in C++.. I wrote the small program as below. I like to foreach(var sal in salaries) like C# but it doesn't allow me to do that so I googled it and found that I have to use iterator.. Im able to compile and run this program but I dont get the expected output.. I'm g...
You created a vector with 5 elements, then you push 10 more onto the end. That gives you a total of 15 elements, and the results you're seeing. Try changing your definition of the vector (in particular the constructor call), and you'll be set. How about: vector<int> salaries;
3,124,467
3,124,494
Tool to identify the similarities in logic between a function of C and C++
Is there a tool in either Linux/Windows that would enable us to determine if a logic of the particular function in C is same as that of a particular function in C++ ?
In general, the equivalence of Turing machines is undecidable, so no.
3,124,595
3,124,638
Multiple declaration for function
I have a function declared in my base class and specified as virtual, I am trying to re-declare it in a derived class but I'm getting a multiple declaration error. Anyone know if I'm missing something here? class Field { public: virtual void display() = 0; virtual int edit() = 0; virtual boo...
You have a function named data and a member variable named data in the same class. That's not allowed. Pick a different name for your member variable. You also appear to be re-declaring many member variables. That's probably not what you want to do. If you want to declare them in the base class and use them in descenda...
3,124,729
3,124,756
Where in memory are variables stored in C++?
If I have code like this: int e; int* f; int main() { int a, b, c; int* d; } Where in memory are these variables stored? And, what's the problem with defining global variables (out of a function, like main in this case)?
a,b,c and d will exist on the stack. If you were to create an instance of an int (with malloc or new), that would go on the heap - but the pointer called 'd' would still exist on the stack. e and f are allocated space in the memory space of the app, in the so-called 'Data segment' - see: http://en.wikipedia.org/wiki/...
3,124,837
3,124,945
Multithreading in C++ ... where to start?
I'd like to start learning multithreading in C++. I'm learning it in Java as well. In Java, if I write a program which uses multithreading, it will work anywhere. However in C++, doesn't multithreading rely on platform-specific API's? If so, that would seem to get in the way of portability. How can I do multithreading ...
If you do not have a compiler that supports C++0x yet (available with visual studio c++ 2010 for example), use boost threads. (Unless you use a framework that already supports threading, which is not the case - you wouldn't ask the question otherwise -). These boost threads became actually the standard in the brand new...
3,124,990
3,125,007
Clear an Array to NULL without knowing the type
I have to create a function that can take in an array of pointers with a known size, and set all the pointers to NULL. The caveat is that I don't know the type beforehand. This is what I have tried so far: template <typename T> static void Nullify(T** _Array, int _Size, unsigned int _SizeOf) { for (int i = 0...
You don't need _SizeOf. This is what you want: template <typename T> static void Nullify(T** _Array, int _Size) { for (int i = 0; i < _Size; i++) { _Array[i] = NULL; } } The compiler knows the size of a pointer, and does the math for you during the array dereference.
3,125,003
3,125,035
Two dimensional arrays allocation problem
this is an interview question my friend was asked yesterday. The question was something like: will this program crash with an "access violation" error or not? I looked at it for a while and thought no, it won't. But actually trying this out in visual studio proved me wrong. I cannot figure out what happens here... or t...
You are passing the double pointer "matrix2" by value. Therefore, when matrixAlloc finishes doing its thing, "matrix2" will still be whatever it was before the function was called. In order to get the change to populate, consider passing matrix2 by reference: int** matrix2 = NULL; matrixAlloc(&matrix2, 4, 5); ... Don'...
3,125,090
3,126,467
<string.h> conflicting with my own String.h
I have a project that was compiling ok within g++(I can't see the version right now) and now on xCode it is not. I think that I got the problem now... I have a String.h file in my project and it seems tha the xCode compiler(that is gcc) is trying to add my own string file from the < cstring >... I am not sure of it, bu...
Naming your headers with the same name as standard headers like string.h and including them simply with #include <String.h> is asking for trouble (the difference in casing makes no difference on some platforms). As you said, however, it would be difficult to try to figure out what those are in advance when naming your ...
3,125,136
3,125,156
C++ header file question
I was trying out some c++ code while working with classes and this question occurred to me and it's bugging me a little. I have created a header file that contains my class definition and a cpp file that contains the implementation. If I use this class in a different cpp file, why am I including the header file inste...
Because when you're compiling another file, C++ doesn't actually need to know about the implementation. It only needs to know the signature of each function (which paramters it takes and what it returns), the name of each class, what macros are #defined, and other "summary" information like that, so that it can check t...
3,125,547
3,125,558
Algorithms that can take an N length string and return a fixed size unique value?
I'm looking to add basic licensing to my application. I want to take in the user's name as a parameter and return a unique, fixed length code (sort of like MD5) What are some algorithms that can do this? Thanks
The SHA algorithms should be decent for this (SHA-1, SHA-512, etc...). They are used in a lot of places where an MD5 could also be used but seem to be more well respected. I use them for password hashing, but sounds like their functionality as a 1-way hash would be good for this as well. If you want fixed sized, you ...
3,125,552
3,125,660
How to reverse data using an array of pointers (parse binary file)
I am parsing a binary file using a specification. The file comes in big-endian mode because it has streamed packets accumulated. I have to reverse the length of the packets in order to "reinterpret_cast" them into the right variable type. (I am not able to use net/inet.h function because the packets has different lengt...
Not quite. The file comes in big-endian mode because it has streamed packets accumulated. I have to reverse the length of the packets in order to "reinterpret_cast" them into the right variable type. You need to reverse the bytes on the level of stored data, not the file and not the packets. For example, if a file st...
3,125,582
3,125,855
boost spirit qi numeric parsing of integer and floating points
i am trying to make sense of the following result. The test case code is #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_fusion.hpp> #include <b...
For your specific example, I think it's actually described in the Boost Spirit documentation under RealPolicies Specialization. To make things a bit easier for you, I whipped out a quick "real" parser, that only parses real numbers and not integers(or at least it worked with your simplified examples): template <typenam...
3,125,679
3,125,695
Cross Platform File Exists & Read In C++
How can I write two simple cross platform (Linux, Windows) functions for reading text file, and determine if some file exists? I don't want to use a big library like Boost.IO for that. It's a very small plugin for some software and I don't think it's neccsary. Thanks.
The standard library should be sufficient. access will tell you if a file exists, and (if it's there) you can read with a normal std::ifstream.
3,125,702
3,125,758
C++: Are YOU using Loki or Boost for functors ?
I've been reading Alexandrescu's book, Modern C++ design , and I've been quite impressed by the techniques he uses, so I wanted to add Loki library to my application. However, after further investigation, I saw that boost, that I'm already using, provides a lot of similar functionality (not all though, I couldn't find...
I'm using Boost in my whole C++ environnement like an extension to the Standard Library (with VC9 and VC10). I don't use it on all projects. I use it on personal projects (mostly games) where I got full control of what are the dependencies. I'm using boost::function in a big game project (with several other libraries ...
3,125,715
3,125,755
How can this compile? (delete a member of const object)
I would expect an error inside the copy constructor, but this compiles just fine with MSVC10. class Test { public: Test() { p = new int(0); } Test(const Test& t) { delete t.p; // I would expect an error here } ~Test() { delete p; } private: int* p; };
The issue that you are running into here is that you are not changing p per se (thus pstays immutable as you're not changing its value), but you're changing what p points to and thus are working at one additional level of indirection. This is possible because deleteing the memory associated with a pointer doesn't chang...
3,125,731
3,125,806
private object pointer vs object value, and returning object internals
Related to: C++ private pointer "leaking"? According to Effective C++ (Item 28), "avoid returning handles (references, pointers, or iterators) to object internals. It increases encapsulation, helps const member functions act const, and minimizes the creation of dangling handles." Returning objects by value is the only ...
The Google C++ style guide is, shall we say, somewhat "special" and has led to much discussion on various C++ newsgroups. Let's leave it at that. Under normal circumstances I would suggest that following the guidelines in Effective C++ is generally considered to be a good thing; in your specific case, returning an obje...
3,125,742
3,125,749
'No matching function' -error when trying to insert to a set (c++)
I have the following code: class asd { public: int b; asd() { b = rand() % 10; } bool operator<(asd &other) { return b < other.b; } }; int main() { asd * c; c = new asd(); set <asd> uaua; uaua.insert(c); } Yet when running it, I get this error: main.cpp|36|error: no match...
You have a set of asd, and you're trying to add a pointer. Use: asd c; set <asd> uaua; uaua.insert(c);
3,125,810
3,125,853
Reading a number from file C++
I have a file with a simple number, for example: 66 or 126 How can I read it to a int value in C++? Note that the file may also contain some spaces or enters after the number. I started like so: int ReadNumber() { fstream filestr; filestr.open("number.txt", fstream::in | fstream::app); filestr.close() }...
I don't really know why people are using fstream with set flags when he only wants to do input. #include <fstream> using namespace std; int main() { ifstream fin("number.txt"); int num; fin >> num; return 0; }
3,125,872
3,125,878
Unsigned Long Long Won't Go Beyond The 93th Fibonacci Number?
Here's the code I wrote for finding the n-th Fibonacci number: unsigned long long fib(int n) { unsigned long long u = 1, v = 1, t; for(int i=2; i<=n; i++) { t = u + v; u = v; v = t; } return v; } While the algorithm runs pretty quickly, the output starts to freak out when ...
http://gmplib.org/ GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers. There is no practical limit to the precision except the ones implied by the available memory in the machine GMP runs on. GMP has a rich set of functions, and the func...
3,125,950
3,126,136
C++ weird syntax spotted in Boost template parameters
I was having a look at the "Function" class documentation in Boost, and stumbled across this: boost::function<float (int x, int y)> f; I must admit this syntax is highly confusing for me. How can this be legal C++ ? Is there any trick under the hood ? Is this syntax documented anywhere?
[Edit] This is an answer to the author's original, unedited question which was actually two questions. I must admit this syntax is highly confusing for me. How can this be legal C++ ? :) Is there any trick under the hood ? Is this syntax documented anywhere ? This is perfectly legal and it's actually not too ...
3,126,106
3,127,350
What's the best way to have a variable number of template parameters?
Please consider this -probably poorly written- example : class Command; class Command : public boost::enable_shared_from_this<Command> { public : void execute() { executeImpl(); // then do some stuff which is common to all commands ... } // Much more stuff ... private: ...
Interesting question :) First of all, there is an issue you overlooked: you need a common base class for all Command and this class cannot be templated if you are going to use a stack of them (for undo/redo). Therefore you are stuck with: class Command { public: void execute(); private: virtual void executeImpl() ...
3,126,141
3,126,245
Getting text from tab control item is failing
I'm trying to get the text from a tab control like this: TCITEM itm; itm.mask = TCIF_TEXT; TabCtrl_GetItem(engineGL.controls.MainGlTab.MainTabHwnd,i,&itm); but the psztext part of the structure is returning a bad pointer (0xcccccccccc). I create the tabs like this: void OGLMAINTAB::AddTab( char *name ...
When setting the text, cchTextMax is ignored. When getting the text, you need to provide your own buffer and set cchTextMax accordingly. (Note that when the message returns, you need to use the itm.pszText pointer and not your own buffer since the control will sometimes change the pszText member to point to its interna...
3,126,448
3,126,455
Install my compiled libs in the system to be used by an executable
I am using Xcode and, after some struggling, it is compiling my dynamic libraries okie dokie for now. My kinda-problem now is that I need to use those libs with another project, that is an executable. I would like that Xcode, after compiling my libs, copy them to the executable folder, or, better, copy the libs to a...
Perhaps the "Copy Files" build phase can do this for you. Select "Absolute Path" and then maybe "only when installing". Ah, so here's the documentation you want (first section after intro, "Build Locations"): http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/XcodeProjectManagement/210-Bu...
3,126,463
3,128,320
Handling large scale dataset
From the online discussion groups and blogs, I have seen a lot of interview questions are related to handling large scale dataset. I am wondering is there a systematic approach to analyze this type of questions? Or in more specific, is there any data structure or algorithms that can be used to deal with this? Any sugge...
"Large-scale" data sets fall into several categories that I've seen, each of which presents different challenges for you to think about. Data that's too big to fit in memory. Here, some key techniques are: Caching data that's frequently used for better performance Working on data from a file a chunk at a time instea...
3,126,646
3,540,788
Please suggest a user-mode filesystem filter framework
I need a user-mode filesystem filter (not virtual filesystem). One of such frameworks is http://eldos.com/cbflt/, but it has some bugs and I need an alternative. Can you please suggest similar frameworks.
CallbackFilter is the only filter driver solution available. You mention dokan and fuse, but they are not filters, they are file system drivers (like Callback File System). This is a very different thing. If you have problems with CallbackFilter, please report them to tech.support and we will address the issues ASAP.
3,126,664
3,127,289
Function doesnt want to take my argument?
A friend sent me his threading class. Now I just want to run a listener but the thread doesnt want to accept the function. I want to execute the function (defined in static class Networks) THREAD listen(void* args). THREAD is a #define THREAD unsigned __stdcall Networks::init() { listenerth = thread(); listenerth.r...
As others say, you can't use a non-static member function here, because it expects a normal function pointer. If you need to call a non-static member (because it needs to access state in the class), then you could use the args argument to call it via a static "trampoline" function, something like this: unsigned listen(...
3,126,669
3,126,688
When to Return a Recursive Function?
I have a question on return and recursive functions. This is again based off of a binary Tree which I am currently working on. The code is void Tree::display() { if( !root_ ) return; display_r(root_); } void Tree::display_r(Tree *node) { if( 0 == node ) return; display_r(node->left_);...
I suggest studying the return keyword more carefully and also practicing recursion a bit more. return display_r(node->left_); // this following code would not be executed in your example, // you've already returned out of the function! std::cout << node->value_ << std::endl; return display_r(node->right_); Here the re...
3,126,795
3,126,810
C++ looking for String.Replace()
i have a a char array in C++ which looke like {'a','b','c',0,0,0,0} now im wrting it to a stream and i want it to appear like "abc " with four spaces insted of the null's i'm mostly using std::stiring and i also have boost. how can i do it in C++ basicly i think im looking for something like char hellishCString[7] =...
Use std::replace: #include <string> #include <algorithm> #include <iostream> int main(void) { char hellishCString[7] = {'a','b','c',0,0,0,0}; // comes from some wired struct actually... std::string newString(hellishCString, sizeof hellishCString); std::replace(newString.begin(), newString.end(), '\0', ' '); st...
3,126,806
3,126,854
When embedding Java in a C++ application, which files do I need to take?
Our C++ application hosts Sun's JVM and I need to upgrade it to the newest version on Windows. I downloaded JDK 6u20, but I have no idea which folders to take into our installation. We currently have some version of Java 5 but it seems that whoever did it in the first place, cherry picked the files. I'd like to know wh...
Without knowing your application, it's not possible to say which files can be left out, so I'd say use the entire JRE. However, you can find out which files the original creator of the installer didn't select by comparing the installer's JRE files with the original JRE. You can then write up these files and take a gues...
3,126,918
3,126,966
parse variable from php to a c++ function as an argument
I have a web server which receives an image from a client and do some SIFT based image matching at the server (win32) end send the result back to the client. Receiving image is done using apache and php. SIFT based processing functions are in C++. Now I want to parse the data in php variable $image (the variable which ...
save the image to a file. you may use file_put_contents... use system('cpp_program "/path/to/image"') function to run the program.(or does it take image data as an argument? that would be strange). these functions return the console output of the run program. that's what i would do: $tmpFileName = tempnam(); file_put...