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
2,799,243
2,799,296
Segmentation Fault in prime number sieve
when I run this program while inputting a number greater than 46348, I get a segmentation fault. For any values below it, the program works perfectly. I am using CodeBlocks 8.02 on Ubuntu 10.04 64-bit. The code is as follows: int main() { int number = 46348; vector<bool> sieve(number+1,false); vector<int> ...
Assuming you are on a common architecture, the problem is that the i*i calculation overflows. The result can not be stored in a signed 32 bit integer. You can try adding cout << temp << endl; after this calculation. In the end it will print: 2144523481 2146190929 2147117569 -2146737495 Segmentation fault For the futur...
2,799,412
2,802,312
How to use QMetaMethod with QObject::connect
I have two instances of QObject subclasses and two QMetaMethod instances of signal in one of objects and slot in another object. I want to connect this signal and slot with each other. I've looked through the qobject.h file and find that SIGNAL() and SLOT() macro are just add "1" or "2" character to the beginning of me...
It looks like there is no way to make it work without relying on internal implementation. If I were you, I'd submit feature request to Qt bug tracker, write a code that mimics current behavior SIGNAL/SLOT macros and add unit test that will fail when SIGNAL/SLOT behavior changes. There might be a simpler solution to the...
2,799,620
2,799,676
windows keydown listeners in C
I am having a very hard time finding resources that talk about the windows message system. Mainly the keydown constant variables. I need to know what const varibles I need to listen for all keypress especially the arrow keys for C
There is a winuser.h header file found in your SDK's installation which lists all the VK_ (Virtual Keys) which are key codes that you require, specifically VK_UP, VK_RIGHT, VK_LEFT and VK_DOWN for the up/right/left/down cursor keys respectively.
2,799,682
2,799,693
C++ includes with and without .h
Possible Duplicate: What is the difference between using #include<filename> and #include<filename.h> in c++ I've never noticed it making any difference whether or not I include the .h at the end of an include, so I've always ignored the meaning, but I've just noticed in a particular program of mine, I get the error ...
<string> is the C++ standard library string header file containing std::string and its friends. <string.h> is a different header, from the C standard library, which has functions for manipulating C strings (null-terminated strings) and other related functions. The two are entirely different and unrelated. In C++ (as ...
2,799,684
2,799,708
x86-64 long double precision
What is the actual precision of long double on Intel 64-bit platforms? is it 80 bits padded to 128 or actual 128 bit? if former, besides going gmp, is there another option to achieve true 128 precision?
x86-64 precision is the same as regular x86. Extended double is 80 bits, using the x87 ISA, with 6 padding bytes added. There is no 128-bit FP hardware. A software implementation of quad or extended quad precision might benefit from the x86-64 64x64 => 128 integer multiply instruction, though.
2,799,739
2,799,748
Load XML from string in libxml++ in C++
Does anyone familiar with libxml++ know if it's possible to load the XML document from a string instead of a file? Alternately, if it can load a document directly from a web page, that would do. Thanks
It sounds like you are looking for either xmlpp::Parser::parse_memory or xmlpp::DomParser::parse_memory. Each of those classes also have a parse_stream method which take a std::istream if that is more convenient.
2,799,789
2,799,804
What C++ library do I need to get this program to compile
When I try to compile my program I get these errors: btio.c:19: error: ‘O_RDWR’ was not declared in this scope btio.c:19: error: ‘open’ was not declared in this scope btio.c: In function ‘short int create_tree()’: btio.c:56: error: ‘creat’ was not declared in this scope btio.c: In function ‘short int create_tree(int, i...
You want: #include <fcntl.h> /* For O_RDWR */ #include <unistd.h> /* For open(), creat() */ Also, note that, as @R Samuel Klatchko writes, these are not "libraries". What #include does is inserts a file into your code verbatim. It just so happens that the standard header fcntl.h will have a line like: #define O...
2,799,876
2,799,903
Is compiler able to do a procedural integration of functions imported from dll?
I know, that modern compilers can do procedural integration not only with functions defined inline, but also with functions residing in object files. But is this also true when you compile your program against shared library (especially dll)? Roughly speaking: will function code be copied into executable from dll, if t...
No, because the compiler does not have the code that makes up those functions. On Windows, when you link against a dynamic library, you usually include a header and link against an import library, which simply contains the code to load the dynamic library and obtain pointers to the functions that you call (technicall...
2,799,966
2,800,029
How to traverse a Btree?
I have a Btree and I'm trying to figure out how traverse it so that the keys are displayed ascending order. All I can figure out is that this can be done with a recursive function. What's the pseudo-code to do it?
Assuming you have a definition like: template <class T> class btree_node { btree_node **child; // an array of child nodes T **element; // the elements in this node unsigned int child_count; // the number of children // the number of elements is 1 less then child_count }; Th...
2,799,972
2,799,990
Canny edge detection - grayscale images always coming up as 3-channel, unusable?
I am working through the book "Learning OpenCV" from the O'Reilly series and am trying to perform a canny edge detection sample. Any grayscale image I choose seems to come up as having 3 channels, and to the best of my knowledge, canny only works with single channel images, so this always fails. I am even using the ...
You can use this method with another parameter IplImage* cvLoadImage(const char* filename, int iscolor=CV_LOAD_IMAGE_COLOR) #define CV_LOAD_IMAGE_COLOR 1 #define CV_LOAD_IMAGE_GRAYSCALE 0 #define CV_LOAD_IMAGE_UNCHANGED -1 The default parameter is load image with color. What you have to do is to load it wi...
2,800,064
2,800,070
singly linked list in the C++ standard library or other widely-used libraries?
Seems that there is only doubly linked list (but no singly linked list) in the C++ standard library, right? Is there any widely-used C++ libraries with singly linked list?
There is slist, which is an SGI extension (__gnu_cxx::slist) #include <iostream> #include <iterator> #include <ext/slist> int main(int argc, char** argv) { __gnu_cxx::slist<int> sl; sl.push_front(1); sl.push_front(2); sl.push_front(0); std::copy(sl.begin(), sl.end(), // The output is 0 2 1 std::...
2,800,138
2,800,312
Mac laptop usage and development discussion?
I bought a new Mac book (MacBook Pro), and I am previously using Windows. I use this MacBook for personal (e.g. instant messaging, document, browsing the web) and development (writing C++ and Java code) purpose. Any recommended discussion group or forums (or I can directly ask here in StackOverflow)? I am a newbie.
Yes, you may be interested in my Development Environment Setup guides. I currently develop on Mac OS X 10.6 Snow Leopard. My recommendation is to install Xcode and MacPorts. I tend to edit everything using Xcode, and I use MacPorts to install pretty much all the various libraries (except Qt, for which it is more sensib...
2,800,143
2,800,160
Why does the answer print out twice?
I made a program that returns the product abc where a,b,c are pythagorean triples and add up to 1000. The program does output the correct answer but does it twice. I was curious as to why this is so. After playing around with it a bit I found out that it prints out when a = 200 b = 375 c = 425. And once again when a =...
Break, in this case, will only break out of the c loop, not the b and a ones. A quick fix is to ensure you don't get repeats by starting each variable greater than or equal to the previous (so b is never less than a and c is never less than b). In addition, you can actually get rid of the c loop altogether since there'...
2,800,250
2,800,357
Sum of all primes under 2 million
I made a program that returns the sum of all primes under 2 million. I really have no idea what's going on with this one, I get 142891895587 as my answer when the correct answer is 142913828922. It seems like its missing a few primes in there. I'm pretty sure the getPrime function works as it is supposed to. I used it ...
The expression i*i overflows because i is an int. It is truncated before being assigned to temp. To avoid the overflow, cast it: static_cast<unsigned long>( i ) * i. Even better, terminate iteration before that condition occurs: for(int i = 2; i*i <= number; i++). Tested fixed. Incidentally, you're kinda (un)lucky that...
2,800,297
2,805,470
Design patterns commonly used for RTOS (VXworks)
Can anyone help me on design patterns commonly used for RTOS? In VXworks, which pattern is more preferable?
Can we ignore the second sentence in your question? It is meaningless, and perhaps points to a misunderstanding of design patterns. The first part is interesting however. That said, I would generalise it to cover real-time systems rather than RTOS. Many of the most familiar patterns are mechanistic, but in real-time...
2,800,642
2,800,654
Interop c# using a "long" from c++
On my System: sizeof(long) in c++ is 4 aka 32bits sizeof(long) in c# is 8 aka 64 bits So in my Interop method declarations I've been substituting c++ longs with c# int's however I get the feeling this isn't safe? Why is a long the same size as an int in c++? And long long is 64bits? What's next a long long long long??...
Best thing to do assuming you have a recent C library is to include <stdint.h> and use uint64_t, int64_t, uint32_t, int32_t. This will works regardless of model of the underlying platform. But if you are curious, the underlying issue is that different systems use different models. On 32 bit systems, both Posix and Wi...
2,801,034
2,801,058
Using C++ to find out how many lines are in a text file
My C++ program needs to know how many lines are in a certain text file. I could do it with getline() and a while-loop, but is there a better way?
No. Not unless your operating system's filesystem keeps track of the number of lines, which your system almost certainly doesn't as it's been a looong time since I've seen that.
2,801,097
2,801,314
Where to add an overloaded operator for the tr1::array?
Since I need to add an operator& for the std::tr1::array<bool, N> I wrote the following lines template<std::size_t N> std::tr1::array<bool, N> operator& (const std::tr1::array<bool, N>& a, const std::tr1::array<bool, N>& b) { std::tr1::array<bool, N> result; std::transform(a.begin(), a.end(), b.begin(), ...
I fully support GMan and sbk who told you to use a named function instead of an operator. Contrary to popular believe, overloading operators is always almost wrong, because it almost never adds clarity to the code. There are surprisingly few exceptions. Among them are the stream input and output operators as well as th...
2,801,315
2,801,605
Disable debug output in libxml2 and xmlsec
In my software, I use libxml2 and xmlsec to manipulate (obviously) XML data structures. I mainly use XSD schema validation and so far, it works well. When the data structure input by the client doesn't match the XSD schema, libxml2 (or xmlsec) output some debug strings to the console. Here is an example: Entity: line 1...
I would investigate the xmlSetGenericErrorFunc() and xmlThrDefSetGenericErrorFunc() functions, they seem right. The documentation is .. sparse, though. Here is some Python code that seems to use these functions to disable error messages, the relevant lines look like this: # dummy function: no debug output at all cdef v...
2,801,426
2,806,541
How do I know if a boost thread is done?
I am using boost::thread to process messages in a queue. When a first message comes I start a message processing thread. When a second message comes I check if the message processing thread is done. if it is done I start a new one if it is not done I don nothing. How do I know if the thread is done ? I tried with join...
Spawning a new thread for each incoming message is very inefficient. You should check out the Thread pool pattern. EDIT: Sorry, jules, I misread your question. I recommend you take a look at the producer-consumer pattern. Check out this article on how to roll your own blocking queue using boost condition variables. Int...
2,801,484
2,801,586
weighted RNG speed problem in C++
Edit: to clarify, the problem is with the second algorithm. I have a bit of C++ code that samples cards from a 52 card deck, which works just fine: void sample_allcards(int table[5], int holes[], int players) { int temp[5 + 2 * players]; bool try_again; int c, n, i; for (i = 0; i < 5 + 2 * players; i++...
Your reject collisions are turning an O(n) algorithm into (I think) an O(n^2) operation. There are two ways to select cards from a deck: shuffle and pop, or pick sets until the elements of the set are unique; you are doing the latter which requires a considerable amount of backtracking. I didn't look at the details of ...
2,801,532
2,801,717
make include directive and dependency generation with -MM
I want a build rule to be triggered by an include directive if the target of the include is out of date or doesn't exist. Currently the makefile looks like this: program_NAME := wget++ program_H_SRCS := $(wildcard *.h) program_CXX_SRCS := $(wildcard *.cpp) program_CXX_OBJS := ${program_CXX_SRCS:.cpp=.o} program_OBJS :=...
You are relying on an implicit rule to compile your .cpp files. You have to redefine it to use the -MM and -MF flags that will create the dependency file. %.o: %.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ -MM -MF $@.d Then, you have to include these dependencies files in the Makefile, using -include that will ...
2,801,666
47,693,140
Wrapping different versions of static library in dynamic libraries
In my project there is a dependency on a static library (just called libsomething from now on) from a 3rd party. Recently, libsomething has become available in another version. My task is to provide my software with support for the old and the new version. Only one version of libsomething is used at run-time at any giv...
It has been few years now but I'd like to mention another solution for completeness. Instead of manual dlopen and dlsym you could generate simple stubs for all necessary functions and on first call (or at program startup) decide which library version is needed, load it and resolve the addresses. You could write a scrip...
2,801,691
2,801,695
a nicer way to create structs in a loop
I haven't coded in C++ in ages. And recently, I'm trying to work on something involving structs. Like this typedef struct{ int x; int y; } Point; Then in a loop, I'm trying to create new structs and put pointers to them them in a list. Point* p; int i, j; while (condition){ // compute values for i and j w...
Sure: Point * p = new Point; You should probably also give your Point class a constructor: struct Point { // note no need for typedef int x; int y; Point( int ax, int ay ) : x( ax ), y( ay ) {} }; so that you can say: Point * p = new Point( i, j ); You may also want to make your list a list of Poi...
2,801,739
2,801,749
calling a function from static function
how can i call a function which computes with input parameters from an another static function. say, class X { static void xyz(); static int pqr(int, int); }; void X::xyz() { ...pqr(10,20); } int X::pqr(int t1, int t2) { return t1*t2; }
You have to call instance methods off an instance of the class. Otherwise, just call it off the class. X::pqr(10, 20)
2,801,859
2,801,872
How would I convert decimal into binary?
All I really know is PHP and I used the decbin function etc, It was fairly easy to do. In this C++ program I want to do the same thing, just a simple number or string how would I do this?
A simple function could be defined such as this: void binary(int decimal) { int remainder; if(decimal <= 1) { std::cout << decimal; return; } remainder = decimal % 2; binary(decimal >> 1); std::cout << remainder; } Although there are many other resources on the web on how to do thi...
2,801,938
2,802,525
GCC ABI compatibility
As far as I've understood, it is not possible to link libraries that use different versions of GCC's Application Binary Interface (ABI). Are there ABI changes to every version of GCC? Is it possible to link a library built with 4.3.1 if I use, say, GCC 4.3.2? Is there a matrix of some sort that lists all the ways I can...
The official ABI page points to an ABIcheck. This tool may do, what you want.
2,801,959
2,802,379
Making only one column of a QTreeWidgetItem editable
I have a QTreeWidgetItem with two columns of data, is there any way to make only the second column editable? When I do the following: QTreeWidgetItem* item = new QTreeWidgetItem(); item->setFlags(item->flags() | Qt::ItemIsEditable); all columns become editable.
Looks like you will have to forgo using QTreeWidget and QTreeWidgetItem and go with QTreeView and QAbstractItemModel. The "Widget" classes are convenience classes that are concrete implementations of the more abstract but more flexible versions. QAbstractItemModel has a call flags(QModelIndex index) where you would ret...
2,802,147
2,802,177
C++ Programming in Linux Platform
I am a software engineer and i work in VC++, C++ in WIndows OS. Are there any major differences when it comes to coding in C++ in Linux environment. Or is it just some adjustments that we have to make when we need to code in C++ in Linux.
It would depend on the types of projects you've worked on and what native windows APIs you made use of. For example if you used the native Windows API for everything, you're going to have a pretty big task ahead of you, it'd be worth making your project(s) work nicely with Wine instead. In the Linux environment you hav...
2,802,188
2,802,196
File count in a directory using C++
How do I get the total number of files in a directory by using C++ standard library?
You can't. The closest you are going to be able to get is to use something like Boost.Filesystem EDIT: It is possible with C++17 using the STL's filesystem library
2,802,197
2,803,533
C++ hash table implementation with collision handling
What is a good C++ library for hash tables / hash maps similar to what java offers. I have worked with Google Sparsehash, but it has no support for collisions.
In addition to those mentioned in other answers, you could try MCT's closed_hash_map or linked_hash_map. It is internally similar to Google SparseHash, but doesn't restrict values used and has some other functional advantages. I'm not sure I understand what you mean by "no support for collisions", though. Both Google...
2,802,302
2,802,327
Simple OOP-related question
This question came to my mind quite a few times. Let my explain my question through an example. Say I've got two classes: 1- Grid. 2- Cell. Now the location of the cell 'should' be stored in the grid class, not in the cell class itself. Say that the cell wanted to get its location through a method in the grid. How can ...
I don't think that's a good design. If the cell needs to know its location, it should hold it itself and provide methods for the grid to access it.
2,802,393
2,802,565
Why does gdb show two different returns?
Last week I was a debugging a code and a weird situation came up: gdb passes through two different return clauses. I made a simple example that illustrates the situation: #include <iostream> using namespace std; int test() { string a = "asd"; string b = "asd"; while (true) { if (a == b) { ...
I suspect you're seeing the function epilogue. Your two strings have destructors, which are being implicitly called on return. Check out what the disassembly says to be sure, but I suspect that both return statements are mapping to something along the lines of: stash return_value; goto epilogue; and correspondingly: e...
2,802,418
2,802,438
'+=' : pointer on left; needs integral value on right
I am confused. I can not use this on a float? Must it be a integer? I try to define that as a point but I guess I can not convert float to float * //global definition float g_posX = 0.0f; &g_posX -= 3.03f;
You probably simply want to do this: float g_posX = 0.0f; g_posX -= 3.03f; What your code tries to do is take the address of g_posX and subtract 3.03f from the address. That does not work, for two reasons: The address is not an lvalue: it cannot be assigned to. Assigning to an address would be meaningless. What would...
2,802,584
2,802,611
passing a float as a pointer to a matrix
Honestly, I couldnt think of a better title for this issue because I am having 2 problems and I don't know the cause. The first problem I have is this //global declaration float g_posX = 0.0f; ............. //if keydown happens g_posX += 0.03f; &m_mtxView._41 = g_posX; I get this error cannot convert from 'float'...
1.) m_mtxView._41 = g_posX; 2.) Update: this piece of code is quite unnecessary, although it shows how to use a pointer allocated on the heap. float* g_posX = new float; // declare a pointer to the address of a new float *g_posX = 0.0f; // set the value of what it points to, to 0.0This m_mtxView._41 = *g_posX; // set...
2,802,953
2,802,984
How do shared pointers work?
How do shared pointers know how many pointers point to that object? (shared_ptr, in this case)
Basically, shared_ptr has two pointers: a pointer to the shared object and a pointer to a struct containing two reference counts: one for "strong references," or references that have ownership, and one for "weak references," or references that don't have ownership. When you copy a shared_ptr, the copy constructor inc...
2,802,960
2,803,621
What is a QT Plugin?
What is a QT Plugin? What are differences between a qt plugin and a custom made qt library? Thanks.
AFAIK Qt plugins are implemented as shared libraries (.so on Unix/Linux and DLLs on Windows). The differences between them are the same as with plugins and libraries in general. What this means is that, a plug-in architecture is independent of the linking method. They tend to be thought of as plug-in/dynamic linking an...
2,803,071
2,803,150
C++ sort array of strings
I am trying to sort an array of strings, but it's not sorting anything.... what am I doing wrong? string namesS[MAX_NAMES]; int compare (const void * a, const void * b){ return ( *(char*)a - *(char*)b ); } void sortNames(){ qsort(namesS, MAX_NAMES, sizeof(string), compare); }
This is C++, not C. Sorting an array of strings is easy. #include <string> #include <vector> #include <algorithm> std::vector<std::string> stringarray; std::sort(stringarray.begin(), stringarray.end());
2,803,258
2,803,303
How to initialise a struct-type in the initialisation list?
How can I initilise a structure in the constructor list? Say: struct St{int x, y}; class Foo { public: Foo(int a = 0, int b = 0) : /*here initilise st_foo out of a and b*/ {} private: const St st_foo; };
You need to provide a constructor for struct St that takes 2 int parameters and assigns them to x and y. Then invoke it in your Foo initialization list. Remember: structs are the same thing as classes except default visibility rules (for structs, default is public.
2,803,304
2,803,445
advance mathematics c++ libraries
what popular advance mathematics libraries for c++ are present out there, so that they can be used as a 1 stop solution and avoiding reinventing the wheel ?
Check out GNU Scientific Library -- it's in C, but I use it all the time to avoid re-writing the Numerical Recipes code.
2,803,403
2,803,512
C++ stream as a parameter when overloading operator<<
I'm trying to write my own logging class and use it as a stream: logger L; L << "whatever" << std::endl; This is the code I started with: #include <iostream> using namespace std; class logger{ public: template <typename T> friend logger& operator <<(logger& log, const T& value); }; template <typename T> lo...
endl is a strange beast. It isn't a constant value. It's actually, of all things, a function. You need a special override to handle the application of endl: logger& operator<< (logger& log, ostream& (*pf) (ostream&)) { cout << pf; return log; } This accepts insertion of a function that takes an ostream reference a...
2,803,502
2,803,610
C++ Detecting ENTER key pressed by user
I have a loop where I ask the user to enter a name. I need to stop when the user presses the ENTER key..... or when 20 names have been entered. However my method doesn't stop when the user presses the ENTER key //loop until ENTER key is entered or 20 elements have been added bool stop = false; int ind = 0; while( !stop...
You convert the read string to an integer with atoi: int enterKey = atoi(temp.c_str()); If temp is a string like "1234" this will set enterKey to 1234. Then you compare enterKey to the ASCII value of \n. This is most probably not doing anything useful. Also std::getline just read the characters up to, but not ...
2,803,910
2,804,018
C++ Beginner - Trouble using classes inside of classes
I am working on a college project, where I have to implement a simple Scrabble game. I have a player class (containing a Score and the player's hand, in the form of a std::string, and a score class (containing a name and numeric (int) score). One of Player's member-functions is Score getScore(), which returns a Score o...
You've got a circular inclusion problem - relatively easy to fix in this case. Remove the #include "Player.h" from Score.h. See this question for an explanation and discussion of what you'd need to do if Score actually used Player. As for the compiler errors you're getting, that's how Microsoft's compiler reports the...
2,804,089
2,805,729
printf("... %c ...",'\0') and family - what will happen?
How will various functions that take printf format string behave upon encountering the %c format given value of \0/NULL? How should they behave? Is it safe? Is it defined? Is it compiler-specific? e.g. sprintf() - will it crop the result string at the NULL? What length will it return? Will printf() output the whole fo...
What happens when you output a NUL depends on the output device. It is a non printing character, i.e. isprint('\0') == 0; so when output to a display device, it has no visible affect. If redirected to a file however (or if calling fprintf()), it will insert a NUL (zero byte) into the file; the meaning of that will d...
2,804,115
2,805,489
How to connect focus event from QLineEdit?
I have to connect focus event from some QLineEdit element (ui->lineEdit) to the method focus(). How can I do this?
There is no signal emitted when a QLineEdit gets the focus. So the notion of connecting a method to the focus event is not directly appropriate. If you want to have a focused signal, you will have to derive the QLineEdit class. Here is a sample of how this can be achieved. In the myLineEdit.h file you have: class MyLin...
2,804,194
2,804,233
How do I retrieve program output in Python?
I'm not a Perl user, but from this question deduced that it's exceedingly easy to retrieve the standard output of a program executed through a Perl script using something akin to: $version = `java -version`; How would I go about getting the same end result in Python? Does the above line retrieve standard error (eq...
For python 2.5: sadly, no. You need to use subprocess: import subprocess proc = subprocess.Popen(['java', '-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() Docs are at http://docs.python.org/library/subprocess.html
2,804,261
2,804,312
How do I create a C++ console/terminal project in XCode?
I am using MacBook Pro Mac OS 10.5 with related version of XCode. I am new to this development environment. I want to develop C++ code for a console/terminal-based application using XCode on Mac OS 10.5, but I did not figure out how to create such type of project using XCode. Could anyone briefly describe the steps or ...
File->New project Then from the list on the left "Command line utility", and on the right "C++ tool".
2,804,320
2,804,457
Linked list issue with insert
The problem appears with the insert function that I wrote. 3 conditions must work, I tested b/w 1 and 2, b/w 2 and 3 and as last element, they worked. EDIT; It was my own problem. I did not realize I put MAXINPUT = 3 (instead of 4). I do appreciate all the efforts to help me becoming a better programmer, using more ...
Your code works fine on my machine (once the insert(()) statement is "filled in" properly as explained in the code comment). The insertion works in all positions. Something else, though: I initially had a look at your insert function. I thought I'd give you a hint on how to make it a little shorter and easier to under...
2,804,426
2,804,621
How do I increase the stack size for executables built with scons on Solaris?
I am working with scons and am trying to compile a program that require bigger stack size but I dont know how to extend the stack size. This is on a solaris machine, and we use scons to compile our projects. Anyone know how to do this ?
In the shell (ksh example) prior to executing your program you can use ulimit -s <size in kbytes>. You may need elevated privileges to change it. You can also use setrlimit programmatically but from the man page it won't adjust the currently running process so it's probably not helpful for your needs. Also consider wha...
2,804,473
2,804,564
Having issues with initializing character array
Ok, this is for homework about hashtables, but this is the simple stuff I thought I was able to do from earlier classes, and I'm tearing my hair out. The professor is not being responsive enough, so I thought I'd try here. We have a hashtable of stock objects.The stock objects are created like so: stock("IBM", "Interna...
As this is tagged C++ can you use std::string instead of doing all the pointer maintenance yourself on char*? std::string name; std::string symbol Then setSymbol becomes easy: void stock::setSymbol(const char* symbol) { this->symbol = symbol; }
2,804,556
2,804,672
How to detect the language of MS Excel
I'm trying to figure out a way of detecting the language of an installed version of Excel (ideally from C++). I need this to resolve an issue with computers on which the language of Excel differs from the Windows language (see this problem).
Using automation, the applications LanguageSettings object gives you that: Application.LanguageSettings.LanguageID(msoLanguageIDUI)
2,804,641
2,851,477
Pretty printing boost::unordered_map on gdb
recently I've started to use the excellent boost::unordered_map on my system, but got one drawback: I couldn't figure how to inspect its contents. Printing it on gdb gives me a table_ and a buckets_, but haven't found where are the items. Anyone has a clue about this?
For the ones that wanted a printer, I've managed to create one. Here is Code: class BoostUnorderedMapPrinter: "prints a boost::unordered_map" class _iterator: def __init__ (self, fields): type_1 = fields.val.type.template_argument(0) type_2 = fields.val.type.template_argument(1)...
2,804,743
2,804,860
How i can display image in symbian c++
Hi i'm new in symbian c++ and sdk 5th, I use carbide c++ how i can display some image? (.bmp extension for example)
Perhaps have a look into the DrawBitmap and BitBit functions.
2,804,880
2,804,895
In C++, what is the scope resolution ("order of precedence") for shadowed variable names?
In C++, what is the scope resolution ("order of precedence") for shadowed variable names? I can't seem to find a concise answer online. For example: #include <iostream> int shadowed = 1; struct Foo { Foo() : shadowed(2) {} void bar(int shadowed = 3) { std::cout << shadowed << std::endl; ...
Your first example outputs 3. Your second outputs 4. The general rule of thumb is that lookup proceeds from the "most local" to the "least local" variable. Therefore, precedence here is block -> local -> class -> global. You can also access each most versions of the shadowed variable explicitly: // See http://ideone.co...
2,804,893
2,805,812
C++ DLL Export: Decorated/Mangled names
Created basic C++ DLL and exported names using Module Definition file (MyDLL.def). After compilation I check the exported function names using dumpbin.exe I expect to see: SomeFunction but I see this instead: SomeFunction = SomeFunction@@@23mangledstuff#@@@@ Why? The exported function appears undecorated (especially ...
You can get what you want by turning off debug info generation. Project + Properties, Linker, Debugging, Generate Debug Info = No. Naturally, you only want to do this for the Release build. Where the option is already set that way.
2,805,029
2,805,066
Overview look of header inclusions
When a project grows it becomes hard to get an overview of header inclusion. I've noticed our object files have grown rather large and so I'm thinking there's a lot to be won by rearranging dependencies. This is where the problem begin, I know of no convenient way to actually get an overview on what headers actually ge...
Visual C++ has the /showIncludes switch, which causes the compiler to output a message when an include is encountered.
2,805,215
2,805,243
What header file is where the boost library define its own primitive data type?
Recently, I try to use the boost::spirit::qi binary endian parser to parse some binary data depends on the endianness of the Platform. There is a simple example, like following: Using declarations and variables: using boost::spirit::qi::little_word; using boost::spirit::qi::little_dword; using boost::spirit::qi::litt...
Types like uint16_t or uint32_t exist so that you can declare a variable to have a specific bit width. You can't do this with normal types like "long" because they are different sizes on different architectures and/or implementations. The afore mentioned types are normally derived by through preprocessor calculations...
2,805,270
2,805,452
"Invalid Handle Object" when plotting 2 figures Matlab
I'm having a difficult time understanding the paradigm of Matlab classes vs compared to c++. I wrote code the other day, and I thought it should work. It did not... until I added <handle after the classdef. So I have two classes, landmarks and robot, both are called from within the simulation class. This is the m...
When you call plot multiple times on the same figure, the previous plot is by default erased, and the handle to the previous plot points to nothing. Thus the error. To fix this, you need to set the NextPlot property of the axes to add. You can do this by calling hold on (that's what you'd do if you were plotting from c...
2,805,457
2,805,479
C++ : Swapping template class elements of different types?
template< class T1, class T2 > class Pair { T1 first; T2 second; }; I'm being asked to write a swap() method so that the first element becomes the second and the second the first. I have: Pair<T2,T1> swap() { return Pair<T2,T1>(second, first); } But this returns a new object rather than swapping, where I ...
You cannot swap in-place, since T1 and T2 need not be of the same type. Pair<T1,T2> is a different type than Pair<T2,T1>. You have to return an object of a different type than the original one, so that has to be a new object. What I'd do is this: template< class T1, class T2 > Pair<T2,T1> swap(const Pair<T1,T2>& pair...
2,805,542
2,805,685
Installing a cpp library on linux
I'm trying to install a library (libspopc), but, when I run the make command, I get the errors: strip libspopc.a libspopc.so strip: 'libspopc.a': No such file strip: 'libspopc.so': No such file make: *** [install] Error Working under the assumption that every version of the library I've tried isn't actually missing t...
While this question is only remotely related to programming (seems more like something for superuser.com), on linux you should whenever you can use the package manager of your system. In most cases, it let's you fetch the files as binaries (thus avoiding possible compilation frustrations), keeps your system clean and i...
2,805,698
2,805,806
Do While loop breaks after incorrect input?
I am trying to have a loop continue to prompt the user for an option. When I get a string of characters instead of an int, the program loops indefinitely. I have tried setting the variable result to NULL, clearing the input stream, and have enclosed in try{}catch blocks (not in this example). Can anyone explain to me w...
It looks like there is a random element here, since result is not initialized. In any case, test cin directly if ( cin && result < options.size() ) and reset it upon invalid input so it will again perform I/O operations result = 0; // inappropriate to initialize an integer with NULL cin.clear(); //...
2,805,744
2,805,823
CreateTimerQueue for linux
Anyone know if there is any function similar to CreateTimerQueue on linux? Or do I have to make my own.
You want to use timer_gettime and timer_settime. Lookup the page on timer_create to get a nice example
2,805,802
2,805,839
boost.threads Singleton initialization
Is there preferred way to initialize (lazily) singleton data when using multiple threads from boost.threads? Thanks.
Check out the call_once free function in Boost.Thread.
2,805,841
2,805,891
Implementing PyMyType_Check methods with Python C API?
All the Python-provided types have a check method (i.e., PyList_Check) that allows you to check if an arbitrary PyObject* is actually a specific type. How can I implement this for my own types? I haven't found anything good online for this, though it seems like a pretty normal thing to want to do. Also, maybe I'm just...
That's because they're macros that use deep magic. Save yourself a bit of headache and use PyObject_IsInstance() instead.
2,805,896
2,806,384
What alignment does HeapAlloc use
I'm developing a general purpose library which uses Win32's HeapAlloc MSDN doesn't mention alignment guarantees for Win32's HeapAlloc, but I really need to know what alignment it uses, so I can avoid excessive padding. On my machine (vista, x86), all allocations are aligned at 8 bytes. Is this true for other platforms...
The HeapAlloc function does not specify the alignment guarantees in the MSDN page, but I'm inclined to think that it should have the same guarantees of GlobalAlloc, which is guaranteed to return memory 8-byte aligned (although relying on undocumented features is evil); after all, it's explicitly said that Global/LocalA...
2,806,046
2,862,380
Linking LLVM JIT Code to Static LLVM Libraries?
I'm in the process of implementing a cross-platform (Mac OS X, Windows, and Linux) application which will do lots of CPU intensive analysis of financial data. The bulk of the analysis engine will be written in C++ for speed reasons, with a user-accessible scripting engine interfacing with the C++ testing engine. I want...
Yes we can! Depending on the version of LLVM you use there are different API calls. you will need llvm::getBitcodeModuleProvider on 2.5. The easiest way to call C++ functions is to create a function (llvm::Function::Create) using the flag llvm::Function::ExternalLinkage and then addGlobalMapping to make it point to y...
2,806,104
2,806,146
Does fwrite buffer the output?
In C++, there is an std::fwrite() which writes a buffer to a file on disk. Can you please tell me if there is any buffer inside that fwrite implementation? i.e. if I call fwrite() multiple times (say 10 times), does it actually invoke file I/O 10 different times? I am asking this for Ubuntu 10.04 environment.
Yes, it is buffered. The size of the buffer is defined by BUFSIZ. (Thanks @ladenedge.) Ten sufficiently large operations will result in ten system calls. You are also allowed to set your own buffer using std::setbuf and std::setvbuf. The functions in cstdio are inherited from C. The preferred interface in C++ is fstrea...
2,806,160
2,806,205
How do I determine which C/C++ compiler to use?
I am trying to figure out which C/C++ compiler to use. I found this list of C/C++ compilers at Wikipedia: http://en.wikipedia.org/wiki/List_of_compilers#C.2FC.2B.2B_compilers I am fairly certain that I want to go with an open source compiler. I feel that if it is open source then it will be a more complete compiler sin...
First of all, IMHO as a beginner your development environment (IDE) matters a lot more than the compiler. I think that people place too much emphasis on compiler choice early on. While it is not Java, C++ is meant to be portable. If the program you're writing only works with specific compilers, you're probably doing t...
2,806,370
2,806,411
C++ std::vector insert segfault
I am writing a test program to understand vector's better. In one of the scenarios, I am trying to insert a value into the vector at a specified position. The code compiles clean. However, on execution, it is throwing a Segmentation Fault from the v8.insert(..) line (see code below). I am confused. Can somebody point m...
You're passing v8 by value to your find function. The iterator returned thus points into the copy of the vector, which is out of scope after the find call returns. Try passing by (const) reference, or better yet, just use std::find.
2,806,769
2,806,809
Esoteric C++ operators
What is the purpose of the following esoteric C++ operators? Pointer to member ::* Bind pointer to member by pointer ->* Bind pointer to member by reference .* (reference)
A pointer to a member allows you to have a pointer that is relative to a specific class. So, let's say you have a contact class with multiple phone numbers. class contact { phonenumber office; phonenumber home; phonenumber cell; }; The idea is if you have an algorithm that needs to use a phone number but t...
2,806,801
2,806,838
Do bit operations cause programs to run slower?
I'm dealing with a problem which needs to work with a lot of data. Currently its values are represented as an unsigned int. I know that real values do not exceed a limit of 1000. Questions I can use unsigned short to store it. An upside to this is that it'll use less storage space to store the value. Will performance ...
This all depends on architecture. Bit-fields are generally slower, but if you are able to to significantly cut down memory usage with them, you can even gain in performance due to better CPU caching and similar things. Likewise with short (though it is not dramatic in any case). The best way is to make your source co...
2,806,922
2,807,047
MySQL, C++: Retrieving auto-increment ID
I have a table with an auto-incrementing ID. After inserting a new row, I would like to retrieve the new ID. I found an article that used the MySQL function LAST_INSERT_ID(). The article says to create a new query and submit it. I'm using MySQL Connector C++, Windows XP and Vista, and Visual Studio 9. Here are my ...
It doesn't look like it - in the C API, you have mysql_insert_id() for this, but it doesn't appear to be used in the C++ connector, nor does it appear to implement the getGeneratedKeys method from the JDBC API (However, I don't use this connector myself, so I may be missing something obvious...). No, there is no resul...
2,806,939
2,807,506
visual c++ 2010 link against older runtime?
Sorry if this has been asked. Just like I can select in C# project that I want it to build for .NET 2.0 runtime, is it possible for native c++ project to be built against older CRT, let's say one from visual studio 2005? I would like this because I have external SDK that was build with VS2005, but I'd like to use newer...
You can build against 2005 and 2008 (think also 2003) as long as they are installed along side vis 2010. You will need to change The platform Tool set for each project to reflect the one you want to build against (properties -> general -> platform toolset) with v100 being 2010, v90 2008, v80 2005 and so on
2,806,957
2,813,379
insufficient buffer when call DocumentProperties, also, global unlock wouldn't unlock
please see comments inline bool res = false; DWORD dwNeeded = DocumentPropertiesW(NULL, m_currPrinterHandle, (LPWSTR) m_currPrinterName.c_str(), NULL, NULL, 0); if (m_devmode_buf) { GlobalFree(m_devmode_buf); } m_devmode_buf = GlobalAlloc(GPTR, dwNeeded); GetLastError(); // = 0; if (m_devmode_buf) { LPDE...
If the second call to DocumentProperties() is returning 1 (i.e. IDOK) then it is not failing, thus the value of GetLastError() is meaningless. It is probably an expected condition that is raised and handled inside of DocumentProperties(). The convention of using GetLastError() is that you only set it on failure; you ...
2,807,013
2,807,086
buffer size for socket connection in c++
I'm trying to build a basic POP3 mail client in C/++, but I've run into a bit of an issue. Since you have to define the buffer size when building the program, but a message can be arbitrarily large, how do you, say, get the mail server to send it to you in parts? And if this isn't the correct means of solving the probl...
Since most email is done using TCP/IP, you can read one byte at a time if you really want to. The underlying implementation will buffer the stream for you. It is received approximately 1,400 bytes at a time off of the network. Generally, I using either std::vector<char> or std::string as a buffer and read one byte a...
2,807,048
2,807,063
C++ vector of strings, pointers to functions, and the resulting frustration
So I am a first year computer science student, for on of my final projects, I need to write a program that takes a vector of strings, and applies various functions to these. Unfortunately, I am really confused on how to use pointer to pass the vector from function to function. Below is some sample code to give an ide...
std::vector<T>::pointer is not std::vector<T>*, it is T*. Don't worry about using pointers; just use references, e.g., void function_1(std::vector<string>& vec) { /* ... */ } function_2, which does not modify the vector, should take a const reference: void function_2(const std::vector<string>& vec) { /* ... */ }
2,807,055
2,986,029
Reading from serial port with Boost Asio
I'm want to check for incoming data packages on the serial port, using boost.asio. Each data packet will start with a header that is one byte long, and will specify what type of the message has been sent. Each different type of message has its own length. The function I want to write should listen for new incoming mess...
This article is helpful in understanding how ASIO can be used asynchronously with serial ports: https://gist.github.com/kaliatech/427d57cb1a8e9a8815894413be337cf9 UPDATE (2019-03): The original article I had linked to is no longer available and is difficult to find even in Internet Archive. (Here is a snapshot.). The...
2,807,095
2,807,111
C++: calling member functions within constructor?
The following code raises a runtime error: #include <iostream> #include <iterator> #include <ext/slist> class IntList : public __gnu_cxx::slist<int> { public: IntList() { tail_ = begin(); } // seems that there is a problem here void append(const int node) { tail_ = insert_after(tail_, node); } private: i...
Looks like You are inserting after end(); In the body of the constructor IntList() { tail_ = begin(); } the base class is constructed and it's members can be called, but for an empty list, it should return end();
2,807,138
2,807,166
can I access a struct inside of a struct without using the dot operator?
I have 2 structures that have 90% of their fields the same. I want to group those fields in a structure but I do not want to use the dot operator to access them. The reason is I already coded with the first structure and have just created the second one. before: typedef struct{ int a; int b; int c; object1 ...
Yes. Rather using a C-style of inheritance, using C++ style: struct str3{ int a; int b; int c; }; struct str2 : public str3{ object2 name; };
2,807,293
2,807,302
Resolving ambiguous this pointer in C++
I'm trying to derive a new class from an old one. The base class declaration looks like this: class Driver : public Plugin, public CmdObject { protected: Driver(); public: static Driver* GetInstance(); virtual Engine& GetEngine(); public: // Plugin methods... virtual bool InitPlugin (Mgr* pMgr); ...
If you derive from Driver, you don't have to call the constructors of Drivers bases explicitly: class NewDriver : public Driver { /* ... */ }; NewDriver::NewDriver() : Driver() {} The constructor of Driver then initializes its own bases, you don't have to and shouldn't do that directly. If it should behave differently...
2,807,492
2,807,501
Can I prevent future developers from making an object constructable?
you have a class A, where you set ctor to be private, so a client can't call "A a;" to create obj on stack. But someday another developer add a new ctor: "A(int)" and try to call "A a(1);" inside main(). So this will create a obj on stack. How do you prevent that?
Nothing you can do to C++ source code can constrain the future behavior of other people with permission to modify the C++ source code. That other developer could delete the string 'private:' just as easily as they could add a public constructor with another signature. All you can do is carefully comment the reasons why...
2,807,786
2,807,788
where is std::cout windows in MacBook Pro?
I am using MacBook Pro Mac OS 10.5 with related version of XCode. I am new to this development environment. I am developing C++ console/terminal applications (File->New project, then from the list on the left "Command line utility", and on the right "C++ tool".). When statement like std::cout executes, I think the outp...
Choose Run => Console or press shift-command-R.
2,808,030
2,808,041
subscript operator on pointers
If I have a pointer to an object that has an overloaded subscript operator ([]) why can't I do this: MyClass *a = new MyClass(); a[1]; but have to do this instead: MyClass *a = new MyClass(); (*a)[1];
It's because you can't overload operators for a pointer type; you can only overload an operator where at least one of the parameters (operands) is of class type or enumeration type. Thus, if you have a pointer to an object of some class type that overloads the subscript operator, you have to dereference that pointer in...
2,808,216
2,808,241
passing a class method as opposed to a function in std::sort
Within a class, I am trying to sort a vector, by passing a method of the same class. But it gives errors at the time of compilation. Can anyone tell what the problem is? Thank you! it gives the following error: argument of type bool (Sorter::)(D&, D&)' does not matchbool (Sorter::*)(D&, D&)' I have also tried usin...
Make Sorter::sortByNumber static. Since it doesn't reference any object members, you won't need to change anything else. class Sorter { public: static bool sortByNumber(const D& d1, const D& d2); ... }; // Note out-of-class definition does not repeat static bool Sorter::sortByNumber(const D...
2,808,324
2,808,340
What trick does Java use to avoid spaces in >>?
In the Java Generic Book, while contrasting the difference between C++ Templates and Java Generic says: In C++, a problem arises because >> without the space denotes the right-shift operator. Java fixes the problem by a trick in the grammar.) What is this trick?
This is actually being fixed in C++ in the next version. There really isn't much of a trick; if you encounter >> while in the process of parsing a generic or template where instead you expected >, then you already have enough information to generate an error message. And, if you have enough information to generate an ...
2,808,437
2,808,638
how to implement a sparse_vector class
I am implementing a templated sparse_vector class. It's like a vector, but it only stores elements that are different from their default constructed value. So, sparse_vector would store the lazily-sorted index-value pairs for all indices whose value is not T(). I am basing my implementation on existing sparse vectors ...
Effectively, it seems that they reinvented the wheel (so to speak). I would personally consider 2 libraries for your need: Loki, for Loki::AssocVector -> the interface of a map implemented over a vector (which is what you wish to do) Boost.Iterator, for its iterator_adaptor class. Makes it very easy to implement a new...
2,808,617
2,808,734
Difference between Locks, Mutex and Critical Sections
There is an existing question regarding difference between Mutex and Critical section but it does not deal with Locks also. So i want to know whether Critical sections can be used for thread synchronisation between processes. Also what is meant by signalled states and non-signalled states
In Windows critical sections are (mostly) implemented in user mode, and a mutex will switch context to kernel mode (which is slow). If a thread terminates while owning a mutex, the mutex is said to be abandoned. The state of the mutex is set to signaled, and the next waiting thread gets ownership. In the same situation...
2,808,960
2,809,619
C++ imitating ls like commands
How to implement the ls "filename_[0-5][3-4]?" like class? The result I would like to store in the vector. Currently I am using system() which is calling ls, but this is not portable under MS. thanks, Arman.
The following program lists files in the current directory whose name matches the regular expression filename_[0-5][34]: #include <boost/filesystem.hpp> #include <boost/regex.hpp> // also functional,iostream,iterator,string namespace bfs = boost::filesystem; struct match : public std::unary_function<bfs::directory_en...
2,809,014
2,809,038
Why does this C++ code-snippet segmentation fault?
#include <iostream> using namespace std; int recur(int x) { 1 and recur(--x); cout << x; return x; } int main() { recur(10); return 0; }
1 and recur(--x); is equivalent to recur(--x); Clearly you are making infinite recursive calls which leads to stack overflow followed by segmentation fault. I guess you meant x and recur(--x); which makes the recursive call only when x is non-zero.
2,809,127
2,812,847
How do I connect from an XPCOM object to a GStreamer plugin in a Songbird addon?
I am writing a Songbird addon, with three parts: XUL (javascript), a GStreamer filter and an XPCOM addon. I am interested in accessing the GStreamer layer from my XPCOM component. If anyone knows any resources on how to do that I'd be grateful. Specifically, I need documentation or examples on accessing the GStreamer f...
A few months ago I created a XULRunner application for recording live camera and audio streams. It was based on GStreamer via an XPCOM component. I got my inspiration from the GStreamer code. However, you want to access the GStreamer functionality from Songbird. I'm not familiar with that route. If I were you I would s...
2,809,167
2,809,203
c++ static int in a class - compile time error
I want to have a simple class i can call to get a unique number whilst the program is running - i can do the below with a dynamic allocation, and then just delete when not needed, but i still wanted to get a static version too. Strangely, the code below (which is seemingly straightforward) throws some strange comiple e...
Add the initialization/definition of the static member as: int Id_gen::curr_id = 0; after the class definition. EDIT: As mentioned in the comment by @sbi : Initialization is optional, the linker requires the definition only.
2,809,309
2,812,260
Can I use the [] operator in C++ to create virtual arrays
I have a large code base, originally C ported to C++ many years ago, that is operating on a number of large arrays of spatial data. These arrays contain structs representing point and triangle entities that represent surface models. I need to refactor the code such that the specific way these entities are stored inte...
After reading the above answers, I decided that Pete's answer with two versions of operator[] was the best way forward. To handle the morphing between types at run-time I created a new array template class that took four parameters as follows; template<class TYPE, class ARG_TYPE,class BASE_TYPE, class BASE_ARG_TYPE> c...
2,809,329
2,809,364
Smart pointer class predeclaration
I have a header file: class A { public: DeviceProxyPtr GetDeviceProxy(); }; DeviceProxyPtr is defined in a different header file like this: typedef SmartPtrC<DeviceProxyC> DeviceProxyPtr; I don't want to include DeviceProxyPtr definition header. If a return type was DeviceProxy* I could simply use predeclaratio...
The fact that it's a concrete return type makes no difference. You can forward-declare return types. However, in this case, it's not a class, but a typedef. You couldn't use class DeviceProxy, even if it was a pointer. Mind you, all hope is not lost. The point of forward declarations is to avoid dragging in too much co...
2,809,330
2,809,405
XCode C++ source code print issue on Mac
I am using MacBook Pro Mac OS 10.5 with related version of XCode. I am new to this development environment. I am developing C++ console/terminal applications (File->New project, then from the list on the left "Command line utility", and on the right "C++ tool".). For C++ source code file, I want to print source file co...
I found this article A Recipe to Pretty-Print Your iPhone Source in Xcode it uses enscript which is installed by Apple for Xcode on Snow Leopard so no need for macports etc. You can get linenumbers by passing -C as an argument to the enscript executable called in the shell script
2,809,559
2,809,602
Using a SOCKS proxy from C++
How I can use a SOCKS proxy from my C++ socket program?
Your question is a bit vague, but I'll try to answer it anyway. If found these links that might help you: A C++ socket library - Includes an sample of a Web Proxy Another C++ socket library - Includes also an example of Proxy Using the SOCKS RFC and the cited links, you might be able to create a SOCKS proxy. I don't ...
2,809,637
2,809,701
Auto tester/debugger for g++?
I just finished a project for my cryptography class and it all seems to go well (mostly). Because the key is generated randomly, I wanted to ensure it would work for all keys. Anyway, I ran it a bunch of times and hit a segfault at around the 30th run. I haven't been able to reproduce this segfault in gdb. Does gdb hav...
Place the loop inside your program so you only have to run it in the debugger once.
2,809,968
2,810,040
how to call a function to refresh GUI
I am refactoring some code to decouple GUI from some state. #include <StateObject> Class GUI{ ... StateObject A; void doSomething() { A->hullaballoo();} **void ReFreshMyGui() { //take state A and redraw }** }; State object is being shared by multiple classes to update the state but this Gui Object s...
In order to decouple GUI and Data you could use the MVC pattern. This means your GUI should register to your model's (data) object(s) and whenever the data changes the GUI will be notified and it will be the GUI to redraw itself. But careful, the model should not have the notion of a concrete GUI, instead the GUI shou...
2,810,118
2,813,596
How to tell the MinGW linker not to export all symbols?
I'm building a Windows dynamic library using the MinGW toolchain. To build this library I'm statically linking to other 2 which offer an API and I have a .def file where I wrote the only symbol I want to be exported in my library. The problem is that GCC is exporting all of the symbols including the ones from the libra...
You can use dllwrap if your distribution of binutils (either native or cross compiling) provides it. It can produce DLLs using the interface in a DEF file (under the hood it calls gcc, ld and dlltool to do so). The difference between using this and passing a DEF file to GCC directly is that the definitions in the file ...
2,810,151
2,810,509
#include - brackets vs quotes in XCode?
In MSVC++ #include files are searched for differently depending on whether the file is enclosed in "" or <>. The quoted form searches first in the local folder, then in /I specified locations, The angle bracket form avoids the local folder. This means, in MSVC++, its possible to have header files with the same name as ...
You should be able to do the same with gcc (I don't know how much xcode wraps things and prevent access to some features). There is a bunch of options controlling the search path (see http://gcc.gnu.org/onlinedocs/gcc-4.5.0/cpp/Search-Path.html and http://gcc.gnu.org/onlinedocs/gcc-4.5.0/cpp/Invocation.html and look f...
2,810,212
2,811,322
Custom PreviewPane - Works in Windows7, not in Vista
I've written an explorer extension to display my custom file format in the Preview Pane. This works fine in Windows 7, but doesn't seem to work in Vista. The same DLL handles both thumbnails and the preview pane. The thumbnails side of things work in both Vista and Windows7. Adding logs to my code, Vistas only calli...
The reg looks okayish, only the default progid is missing. Win7 does have documented alternate behavior for the location of the PreviewHandlers key. Unfortunately the SDK docs don't say what Vista requires. A Vista time magazine article uses HKLM instead of HKCU. I bet that's it.