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
4,606,716
4,606,799
How should i build my GUI in Qt?
I am wondering which way is the best to start building a GUI+SOFT in Qt. I am trying to build a sound media player based on a MVC pattern. Until now i have found 3 ways to do so. 1- Should I use a .ui file thanks to Qt designer, is it flexible enough ? 2- Should I use QML to make the design than integrate it to a C++ d...
I prefer building UI completely from scratch. This gives a lot of flexibility and better understanding of what is where, but on the other hand changing layout sometimes is a big headache.
4,606,907
4,607,261
strcmp segmentation fault
Here is a problem from spoj. nothing related to algorithms, but just c Sample Input 2 a aa bb cc def ghi a a a a a bb bb bb bb c c Sample Output 3 5 it counts the longest sequence of same words http://www.spoj.pl/problems/WORDCNT/ The word is less than 20 characters But when i run it, it's giving segmentation fault....
The problem is probably here: while (p != NULL) { p = strtok(NULL, " '\t''\r'"); strcpy(current, p); While p may not be NULL when the loop is entered. It may be NULL when strcpy is used on it. A more correct form of the loop would be: while ((p != NULL) && ((p = strtok(NULL, " \t\r")) != NULL))...
4,607,047
4,607,111
why constructors aren't explicit by default?
It's so easy to forget to mark a constructor "explicit": adding/removing args, making them optional etc. the single reliable way I know is to declare every constructor as explicit and then remove this keyword only if implicitness is required by design (thanks to the standard that allows this not only on single-argument...
Backward compatibility at the time when explicit was added. The language was evolving and changing meaning of existing constructs in an evolving language is a sure way to make your users angry. It is still the case now, backward compatibility is something high in the mind of the comittee.
4,607,069
4,607,135
Is there a function to retrieve integer input?
This one is kinda specific. I want to be able to retrieve an integer from the user using a function rather than cin. I have tried several different things, but none seem to work so I have just wound up writing my own function. It really does baffle me though because it seems like something that would have a function in...
There is no standard function doing what you want.
4,607,197
4,608,915
Access Declaration of Base Class Overloaded Method
Given that we have overloaded methods in base class, and a derived class that was inherited as private/protected. Can we restore only one/several of the original access level of the overloaded methods? On GCC 4.4.0 i try to put the base methods under protected access, then inherited it using private access. When i try...
Changing accessibility of inherited functions through a using declaration cannot be done selectively on given overload for the simple reason that a using declaration only introduces a name into the declarative region and that by definition, functions overloads share the same name. The only alternative I see here is to ...
4,607,418
4,607,440
How do the operators < and > work with pointers?
Just for fun, I had a std::list of const char*, each element pointing to a null-terminated text string, and ran a std::list::sort() on it. As it happens, it sort of (no pun intended) did not sort the strings. Considering that it was working on pointers, that makes sense. According to the documentation of std::list::sor...
In C++, you can't compare just any pointers using the relational operators. You can only compare two pointers that point to elements in the same array or two pointers that point to members of the same object. (You can also compare a pointer with itself, of course.) You can, however, use std::less and the other relati...
4,607,473
4,607,520
C++ significant figures
How can I do math involving significant figures in C++? I want this to work correct with measured data from chemistry and physics experiments. An example: 65 / 5 = 10. I would need to get rid of unneeded decimal places and replace some digits with 0s. Thanks!
Well there are good math libraries in math.h Also storing your figures in floats, doubles or long doubles will allow for more precise operations. Floats offer 7 significant digits while doubles offer 16 significant digits. source Also when printing out usually people use _snprintf or printf and you can format those ...
4,607,509
4,607,597
Pass struct or string array from C++ to C# using COM
I have a COM component (in C#) that has the following interface: namespace InterOp { [StructLayout(LayoutKind.Sequential)] public struct MyStruct { [MarshalAs(UnmanagedType.BStr)] public string name; [MarshalAs(UnmanagedType.BStr)] public string surname; public int ag...
It looks like your question is the same as this: https://stackoverflow.com/questions/268117/safearray-of-structs Specifically, see http://vcfaq.mvps.org/com/4.htm: Import the struct into C++ via the type library generated from C# Call SafeArrayCreateEx(VT_RECORD), SafeArrayAccessData and SafeArrayUnaccessData to popul...
4,607,615
4,607,657
Calling method of derived class on object of base class
I have written a few lines of code which I think should not compile. I am calling a method of a derived class on a static_cast-ed pointer to object of base class as follows: class B {}; class D: public B { public: void bar() { printf("%d\n", m_i); } private: int m_i; }; int main() { B b; D* d = st...
gcc can't guarantee that it's incorrect, except in enough of a minority of cases that it really isn't worth checking. When you use static_cast, then you are promising the compiler that you know wtf you're doing. There are two kinds of casts here. static_cast, which is, you are telling the compiler that pointer to a bas...
4,607,665
4,607,755
"Sleep" function and suspend count
I want to find out whether or not a certain process is sleeping or not (C++/Windows). I'm trying to use the suspend count to do so and suspending to process before the check for profiling processes. I'm doing something like this: SuspendThread(threadHandle); ... Do Some Stuff ... int suspended = ResumeThread(t...
You're confusing threads and processes. ResumeThread and SuspendThread do not operate on process handles, they operate on thread handles. Also, Sleep does not change the suspend count of a process, only ResumeThread and SuspendThread change that. If you're trying to detect if a thread is currently in a Sleep call, y...
4,607,989
4,608,094
Member function overloading/template specialization issue
I've been trying to call the overloaded table::scan_index(std::string, ...) member function without success. For the sake of clarity, I have stripped out all non-relevant code. I have a class called table which has an overloaded/templated member function named scan_index() in order to handle strings as a special case. ...
You explicitly call templated member here: index_table->scan_index<T>(value, [&](uint recno, T n)... Since value is the template parameter you should be fine replacing that with: index_table->scan_index(value, [&](uint recno, T n)...
4,608,195
4,644,412
What parts of C++ are / aren't supported with Brew (MP)?
Hi I'm trying to find out what is and isn't possible with C++ on BrewMP. Does anybody have first hand experience of using C++ with Brew, specifically BrewMP, and can say if they have managed to get these things working on a device without too much hassle: static variables/functions templates exceptions casting etc.
Before in Brew3.X, global and static variables are not supported. However in Brew MP, there is an ELF2MOD tool. With this, you can use global and static varaibles. See your SDK path such as: C:\Program Files\Qualcomm\Brew MP SDK\Toolset 7.10 Rev 10.0.1489821\bin If your global or static data is non-POD (a C++ obje...
4,608,217
5,807,716
silent closing VS 2008 on Windows 7
I am trying to build a MFC Windows Application with Visual Studio 2008 on Windows 7. I use the "Batch build" feature of Visual Studio to get both Release and Debug of several projects' outputs with only one-click. The problem is: Frequently, after I instruct VS 2008, some minutes later VS closes its window without any ...
Seems that installing the patch quoted on http://arstechnica.com/microsoft/news/2009/03/widely-reported-crash-in-visual-studio-2008-sp1-fixed.ars solves the issue.
4,608,780
4,609,011
Compiling a SWIG Python wrapper for a static library?
This is a noob question. I'm trying to learn how to use SWIG to make a python interface for a C++ library. The library is a proprietary 3rd party library; it comes to me in the form of a header file (foo.h) and a static archive (libfoo.a). To simplify matters, I've cooked up an example which I think has the same pat...
I'm not really sure if it's the case for you but in general the order of object files and static libraries matters. The order defines the order of initialisation. You have to put the most general objects and/or static archives as last parameters. The objects/archives with the most dependencies have to be placed at the ...
4,608,791
4,795,343
Enum USB devices in Linux/C++
Im writing IO routines for a linux device that will have various and changing USB devices connected to it. To this end I need to be able to figure out which device is connected to which port so I can open it with the correct software. Something akin to 'udevinfo' would be ideal but I have no idea how to start in writin...
I ended up using a BASH solution in the chkconfig file. I walk through all ttyUSB entries and look at the driver info for each: USB_ID=`egrep -i "mct u232|pl2303|keyspan" -m 1 /proc/tty/driver/usbserial | awk '{ printf( "$d", $1 )}'` if [ -z $USB_ID ] then echo $echo_n "No USB serial adapter found."; exit 1 fi
4,608,838
4,608,945
getting a thread state in c++/windows
There must be a function that gets the current status of a thread in the system because there is this application: http://www.softwareverify.com/cpp/thread-status-monitor/index.html It must be using some sort of API function or something... How can I get a thread state myself in C++/Windows? thanks :) (this is my l...
You can use the following examples to get the running processes and, when you have a process ID, the threads. Taking a Snapshot and Viewing Processes Traversing the Thread List EDIT: After getting the handle to the thread(s) you are interested in you can call GetExitCodeThread but that will only tell you if the thread ...
4,608,876
4,621,621
C# DllImport with C++ boolean function not returning correctly
I have the following function in a C++ DLL extern "C" __declspec(dllexport) bool Exist(const char* name) { //if (g_Queues.find(name) != g_Queues.end()) // return true; //else // return false; return false; } Inside my C# class I have the following: [DllImport("Whisper.dll", EntryPoint="Exist", CallingConvention=C...
I found the solution for your problem. Your declaration should be preceded with this marshaling: [return:MarshalAs(UnmanagedType.I1)] so everything should look like this: [DllImport("Whisper.dll", EntryPoint="Exist", CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)] public static e...
4,608,924
4,609,326
Memory Layout difference between nested classes and multiple inheritance in C++?
I am trying to understand how COM specifies the layout of its objects so that a client that wants to use a COM object knows how to do it. I've read that a COM object that implements multiple interfaces can do it it in different ways including using nested classes or multiple inheritance. My understanding is that both...
COM is completely agnostic of the memory layout of your object. All that it wants and needs is a table of function pointers when it calls IUnknown::QueryInterface(). How you implement it is completely up to you. MFC uses nested classes, just about anything else leverages the built-in support for multiple inheritance...
4,609,094
4,609,105
Boost libraries vc100
I have all boost libraries named with vc80 for example - libboost_serialization-vc80-mt-1_42 but the compiler is looking for libboost_serialization-vc100-mt-1_42 would i need to re-download the libraries for vc100 ?
Yes. You either need to download and install new libraries or build them yourself.
4,609,618
4,609,643
programming windows using VC++ express
Can I develop full fledged win32 app using VC++ express (i.e access to all the win32 APIs). I do't want to use .net, but if it works with .net then its a bonus. I do have Visual studio DVD but I do not want to install ton of crap just to program in C++. I just want to use windows APIs for networking, filesystem, thread...
VC++ Express has access to all of the Windows API. It does not come with a framework for GUI development, but you can easily add a third party package such as Qt or wx, or work directly with the API if you prefer.
4,609,621
5,107,347
Problem installing QCA-OSSL (part of the Qt Cryptographic Architecture) plugin on Windows 7
I have been trying to use QCA (Link) on my Windows PC for a couple of days now, works fine on my linux box, just can't get it working with Windows. So i followed all the instructions for installing QCA and then the ossl plugin for QCA. The QCA works fine but for some reason the plugin isn't showing up in my Qt Creator ...
I've been struggling with a similar situation: qca-ossl builds fine on linux and not at all on windows. I just hit a breakthrough which might help you as well. Versions and Patches qtsdk-2010.05 qca-2.0.3 qca-ossl-r1190163 (from the repository) openssl-1.0.0b First of all, if you're using a newer version (0.9.7+, I t...
4,609,631
4,609,777
deciphering vtable dumps
I am "playing" with virtual inheritance in C++, and I want to know how a class object is laid out. I have those three classes: class A { private: int a; public: A() {this->a = 47;} virtual void setInt(int x) {this->a = x;} virtual int getInt() {return this->a;} ~A() {this->a = 0;} }; class B { priv...
I'm not 100% sure that this answer is correct, but here's my best guess. When you have a class that inherits multiply and non-virtually, the layout of the class is usually a complete object of the first base type, then a complete object of the second base type, then the data for the object itself. If you look at B, yo...
4,609,705
4,610,141
Problems compiling gtkmm
OS: Fedora 14 Compiler: g++ (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4) I installed gtkmm24-devel from repository via yum. To make sure the install went as planned I decided to try one of the examples on the page. #include <gtkmm.h> int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); Gtk::Window window; ...
Short answer Use the output of 'pkg-config gtkmm-2.4 --cflags' for include paths and 'pkg-config gtkmm-2.4 --libs' for libraries to link. Long answer It said it couldn't find gtkmm.h, no problem, I just forgot to link the library. Building a C/C++ program is done in two separate steps. First the source files are comp...
4,610,073
4,610,491
Qt Designer C++ or QML for GUI
I know that the use of QML is quite new in Qt and I was wondering if I should design my application using Qt Designer or QML. I will be using a MVC pattern and my main concern if I use QML for the GUI is that it might not be easy to integrate inside the rest of my C++ app. Feel free to give your personal advice, I woul...
QML is primarily intended for mobile platforms. Due to its youth and its concern for varied platform interface conventions, it lacks standard controls like buttons and combo boxes (but see the Components project). If you're on mobile, or your UI requires a highly customized visual style, QML might be worth considerin...
4,610,086
4,610,138
pthread_cancel() alternatives in Android NDK?
I am porting a mid-sized body of C++ code to Android NDK. Unfortunately the pthreads implementation (as of NDK v5, anyway) is incomplete. Specifically, our application relies on pthread_cancel() to kill a worker thread. NDK does not implement pthread_cancel()! There are other obvious answers when the worker thread is r...
Possible option that works for this guy: http://igourd.blogspot.com/2009/05/work-around-on-pthreadcancel-for.html Reposting here in case: Then I use pthread_kill to trigger a SIG_USR1 signal and use signal handler to exit this pthread and tried it, it works, but still wondering if any drawbacks for this kind o...
4,610,093
4,610,216
Every permutation of the alphabet up to 29 characters?
I'm attempting to write a program that will generate a text file with every possible permutation of the alphabet from one character up to twenty-nine characters. I've chosen 29 as the longest English word that everyone knows is antidisestablishmentarianism which is 28 characters in length. There are longer ones, but th...
The word "permutation" usually means that each letter appears exactly once, so it would be impossible to generate any permutation with more than 26 letters. Anyway, since the number of generated strings is too big, you can use random strings instead (the following is C code): char s[30]; int p; for (;;) // repeat forev...
4,610,142
4,610,190
Doesn't fstream support dynamic creation of files
I'm trying to create files dynamically and it seems like there is no way with fstream. Is there actually any? #include <iostream> #include <fstream> using namespace std; int main () { for (int i = 0; i<2; ++i){ std::ofstream outfile outfile.open ((char)i+"sample_file.txt"); // something like this. numbers appended ...
If you mean with a name created at run time, then yes, but you have to build your name in a valid way. E.g. (after #include <sstream>): std::ostringstream fname; fname << "sample_file_" << i << ".txt"; outfile.open(fname.str().c_str());
4,610,232
4,610,244
Sorting a std::vector<std::pair<std::string,bool>> by the string?
How can I sort this vector by comparing the pair.first which is an std::string? (without providing a static compare function, nor use boost).
std::vector<std::pair<std::string, bool> > v; std::sort(v.begin(), v.end()); std::pair overloads operator< to sort first by the first element then by the second element. Thus, if you just sort the vector using the default sort ordering (operator<), you'll get your desired ordering.
4,610,425
4,610,463
std::vector abort problem
I'm having diffuculty with the example below, the last line is producing an "abort has been called" error. I don't see why this should be. I'm using (*abc).def instead of abc->def for clarity in this case. #include <iostream> #include <string> #include <vector> class branch { public: unsigned short n; ...
The problem with this code is that trunk.left() returns a copy of the branch, not a reference to the branch. Consequently, your focus3 pointer is pointing at a temporary object that's immediately going to be cleaned up after that line of code finishes executing. Consequently, when you try dereferencing focus3 on the ...
4,610,427
4,610,476
std::string copy constructor seg fault
this happens when constructing a structure, my code: http://wklej.org/hash/c42680a7f9d/txt/ at this line: http://wklej.org/hash/5fefcecc371/txt/ backtrace: http://wklej.org/id/451070/txt/ any help is apperciated Sorry, i fail to copy the code here so i post it at any other site ;(
Use a debugger and get a stack trace. The problem is almost certainly passing a bad C string into the std::string constructor. Perhaps the pointer is invalid or the C string does not terminate and the constructor reads off into protected memory. But without more information I can't tell what the bug is. The debugger sh...
4,610,503
4,610,512
How to resolve ambiguity of call to overloaded function with literal 0 and pointer
I'm pretty sure this must have been here already, but I didn't find much information on how to solve this kind of problem (without casting on the call): Given two overloads, I want that a call with function with a literal 0 always calls the unsigned int version: void func( unsigned int ) { cout << "unsigned int" <<...
1) Is there a recommended way to do this in general? Yes, I would do it the way you did in 2). I don't think there is any deeper meaning as to why 2) works. The type int simply doesn't match T*, so it has no way to find out T. It will therefor ignore the template.
4,610,522
4,610,596
modify every element of collection
Is there any common way to get rid of custom 'assign' functor? std::transform could be great but according to c++ standard it prohibits modification of the source elements The goal is to modify collection elements using as more declarative approach as possible template <typename T> struct assign : std::binary_function<...
std::transform() does allow the output iterator to point to the same element as the beginning of your input range. See here. The code example shows essentially this in the line demonstrating a transform with two input ranges. The output iterator is the same as the first input iterator. Does that make it more palatab...
4,610,523
4,610,604
Is there a simple way for opening one (or many) opengl window in mac OS X with C++?
Yes, I hate Objective-c, plus my project will be portable, so I'd like to code as much of it in C++ as possible, ideally 100%. So I have a regular C++ project made with Xcode, and want to open some OpenGL windows. edit: Damn, Glut takes over the app's control with glutMainLoop() and I'll like to have more control ove...
If you don't want to use objective-c you're going to have to use either the deprecated carbon libraries, X11, or another library like GLUT to create the window. If portability is a concern either go the GLUT route, or you'll need to write your own window management code for each platform you want to support. If you don...
4,610,656
5,007,203
Why is class member variable x not allowed to be shared(x) in OpenMP?
In a member function, I can parallelize using the shared member variable int *x like this #pragma omp parallel for default(shared) for(int i=0;i<size;i++) { x[i]=i; } But if I try #pragma omp parallel for default(none) shared(x,size) for(int i=0;i<size;i++) { x[i]=i; } I get the error: 'obj::x' is not a variable...
Most implementations of OpenMP outline the parallel region. That is, they make it a function. Private variables are generally passed to this function and shared variables may be passed or be within the function's scope. The problem with class data members is that they are not the same as variables. When the compil...
4,610,671
4,610,710
Examples of ISO C++ code that is not valid C++/CLI
I've seen contradictory answers on the internet with regard to whether C++/CLI is a superset of C++ or not. The accepted answer on this question claims that "technically no", but doesn't provide an examples of non-C++/CLI code that conforms to ISO C++. Another answer on that question cites a book that says the opposit...
Valid C++, invalid C++/CLI: int main() { int gcnew = 42; } gcnew, generic, and nullptr are all reserved words in C++/CLI; nullptr isn't really an issue in C++0x, of course. Herb Sutter blogged about C++/CLI keywords: Under the hood in 2003. For what it's worth, when I was working on a large mixed codebase (both C...
4,610,673
4,610,794
How to use another classes member variables in c++?
I'm currently programming a Yahtzee game, and I'm having trouble with some of my classes I have two classes, Player, and Scorecard. class Player { private: string name; Scorecard scorecard; }; class Scorecard { public: void display() { //... } }; (All the classes have the appropriate getter...
I would not have Scorecard print the Player's name. A player has-a scorecard. A scorecard does not have a a player. The Player class should have a display method that displays the player's name followed by the score card: class Player { private: string name; Scorecard scorecard; public: void displa...
4,610,937
4,617,869
How to put results into a STL map by using boost-spirit?
#include <QtCore/QCoreApplication> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <iostream> #include <string> #include <list> #include <map> #define CODE_CPP_KEYWORD_ENUM "enum" namespace haha { //简单表示c++的enum的类(A structure use to simply description C++ enum)...
Please have a look at this article, which describes exactly what you're trying to achieve. The gist is that Spirit.Qi allows to directly parse the key/value pairs into a map without any additional code.
4,611,237
4,612,146
Double null-terminated string
I need to format a string to be double null-terminated string in order to use SHFileOperation. Interesting part is i found one of the following working, but not both: // Example 1 CString szDir(_T("D:\\Test")); szDir = szDir + _T('\0') + _T('\0'); // Example 2 CString szDir(_T("D:\\Test")); szDir = szDir...
The CString class itself has no problem with a string containing a null character. The problem comes with putting null characters into the string in the first place. The first example works because it is appending a single character, not a string - it accepts the character as is without checking to see if it's null. Th...
4,611,302
4,611,330
Sorting UTF-8 strings?
My std::strings are encoded in UTF-8 so the std::string < operator doesn't cut it. How could I compare 2 utf-8 encoded std::strings? where it does not cut it is for accents, é comes after z which it should not Thanks
If you don't want a lexicographic ordering (which is what sorting the UTF-8 encoded strings lexicographically will give you), then you will need to decode your UTF-8 encoded strings into UCS-2 or UCS-4 as appropriate, and apply a suitable comparison function of your choosing. To reiterate the point, the UTF-8 encoding ...
4,611,415
4,611,476
Access Powershell via Visual C++ (API)
I'd like to write a program that effectively "pipes" Powershell, so that I can send commands and parse the responses in C++, without actually opening the prompt on the screen. Any tips?
You can certainly do this but you'll need to use managed code as PowerShell's architecture is based entirely on the CLR object model. I'm not sure of the C++ syntax but you can start with the PowerShell class in System.Management.Automation.dll and use its static Create method to create an instance to which you can pip...
4,611,514
4,612,230
Error converting types in C++
I have a program in which I need to use the Format(); function to combine a string literal and a int into a CString variable. I have tried several different ways of doing this, the code for them is here: // declare variables used CString _CString; int _int; // try to use format function with string literal _CString.Fo...
The problem is that you're performing a UNICODE build (which is fine), so the _CString.Format(); function i expecting the first parameter to be a wide character string. You need to use the L"" syntax to form a wide-character string literal: _CString.Format(L"text",_int); Of course, you'll need a specifier to actu...
4,611,987
4,612,113
Undefined OLE references in external library even when linking with libole32
Using MINGW, I'm trying to link my C code with a static C++ library that performs some OLE operations: mingw32-gcc main.o resources.o -o mbcom.exe -L../../Lib/Iup -liup -liupole -lole32 -lcomctl32 -lstdc++ -mwindows Unfortunately, I get this: ../../Lib/Iup/libiupole.a(tOleHandler.o):tOleHandler.cpp:(.text+0x341): unde...
libuuid is where these things should be found. Except VariantInit, which is in liboleaut32.
4,612,273
4,612,318
Correct way to work with vector of arrays
Could someone tell what is the correct way to work with a vector of arrays? I declared a vector of arrays (vector<float[4]>) but got error: conversion from 'int' to non-scalar type 'float [4]' requested when trying to resize it. What is going wrong?
You cannot store arrays in a vector or any other container. The type of the elements to be stored in a container (called the container's value type) must be both copy constructible and assignable. Arrays are neither. You can, however, use an array class template, like the one provided by Boost, TR1, and C++0x: std::v...
4,612,383
4,614,984
Dealing with array of IntPtr
I think I'm close and I bet the solution is something stupid. I have a C++ native DLL where I define the following function: DllExport bool __stdcall Open(const char* filePath, int *numFrames, void** data); { //creates the list of arrays here... don't worry, lifetime is managed somewhere else //foreach item of the...
The runtime will have no clue to the length of the array when receiving unmanaged arrays, you need to use the MarshalAsAttribute in conjunction with the SizeParamIndex field to specify the length of the array. There's an example of this here. You also don't need to define the method signature as ref IntPtr[] for the ar...
4,612,514
4,622,825
SetWindowLongPtr with DialogBoxParam?
A while back I was writing a C++ program with the Win32 API that would display a dialog box and then listen to the messages it generated. At one point, I was interested in associating a piece of data with the dialog window. Were I manually creating the window and attaching a window proc, I'd just use SetWindowLongPtr...
Technically, the GWLP_USERDATA is for the use of the (base in the case of subclassing) window class to use. Because dialogs are a ready made class, GWLP_USERDATA is for internal use - whihc is why dialogs supply a DWLP_USER field for your DialogProc implementation's use. As things stand however, all the internal window...
4,612,583
4,612,611
Will Derived class type compatibility to base class cause a memory leak?
I understand that derived class is type compatible with a pointer to its base class. In the given sample code, new bar object construction takes place calling foo::foo() followed by bar::bar(). In the respective constructors, I am allocating resources to class members foo::int *a and bar::int *b. Now I am initializing...
This is where the idea of the "virtual destructor" comes in. Technically speaking, if you delete an object through a pointer of a base class type, you must mark that base class destructor virtual or the result is undefined. If you do mark the destructor virtual, the meaning is different from other virtual functions. ...
4,612,702
4,613,238
What can cause a pure virtual function call in C++?
I teach a C++ programming class and I've seen enough classes of errors that I have a good feeling for how to diagnose common C++ bugs. However, there's one major type of error for which my intuition isn't particularly good: what programming errors cause calls to pure virtual functions? The most common error I've seen...
"The most common error I've seen that causes this is calling a virtual function from a base class constructor or destructor." When an object is constructed, the pointer to the virtual dispatch table is initially aimed at the highest superclass, and it's only updated as the intermediate classes complete construction. ...
4,612,904
4,615,079
access shadowed global variable in C via dlsym not work
int myvar=100; main() { pid_t (*f) (void ); int *ip; int myvar=10; f = (pid_t(*) (void)) dlsym(RTLD_NEXT, "getpid"); ip = (int *) dlsym(RTLD_NEXT, "errno"); if (ip) printf("%d \r\n", *ip); ip = (int *) dlsym(RTLD_NEXT, "myvar"); if (ip) printf("%d \r\n", *ip); //not work where is i am wrong...
myvar will not be generally exported into the dynamic symbol table, unless you use a linker flag like -rdynamic when linking it.
4,612,999
5,733,221
QtScript output redirection
When I call this code: QScriptEngine e; e.evaluate("print('hello, world!')"); the output text (from print method) is written to main application's terminal. Is there any way to redirect it to a custom QIODevice?
You can replace print() with your own implementation: First, define a C++ function that does what you want. In this case, it's just empty for exposition: QScriptValue myPrint( QScriptContext * ctx, QScriptEngine * eng ) { return QScriptValue(); } Then install that function as your new print(): QScriptEngine e = .....
4,613,032
6,079,363
Difference between Singleton implementations
So, i found different ways to implement the "creation" of the singleton. EDIT: When I say "creation", I mean it. This code would be placed in the Singleton::{ctor} or static Singleton::Init() functions of course. //v1 //the first "1" is casted to a pointer to Ty, then that pointer is casted //back to in...
(Since the question seems to have died, I'll try to answer it on my own.) What v1 does is manually adjusting the this pointer to point to the address of the derived object. Normally, static_cast or a normal c-style cast does this by itself, but maybe that wasn't the case on earlier compilers or there was a bug. What ev...
4,613,077
4,613,193
C++ Using the new operator efficiently
When instantiating a class with new. Instead of deleting the memory what kinds of benefits would we gain based on the reuse of the objects? What is the process of new? Does a context switch occur? New memory is allocated, who is doing the allocation? OS ?
You've asked a few questions here... Instead of deleting the memory what kinds of benefits would we gain based on the reuse of the objects? That depends entirely on your application. Even supposing I knew what the application is, you've left another detail unspecified -- what is the strategy behind your re-use? But e...
4,613,159
4,613,228
Java c++ Reference question
In c++ we use & to represent pass by reference. Since objects are always passed by reference you do not need to use this &? Or does it not matter? How do java and c++ differ in pass by value and reference. Everything in java I thought is pass by reference but it is pass by value? Why is this? So is it primitives are pa...
Clear two things up: C++ default is pass by value always, and you explicitly have to indicate if your function accepts a reference with the & Java is pass by value always (objects are not passed by reference, but the reference is passed by value - i.e. it's a copy of the reference to the object - hence you can modify ...
4,613,361
4,613,398
open source code for RSA implementation in C/C++ (Use library or write my own)
I need open source code for RSA implementation (encrypt/decrypt and others). Can anyone suggest some. Edit: Is it good to use a open source library like opessl or write it your own (Library include other redundant stuff too)
OpenSSL library is the obvious choice. CryptLib is another option, yet you need to check the license (it's quite specific). Regarding writing your own code: if you need only RSA, it's not large and you can write it yourself. However, RSA is almost never used by its own. Usually encryption is performed using random ke...
4,613,498
4,613,524
Traversing nested vectors of strings
There's an issue in my code with nested vectors of strings. It is not printing the strings. void foo(vector<vector<char const *> > const & vcp){ vector<vector<char const *> >::const_iterator i(vcp.begin()); vector<vector<char const *> >::const_iterator e(vcp.end()); for(; i != e; ++i){ vector<char const...
This has nothing to do with the vectors. You are creating temporary std::string objects, getting pointers to their underlying data, and trying to use those pointers after the strings no longer exist. That is not allowed. (Also, feeding '*x' to std::cout, where 'x' is a char const*, would print only the first character ...
4,613,551
4,613,573
good practice in c++ (lazy evaluation)
I have some question about lazy evaluation of c++, can I be sure that this snippet of the code will always work, or it is bad idea? if Yes, why? Thanks in advance if(currentNode == 0 || *currentNode == element){ return; }
It is guaranteed to work: logical AND and OR expression chains are evaluated from left to right, and if the first subexpression satisfies the condition, no further subexpressions are evaluated. In your case, if currentNode is null, it will never get dereferenced by the second subexpression, so the code is safe. As @jdv...
4,613,739
4,616,990
Botan vs OpenSSL vs Crypto++ for cryptography
I want to use a cryptography library to implement RSA, DSA and others. Can anyone suggest which is better if you have used it.
My personal favorite is Botan. It allows for as much control as you want. It allows you to chain several steps together in a "pipe" , where you basically write your data to it and botan first BZip2's it and then RSA /DSA's it or whichever function you want and botan provides. I like the nitty-gritty stuff, like settin...
4,613,768
4,615,295
Scheduled build with C++ in Visual Studio
I use visual studio 2008, and I would like to know if it is possible to run scheduled build on it. Indeed, I have several projects I work on, and every time I change one, it may impact the other. I would like to run, every night, a batch build on all my projects, so when I come in the morning I can see what compiled (...
Both @Rup and @Nawaz have the best solutions. If you're looking for something really low-tech, though, you could consider simply creating a windows task that does a command-line build of your code on a nightly basis.
4,613,805
4,613,833
boost::function assignment to member function
I want to use a boost::function and pass it to a function to function as a callback. I seem to be having some trouble assigning the member function to it. The function that I want to pass it to is a static function (as it is invoked on another thread). boost::function<std::string (ResolverReply& reply)> call_back = st...
It is a known limitation of the standard binders that they do not handle functions which take their parameter by reference. You should consider using boost::bind : boost::function<std::string (ResolverReply& reply)> call_back = boost::bind(&ResolverCommunicator::reply_call_back, this, _1);
4,613,823
4,613,842
Should accessors return values or constant references?
Suppose I have a class Foo with a std::string member str. What should get_str return? std::string Foo::get_str() const { return str; } or const std::string& Foo::get_str() const { return str; } What is more idiomatic in C++?
The short answer is: it depends :-) From the performance point of view returning a reference is (usually) better: you save the creation of a new std::string object. (In this case, the creation is costly enough and the size of the object is high enough to justify make this choice at least worth considering - but this is...
4,613,947
4,614,657
Can I cast a char* buffer to an object-type?
I ask this question out of curiosity rather than difficulty, as I always learn from you, even on unrelated topics. So, consider the following method, written in C++ and linked with g++. This method works fine, as everything is initialized to the correct size. extern "C" { void retrieveObject( int id, char * buf...
In your first effort... void retrieveObject( int id, char * buffer ) { Object::Object obj; extractObject( id, obj ); memcpy( buffer, &obj, sizeof(obj) ); } ...you still had the compiler create the local variable obj, which guarantees correct alignment. In the second effort... void retrieveObject( int ...
4,614,008
4,677,372
In MFC APP, if I call "LoadLibraryA" from "InitInstance", it calls "InitInstance" again and again
I have created an MFCApp using VS2008 wizard. Inside my application's "InitInstance()" I'm calling "LoadLibraryA()" method as I need to load a few dll files. But as soon as I call "LoadLibraryA()", it again calls "InitInstance()" of my application and hence it becomes a infinite recursion stuff. Is there something I'm ...
Yes, you are doing something wrong. You are in mfc90.dll's DllMain and it is not safe to call LoadLibrary from DllMain, says so right here: http://msdn.microsoft.com/en-us/library/ms684175%28v=vs.85%29.aspx
4,614,435
4,614,531
C++ Command Line Apps on Android?
Is it possible to make a command line app for linux, and then run it on android with shell? Since android runs on linux, I don't see why there would be any problems running it. I know that /system/bin/* has all the things you can use from adb so this should be the same.
Yes, it's possible. Here is one claim of doing this successfully.
4,614,564
4,614,868
Boost Asio io_service, Read Messages from Client
I am trying to Create a simple Tcp Server in C++ using Boost ASio Library. I wrote two classes TcpConnection and TcpServer. The behaviour I need is that The Tcp Server should be able to send messages to all the connected clients and clients should be able to register/deregister with the server. I was able to achieve t...
Firstly this appears to be incorrect! boost::array<char, 1> buf; You are declaring an array of size 1! I'd suggest something bigger! boost::array<char, 1500> buf; Aside from the buffer, I can't see anything wrong with your code, just check that you are not interleaving async_read calls on the same socket.
4,614,598
4,614,634
c++ get an string(serialized object) from ostream
I have an Image class which has the following implementation friend std::ostream& operator << ( std::ostream &os,Image* &img); So I can serialize it by calling ostm << img; // which will write an string into the ostream. Is it possible to get that string out of the ostream or serialize it directly into an string ob...
Yes, you can use a std::ostringstream. E.g. #include <sstream> #include <string> #include <stdexcept> std::string Serialize( const Image& img ) { std::ostringstream oss; if (!(oss << img)) { throw std::runtime_error("Failed to serialize image"); } return oss.str(); }
4,614,687
4,614,726
how to print data inside a char pointer (c++)?
I have a function(const char * data) { //how to print the data which is inside the data } when I debug I see only the address. If I print (*data) nothing is printed. Any idea?
#include <iostream> void function(const char * data) { std::cout << data; }
4,614,784
4,615,066
Converting 32-bit float to IEEE 80-bit
I'm trying to convert a 32-bit float into an extended precision 80-bit float. I'm using MSVC x86. I tried the following inline ASM code: void Convert32To80(float *value, void *outValue) { __asm { fld float ptr [value]; fstp tbyte ptr [outValue]; } } Here, void *outValue is a buffer that is ...
OK, this should do it: void Convert32To80(float *value, void *outValue) { __asm { mov eax,dword ptr [value] fld dword ptr [eax] mov ecx,dword ptr [outValue] fstp tbyte ptr [ecx] } } All I did was wrote some C code to do the same, but for a float to double conversion, loo...
4,614,861
4,614,895
What's the equivalent function in KissFFT for fftw_plan_dft_r2c_1d() from FFTW?
I've got a project that uses fftw_plan_dft_r2c_1d and fftw_plan_dft_c2r_1d from FFTW, as well as fftw_execute. What are the equivalent functions in KissFFT?
You need to use the real-optimised functions in kiss_fftr.h (in the tools subdirectory). Use kiss_fftr_alloc instead of setting up FFTW "plans" with fftw_plan_dft_r2c_1d and fftw_plan_dft_c2r_1d. Use kiss_fftr and kiss_fftri to do the forward/inverse transforms instead of calling FFTW's fftw_execute. Don't forget to ca...
4,614,960
4,615,224
Class not being consistent
I have made a nibble class that appears to work, but when I use it more than once, the result is different. the following code should illustrate the problems. #include <cstdlib> #include <iostream> using namespace std; class nibble{ public: nibble(){} nibble(int n){ for (int x=0;x<4;x++){ b[...
Do following changes: bool bit(int n){ return b[n-1]; } void set(int n,bool bl ){ b[n-1]=bl; } Finally (how did you miss this?) private: bool b[4]; //you had b[3]
4,615,021
4,615,059
Bad allocation exceptions in C++
In a school project of mine, I was requested to create a program without using STL In the program, I use a lot of Pointer* = new Something; if (Pointer == NULL) throw AllocationError(); My questions are about allocation error: is there an automatic exception thrown by new when allocation fails? if so, how can I catch...
Yes, the new operator will automatically thrown an exception if it cannot allocate the memory. Unless your compiler disables it somehow, the new operator will never return a NULL pointer. It throws a bad_alloc exception. Also there is a nothrow version of new that you can use: int *p = new(nothrow) int(3); This versio...
4,615,046
4,615,130
C++ get each digit in int
I have an integer: int iNums = 12476; And now I want to get each digit from iNums as integer. Something like: foreach(iNum in iNums){ printf("%i-", iNum); } So the output would be: "1-2-4-7-6-". But i actually need each digit as int not as char. Thanks for help.
int iNums = 12345; int iNumsSize = 5; for (int i=iNumsSize-1; i>=0; i--) { int y = pow(10, i); int z = iNums/y; int x2 = iNums / (y * 10); printf("%d-",z - x2*10 ); }
4,615,064
4,615,131
Dynamic binary from file
This is a little bit of weird problem here. Say I have a C++ code, running on a specific platform. The only purpose of this code is to run files containing binary, NATIVE to that platform. Now - my question is - HOW would I get the data from these files (could even be by bits, like 1024 bits a cycle) to the memory of m...
You should just read file to memory, mark this memory as executable (it's platform-specific, for example VirtualProtect() for Windows), and call it as function: ((void(*)())ptr)(); Of course code in file should be position-independent.
4,615,102
4,616,749
C++ library for log parsing
Is there any C++ library specifically for log parsing (helping recognize multiline events)? Like MergeLog for Apache logs or libcurl for web parsing?
Unless you stumble upon a suitable library, my advice would be to use a standalone lexer. Instead of flex + bison, use flex alone (C/C++). Instead of ocamllex + ocamlyacc, use ocamllex alone (OCaml). Ragel (C/C++/Objective C/D/Java/Ruby). This way you avoid having to define a grammar (which is kind of pointless for l...
4,615,171
4,615,222
are there problems with this macro - check status and return if failed
we have a frequently recurring lines in the code that check for the return status of a function, and if it's a failure return with the status immediately. I thought of defining a macro for this: #define RETURN_IF_FAILED(x) { int stat = (x); if (FAILED(stat)) return stat; } The local variable is because the parameter x...
I would like to modify it a bit; enclosing it with do{} while(0) like this: #define RETURN_IF_FAILED(x) do { int stat = (x); if (FAILED(stat)) return stat; } while(0) Now you can use this MACRO, like this: if (SomeCondition) RETURN_IF_FAILED(x); //<--- note the "usual" semicolon! else { //some code } With your v...
4,615,192
4,615,235
Why does the "static" keyword have so many meanings in C and C++?
As we know, the keyword static has multiple meanings in C. C99 added the possibility of legally writing void foo (int arr[static 50]) { // ... } which adds to the confusion, and C++ has static member variables and functions. This would not be so troublesome if all the uses could be connected in some way, but I fi...
Adding new keywords to a language breaks backwards compatibility. So static gets used where its use might possibly mean something ( int arr[static 50] vs int arr[auto 50] or int arr[extern 50] ) and cannot syntactically appear in that location based its use in previous versions. Though in that case adding a not_less_th...
4,615,205
4,615,537
Open file from QTextBrowser
I am just trying to write a code to open file by clicking a link which is displayed in QTextBrowser. But file is not getting open instead it is displaying in QTextBrowser itself. Here is my code void MainWindow::openTextEdit() { QTextBrowser *p = new QTextBrowser(); p->show(); p->append("<a href = \"/home...
It sounds like the anchorClicked signal could be useful to you. It contains the URL of the clicked link as a QUrl. Edit: OP asks for a usage example. I don't have time for that right now, but here's roughly what I would do: Let the class that needs to open a file have a slot foo that takes a const QUrl&. foo can use Q...
4,615,232
4,615,257
Qt - How to override a widget?
I've created a form using the Qt designer which includes a QToolButton. I can turn it using ui->favouriteToolButton. I used the designer because it's much more simple then code all the gui. Problem is that specifically for this ToolButton i want to code by creating its own class: class FavouriteMenu : public QToolButto...
Right click on the button in designer and select "Promote To..." Under Promoted class name enter "FavouriteMenu" Under Header File enter the filename of the .h file Click "Add" Click "Promote"
4,615,491
4,615,651
static const references to temporaries
I have a templated class that is dependent on two template parameters to calculate its values but only one for construction. I would like to relieve the dependency on the second over its lifetime. I am looking at doing this by using a templated static function to calculate the values and then create an instance. All...
This should be okay. Since the reference temp is bound to the temporary object, the lifetime of the temporary is extended to the lifetime of temp, which extends past the end of main(). But I don't see any real reason to use a reference there. Why not just: { static const FOO<member> foo = FOO<member>::CreateFOO<s...
4,615,890
4,618,059
How to handle C++ exceptions when calling functions from Lua?
I have a working C++ function that I am able to call from Lua. To demonstrate my problem here is an example: int PushHello(lua_State *L){ string str("Hello"); lua_pushlstring(L, str.data(), str.length()); return 1; } Note: I know I don't have to use string variable there, but it is there to demonstrate the...
I have found a reasonable solution. The question is whether it is correct. Instead of exporting (or calling via lua_cpcall) the original function int PushHello(lua_State *L) a wrapper int SafeFunction<PushHello>(lua_State *L) is exported/called. The wrapper looks like: template<lua_CFunction func> int SafeFunction(lua_...
4,615,912
4,619,562
Is there an equivalent to OpenAL <alc.h> in OpenSL ES?
I made a game in C++ with OpenGL ES rendering and using OpenAL for sound. To make it work on iPhone I could not use ALUT so I use only "al.h" and "alc.h". I now try to build my game with the last Android SDK, that supports native applications and added sound support with OpenSL ES. (I believed OpenSL ES was to OpenAL w...
I found this on the site that seemed to have what you're looking for: Android OpenAL? Looks like someone was able to compile OpenAL for Android. Hopefully this can get you started!
4,616,037
4,616,199
C++ Inheritance Exercise
Class One : public Two { public: One() { Three three; cout << "something"; } private: Four _four; }; I have to display a sentence: "One Two Three Four Five Six Seven" and class One have to remain as it is. Ever...
What we can deduce, based solely on the known definition of One (and my remembrance of C++ construction rules, which may not be 100% accurate :-), not taking into account any additional possible inheritance relationships between the classes: the output of Two() (being the base class constructor) comes before the outpu...
4,616,148
4,618,213
Sharing memory between modules
I was wondering how to share some memory between different program modules - lets say, I have a main application (exe), and then some module (dll). They both link to the same static library. This static library will have some manager, that provides various services. What I would like to achieve, is to have this manager...
I think you're going to need assistance from a shared library to do this in any portable fashion. It doesn't necessarily need to know anything about the objects being shared between modules, it just needs to provide some globally-accessible mapping from a key (probably a string) to a pointer. However, if you're willin...
4,616,281
4,616,326
Unable to use LVM_GETITEMTEXT without target application crashing in C++
I'm trying to capture data from a SysListView32 class (according to Spy++) from another application. Sending a LVM_GETITEMCOUNT message to this handle always returns the correct number of items. There is a child window which is SysHeader32 which presumably contains header titles. When I try to send a LVM_GETITEMTEXT me...
Your problem is that since the list view exists in another process, the memory you allocate is not valid in that other process. I refer you to an article over at The Code Project which offers a solution. What's more, you do not appear to have allocated any memory for lpText so it would fail in your own process.
4,616,462
4,616,517
How to overload and call a method in a derived class which was previously defined in its base class?
This is the base class: template <class T> class DataLogger { // ... public: void AddData(T Data); // ... } And this is the derived class: #include "DataLogger.h" #include <utility> class Plotter : public DataLogger<std::pair<long double, long double>> { // ... public: ...
Your AddData from the base is hidden by the AddData from derived class. Either explicitly qualify the call DataLogger<std::pair<long double, long double>>::AddData(...) or bring it to scope with using DataLogger<std::pair<long double, long double>>::AddData;
4,616,732
4,616,849
What does this code line infer?
I understand that std::pair couples two different/same date types. If used as shown under, what does it say ? And what is it useful for in this case ? class A : public B<std::pair<long double, long double>> Thanks.
It infers that B is a template class, and that A derives from the specialization of B that works with pairs of long doubles. One possible use of that pattern would be a generic complex number implementation. In that scenario, you would be deriving a class from a generic complex type based on long double (sometimes more...
4,616,742
4,616,820
My C++ executable runs way faster outside the Visual Studio 2008 IDE than inside, even in release
I build a C++ application that does some number crunching. I'm running in Visual Studio 2008 PRO SP1, in release mode, Windows 7 64 bit. If I run it inside the IDE, the application takes 4 minutes, if I run the same executable from windows explorer it takes 6 seconds! I have no clue. I have checked that this does not ...
Presumably, the slow down is caused by the debugger being attached when you are starting the application in Visual Studio. This is the case even when you've built the program in "Release" mode. To confirm that this is indeed the source of your problem, try running your application without the debugger, using the "Start...
4,616,887
4,616,968
Memory management of hDCs
I've got an ID3DXFont (which is Direct3D9, by the way) which offers a method GetDC() which returns a handle to a device context (hDC). How is the memory for this value managed? MSDN doesn't mention anything about it and it doesn't provide it's own memory management like COM interfaces do.
You need to release that handle with ReleaseDC(HDC).
4,617,167
4,617,232
static member functions and thread-safety
Objects and variables created in a static member function are not considered 'local' as they would in a member function, so that they can now be shared amongst multiple threads right? Whereas if you have a member function which creates some object, this would be local to the thread and therefore it is non-shared. Am I ...
No you are not correct. Objects created in a static function are not shared, and this is also the case for any normal functions. Objects can be shared though if they are declared static themselves, and it does not depends if the function is static or not. void myFunc() { static MyObject o; o.CallMethod(); // he...
4,617,188
4,617,283
Object Oriented Design for an Image with ImageList
I am making a class which represents and Image, and with Windows, you store images in ImageList controls. This class will be used to handily add images to other controls like ListViews or Buttons, or simply to draw on the screen. My question is: what is the proper design for something like this? Should each Image have ...
Generally, I would recommend something in between. It seems silly to have a different image list for each image. They're designed to store collections of images and make managing these collections more efficient, not so much to hold a single image. Then again, there are drawbacks to trying to use one giant image list f...
4,617,446
4,617,709
How does typeid work and how do objects store class information?
http://en.wikipedia.org/wiki/Typeid This seems to be a mystery to me: how does a compiler stores information about the type of an object ? Basically an empty class, once instantiated, has not a zero size in memory.
How it is stored is implementation-defined. There are many completely different ways to do it. However, for non-polymorphic types nothing needs to be stored. For non-polymorphic types typeid returns information about the static type of the expression, i.e. its compile-time type. The type is always known at compile-time...
4,617,469
4,617,502
Error C2227,C2065, Class within a Class
I'm trying to structure my code like this main <- game <- player. IF I write in main: player* P; P = new player; P->move(); Everything works but when trying to move this code in to the game component I run in to problems. Here is the parts of game.cpp I need help with. #include "game.h" #include <string> using names...
Move #include "player.h" to game.cpp if you need only pointers or references on game.h. If you need to reference Player on game.h to declare a pointer, you can use a forward declaration, like: class Player; class game { Player *myPlayer; };
4,617,518
4,617,563
Call non-specialised template class function from specialized template class function
Is it possible to call a function defined in a non-specialised template class from a specialised template class? Here is an example of what i am attempting: template <typename T> struct Convert { static inline void toString(unsigned num, unsigned places, std::string& str) { ... } }; template <> struct Convert<int8_t>...
In general, this isn’t possible. There are different possible solutions but they “cheat”. The first is to hoist off the actual default logic into a different function that is not specialized. Now you can call this function from both toString implementations. The second alternative entails inheriting from the non-specia...
4,617,727
4,618,032
Can Silverlight run a library written in C++ on PC/Mac/Linux?
I have some C++ libraries. Is there a way to use them from Silverlight in a cross platform way (on Linux/Mac/PC)? I don't want to use C++/CLI if possible. I googled this article saying COM is the only way. However, I was told that Silverlight4 supports PInvoke.
Silverlight 4 does not support PInvoke so the answer is no you can't directly use your C++ Libraries. PInvoke is currently expected to be in Silverlight 5 for release sometime this year (2011). See this John Papa blog Silverlight 5 Features, bullet point on OOB features.
4,617,904
4,618,566
What is a good platform for building a game framework targeting both web and native languages?
I would like to develop (or find, if one is already in development) a framework with support for accelerated graphics and sound built on a system flexible enough to compile to the following: native ppc/x86/x86_64/arm binaries or a language which compiles to them JavaScript ActionScript bytecode or a language which com...
There is a language currently in development by Blitz Research ( http://www.blitzbasic.com ), it is NOT YET released, although the release date looms close. The blog of the main developer is here: http://marksibly.blogspot.com/2010/05/hi-ok-heres-plan-i-am-currently-working.html This language has been announced as free...
4,617,978
4,618,394
Is there any standardized and commonly-used library for C (C99 or whatever), as STL is for C++?
Possible Duplicate: Container Class / Library for C I expect I'd be forced to use vectors, lists and sets for my C program. Should I invent those entities from scratch, or there is some kind of standard library for C as STL is for C++ ?
You can look at APR, or GLib. Those are widely used portable C libraries with everything you need not to reinvent the wheel each time.
4,618,101
4,618,206
Using libcurl on windows, in my c++ project, with visual studio, does not work because string get corrupted
As explained in the title, I am trying to use the libcurl C API to submit simple http query. I am using windows as an OS, C++ as a language, Visual Studio 2008 as an IDE. My code is quiet simple: I initialize curl: CURLcode init = curl_global_init(CURL_GLOBAL_ALL); I initialize my handle: CURL* handle = curl_easy_init...
"Linking againgst libcurld.lib (version 7.21.3) compile using the vc6curl.dsw project" This is the problem. Static libraries must be built with the same compiler and the same runtime libraries (/MDd). You can avoid this with DLL version of libcurl.
4,618,102
4,618,122
understanding pointers c++
When i write this code: Animal *p; Animal b; p = &b; In the first line when I am creating a pointer. Does a new object of Animal is created or only when you write the second line? Thanks.
In the first line, a pointer is created but it doesn't point to anything yet. In the second line you create an actual Animal object.
4,618,117
4,618,192
Vtable placement of completely pure-virtual class
According to my (limited) knowledge of the C++ spec, the vtable of a class with virtual members is placed at the definition of the first non-pure non-inline virtual method. How do compilers handle classes which inherit from a class with ALL pure virtual methods (interfaces, for example)? Where is the vtable placed in t...
The vtable stores the addresses of the implemented virtual methods. If all methods of a class are pure-virtual and none are implemented, then no vtable needs to be generated. You could not use such a class for much without some classes which derive from it and implement the methods. Each class with implemented virtua...
4,618,202
4,626,444
How can I compile XJig for Snow Leopard?
I'm trying to compile XJig (http://sourceforge.net/projects/xjig/) for Snow Leopard and getting errors: make c++ -m32 -DUSE_MIT_SHM -DJIG_DEFAULT=\"/usr/lib/games/xjig/tina.gif\" -c xjig.C -o xjig.o xjig.C:161: warning: deprecated conversion from string constant...
The 'somebody' who fixed it was me. I rushed a fixed after your first posting. Go and download again.(2.5.4-1) I missed a couple of references to the old ppm stuff, the errors only showed on a fresh build. It should compile ok now. If you still have problems, contact me directly. About the make file. The make file is c...
4,618,265
4,618,795
Help with the use of std::locale?
I have a class that I want to use to sort my string, bool pair vector. My strings are utf-8 encoded. I want to sort them so that, if the person's locale is set to for example, French, I would hope that if the user typed: zap apple école blue erable That it would sort out to be: apple blue école era...
I don't think VC++ supports UTF-8 locales. You should probably convert to wstring and use collate<wchar_t>, or switch to a C++ library that supports UTF-8 locales. Locale names on Windows/VC++ are different than on UNIXes; see Language and Country/Region Strings (CRT) on MSDN.
4,618,399
4,619,040
Suppressing warning: comparison is always false due to limited scope of data type
I have a templated function for returning the number of digits in a number: template <typename R> static inline unsigned count(const R num) { if(num < 10) return 1; else if (num < 100) return 2; else if (num < 1000) return 3; else if ...
If you don't care about user-defined integer types (and evidence suggests that you don't care about negative values, either), just define one function which takes the largest type that you care about: inline unsigned count(unsigned long long num){ if(num < 10) return 1; else if (num < 100) ...