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,264,819
2,264,847
Ambiguity while including std class libraries
I have Visual studio 2005 . One of my header file has a enum like typedef enum { scalar, array, set } increment; When I try to include the header file I get an ambiguity error for "set". I am using the std::set in this cpp file . The issue is the compiler is unable to differentiate between the std::set and the set in t...
Don't import the std namespace into the global namespace. The STL set is in the std namespace so if you don't have the line using namespace std in your headers you shouldn't get a conflict. Beyond that, refactor your enum.
2,265,022
2,265,161
Alternative for templates in C++
I wrote code that looked like the following: template<typename CocoaWidget> class Widget : boost::noncopyable { private: CocoaWidget* mCocoaWidget; public: Widget() { mCocoaWidget = [[CocoaWidget alloc] init]; } // ... }; class Button : Widget<NSButton> { // ... }; But that doesn't work, because Mac...
Are you sure you can't do this (have you tried)? The quote from Mac Dev Center says you can't declare an Objective-C class inside a template. What you're doing, however, is merely declaring a pointer to an Objective-C object inside a template -- quite a different thing, and I don't see a reason why it shouldn't be allo...
2,265,027
2,265,065
problem mixing c and c++
i need to build a c++ project that exports functions to c project this is my c++ class : ** MyCppClass.h ** class MyCppClass { public: static void MyCppMethod() } ** MyCppClass.cpp ** void MyCppClass::MyCppMethod(){} *now i need to create an interface for the Method MyCppMethod (static). i did that : ** MyExport.h** ...
you can easily conditionally define the extern if that is what you want to do as such: #ifdef __cplusplus #define EXTERN_C extern "C" #else #define EXTERN_C #endif And then: EXTERN_C Export MyCppMethodWrapper();
2,265,187
2,265,222
start/stop thread in ctor/dtor or better use start()/stop()?
I've a class that internally uses a worker thread. Currently the ctor starts the thread and the dtor stops (and waits for) it. Is this considered good code? I think it would be better to have separate start() / stop() functions for this purpose. One of the problems is that stopping and waiting for the thread may throw ...
I would probably not start the thread in the constructor, but rather have a start function. If the worker thread is basically invisible to the user then it might make little difference, and starting in the constructor might be better. But if the user interacts with the worker thread in any way (e.g. their code is run i...
2,265,192
2,265,212
Sound capture in CPP and Qt
I would like to capture some sound from the microphone in cpp, in order to use it in a Qt application. So I'm looking for a multi platform library easily integrable in a Qt4 project.
OpenAL is a good, cross-platform C++ library for capturing audio.
2,265,381
2,265,406
How do I check my template class is of a specific classtype?
In my template-ized function, I'm trying to check the type T is of a specific type. How would I do that? p/s I knew the template specification way but I don't want to do that. template<class T> int foo(T a) { // check if T of type, say, String? } Thanks!
I suppose you could use the std::type_info returned by the typeid operator
2,265,518
2,265,540
returning two created arrays in c++
Hi I have a text file containing two arrays and one value(all integers) like this 3 90 22 5 60 33 24 Where the first number stands for how many integers to read in. I can read in all this in one function. Do I need several functions to be able to use the different matrices and the first variable? ifstream in(SOMEF...
Whenever you want to group together data items, use a class or a structure. For example, to pass three integers as x, y and z coordinates,: struct Coord { int x, y, z; }; and then pass the structure to the function: void f( Coord & c ) { } The same goes for arrays, but in your case you would make the structure co...
2,265,650
2,718,770
How can I send messages to/from a Websphere Message Broker from an embedded C client (no JVM)?
What are my options for pubsubing (or point to point but pubsub is better) messages to and from an IBM message broker from an embedded headless C/C++ linux client that doesn't have a JVM? Ideally we want large file transfer (2GB once per day off of the client) encryption (SSL) reliable ('assured' delivery / QoS2, maybe...
Why not just use the WMQ C/C++ API? The WMQ Client install is downloadable as SupportPac MQC7: WebSphere MQ V7.0 Clients. Once you have that, just use the C API and compile as usual. This is all native WMQ base product functionality. Note that the WMQ V7 QMgr with the WMQ v7 client provides much better interop with...
2,265,664
2,265,674
How to dynamically allocate an array of pointers in C++?
I have the following class class Node { int key; Node**Nptr; public: Node(int maxsize,int k); }; Node::Node(int maxsize,int k) { //here i want to dynamically allocate the array of pointers of maxsize key=k; } Please tell me how I can dynamically allocate an array of pointers in the constructor -- th...
Node::Node(int maxsize,int k) { NPtr = new Node*[maxsize]; } But as usual, you are probably better off using a std::vector of pointers.
2,265,671
2,265,953
How to force QDateTime::fromString to read UTC time
I have some input containing UTC time formatted according to iso8601. I try to parse it using QDateTime: const char* s = "2009-11-05T03:54:00"; d.setTimeSpec(Qt::UTC); d = QDateTime::fromString(s, Qt::ISODate); Qt::TimeSpec ts = d.timeSpec(); When this fragment ends, ts is set to localTime and d contains 3 hou...
What about setting the time spec after the fromString method. const char* s = "2009-11-05T03:54:00"; d = QDateTime::fromString(s, Qt::ISODate); d.setTimeSpec(Qt::UTC); Qt::TimeSpec ts = d.timeSpec();
2,265,967
2,265,981
Writing a LinkedList destructor?
Is this a valid LinkedList destructor? I'm still sort of confused by them. I want to make sure I'm understanding this correctly. LinkedList::~LinkedList() { ListNode *ptr; for (ptr = head; head; ptr = head) { head = head->next delete ptr; } } So at the beginning of the loop, pointer ptr is set...
Why not do it much much simpler - with an elegant while-loop instead of trying to carefully analyze whether that overcompilcated for-loop is correct? ListNode* current = head; while( current != 0 ) { ListNode* next = current->next; delete current; current = next; } head = 0;
2,266,179
2,266,192
C++ STL map I don't want it to sort!
This is my code map<string,int> persons; persons["B"] = 123; persons["A"] = 321; for(map<string,int>::iterator i = persons.begin(); i!=persons.end(); ++i) { cout<< (*i).first << ":"<<(*i).second<<endl; } Expected output: B:123 A:321 But output it gives is: A:321 B:123 I want it to maintain the...
There is no standard container that does directly what you want. The obvious container to use if you want to maintain insertion order is a vector. If you also need look up by string, use a vector AND a map. The map would in general be of string to vector index, but as your data is already integers you might just want t...
2,266,203
2,266,773
Using boost.assign on collection of shared_ptr
Consider the following snippet: class Foo { public: Foo( int Value ); // other stuff }; std::list< boost::shared_ptr< Foo > > ListOfFoo = list_of( 1 )( 2 )( 3 )( 4 )( 5 ); This does not work out of the box. What is the simplest way to make this work, or is there any method to assign values to ListOfFoo as si...
boost::assign::ptr_list_of lets you construct a Boost pointer container with a very simple syntax. You can extend it through private inheritance so that it lets you create containers of shared_ptr: template< class T > struct shared_ptr_list : boost::assign_detail::generic_ptr_list<T> { typedef boost::assign_detail...
2,266,218
2,266,242
Memory / heap management across DLLs
Although it seems to be a very common issue, I did not harvest much information: How can I create a safe interface between DLL boundaries regarding memory alloction? It is quite well-known that // in DLL a DLLEXPORT MyObject* getObject() { return new MyObject(); } // in DLL b MyObject *o = getObject(); delete o; mig...
As you suggested, you can use a boost::shared_ptr to handle that problem. In the constructor you can pass a custom cleanup function, which could be the deleteObject-Method of the dll that created the pointer. Example: boost::shared_ptr< MyObject > Instance( getObject( ), deleteObject ); If you do not need a C-Interfac...
2,266,290
2,266,527
Link a static library to a DLL
I am using Visual Studio 5.0 I have DLL and a static library . My intention is to use a static function that is defined in the static library . I have included the header file in the intended source cpp and also given the path in the project dependencies . Still it gives me linker errors . Following is the linker error...
It could be that the linker is not finding your function because it is compiled with different settings. Like release vs debug, unicode vs non-unicode, differences in calling conventions. That may cause the name to be mangled differently. If the .h file is written in c, not c++, you might need to disable name mangling ...
2,266,317
2,266,384
Question on Call-By-Reference?
main() calls Call_By_Test() function with argument parameter First Node. I have freed the First Node in Call_By_Test() but First node address not freed in main(), why ?. typedef struct LinkList{ int data; struct LinkList *next; }mynode; void Call_By_Test(mynode * first) { free(first->next); first->next...
Since the question is tagged c++, I would refactor to: void Call_By_Test( mynode *& first ) // rest of code remains the same That conveys the pass-by-reference without extra dereferences. All the solutions that propose passing a pointer to the pointer (void Call_By_Test( mynode ** first )) are using pass-by-value sema...
2,266,417
2,269,330
Delphi: Calling a function from a vc++ dll that exports a interface / class
i have some trouble accessing a dll written in vc++ that exports an interface. First i tried to use classes, but after some google-search i came to the solution, that this i not possible. I just want to make sure, that the plugin interface can accessed, by using other languages like c++. Delphi Interface IPlugIn = inte...
You get the access violation because this code extern "C" bool __declspec(dllexport) __stdcall LoadPlugIn(IPlugIn* PlugIn); bool __declspec(dllexport) __stdcall LoadPlugIn(IPlugIn* PlugIn) { PlugIn = new TMyPlugIn; return TRUE; } creates an instance of your plugin class and writes the address to the stack, where it...
2,266,452
2,270,723
How to programmatically clear the Kerberos ticket cache
Does anyone know how to clear out the Kerberos ticket cache on the local computer - using managed \ unmanaegd code? Thanks in advance!
I believe you need to do a call to LsaCallAuthenticationPackage using KERB_PURGE_TKT_CACHE_REQUEST after using either LsaConnectUntrusted or LsaRegisterLogonProcess. Sorry no specifics, but I don't have my code for this around...
2,266,735
2,268,489
Make an executable at runtime
Ok, so I was wondering how one would go about creating a program, that creates a second program(Like how most compression programs can create self extracting self excutables, but that's not what I need). Say I have 2 programs. Each one containing a class. The one program I would use to modify and fill the class with da...
Building an executable from scratch is hard. First, you'd need to generate machine code for what the program would do, and then you need to encapsulate such code in an executable file. That's overkill unless you want to write a compiler for a language. These utilities that generate a self-extracting executable don't re...
2,266,975
2,267,189
Can I measure the necessary buffer for sprintf in Microsoft C++?
I'm writing a small proof-of-concept console program with Visual Studio 2008 and I wanted it to output colored text for readability. For ease of coding I also wanted to make a quick printf-replacement, something where I could write like this: MyPrintf(L"Some text \1[bright red]goes here\1[default]. %d", 21); This will...
You want _snwprintf. That function takes a buffer size, and if the buffer isn't big enough, just double the size of the buffer and try again. To keep from having to do multiple _snwprintf calls each time, keep track of what the buffer size was that you ended up using last time, and always start there. You'll make a few...
2,267,026
2,267,633
Crypto++ Version 5.6.0
anyone used the latest version of cryptopp. i think its 5.6.0. I have a solution working in unix. but in windows I am stuck. Anyone here already using cryptopp 5.6 in vs2008 could you please give very specific instructions on how you compiled this? i have also posted in the cryptopp user groups for an answer. There are...
All I did was open the cryptest.sln file and tell it to build. EDIT: Visual Studio did have to convert from VS2005 format but it compiles and runs just fine.
2,267,253
2,267,492
rotation, translation in opengl through header file?
I've a header file called base.h which has all initial display and stuff like, my main aim is to simulate a robot with degree of freedom. class center_rods { public: center_rods() { } void draw_center_rod() { glPushMatrix(); glTran...
You should put some state to represent the transformations inside one of the classes (probably the robot). You can represent the orientation as Euler angles, a matrix or quaternion, but Euler angles are probably the simplest to start out with. The glutkeyBoardFunc function should then modify this state through member ...
2,267,262
2,267,363
Storing data effectively
maybe i'm having stupid question as always, but somehow i can't google out how should I store variables so it's effective. Our teacher on c++ just by the way droped something about how could size of the stored data type affect the speed of storing it (like searching for closest sufficient continuous block of memory) an...
In general for numeric variables (such as loop counters) you should use "int" and let the compiler choose the most efficient size for the task. If you have a particular need for a specific size (eg uint16 for a 16-bit part of a packet header being received off a network, or similar) then use a typedef that gives that s...
2,268,339
2,268,647
Change version of documented code in doxygen (without using macros)
Is there any way to change the version in a comment block? For e.g. const char VER[] = "1.2.3.4"; /** * \version (VER) */ I know how to do this with preprocessing and I was wondering if there were any other way? On a related note, how do you guys handle changing version numbers in documentation, the application, et...
Most developers use a source control tool which usually provides a mechanism for obtaining the current revision, stringizing it, and inserting into the source. Something along the lines of const char *VER = "$Rev$";
2,268,478
2,268,538
unable to start "program.exe" the system cannot find the file specified vs2008
I am able to successfully build solution. but i keep getting this when i try to start debugging or executing it. any suggestions why this might be the case? update: i fixed the issue. I just recreated the proj with empty files and then just rebuild and it worked. one question: when i start the program (its a console ap...
Make sure the debug command (Properties > Configuration Properties > Debugging > Command) is pointing to the output file built by your selected configuration. (Properties > Configuration Properties > General > Output Directory), (Properties > Configuration Properties > Linker > General > Output File)
2,268,562
2,268,587
What are intrinsics?
Can anyone explain what they are and why I would need them? What kind of applications am I building if I need to use intrinsics?
Normally, "intrinsics" refers to functions that are built-in -- i.e. most standard library functions that the compiler can/will generate inline instead of calling an actual function in the library. For example, a call like: memset(array1, 10, 0) could be compiled for an x86 as something like: mov ecx, 10 xor eax, eax...
2,268,749
2,268,783
Defining global constant in C++
I want to define a constant in C++ to be visible in several source files. I can imagine the following ways to define it in a header file: #define GLOBAL_CONST_VAR 0xFF int GLOBAL_CONST_VAR = 0xFF; Some function returing the value (e.g. int get_GLOBAL_CONST_VAR()) enum { GLOBAL_CONST_VAR = 0xFF; } const int GLOBAL_CONS...
(5) says exactly what you want to say. Plus it lets the compiler optimize it away most of the time. (6) on the other hand won't let the compiler ever optimize it away because the compiler doesn't know if you'll change it eventually or not.
2,268,762
3,086,422
How to add statusbar correctly?
Currently it is floating on top of my rendered window, i dont think thats good for few reasons: 1) i waste rendering time for rendering stuff that isnt visible. 2) it must be rendered every frame again when i wouldnt be updating the whole statusbar every frame anyways. So how i could create a window where it leaves spa...
http://www.gamedev.net/community/forums/topic.asp?topic_id=291682 Edit: Its not a simple question to answer. If you don't know what a child window is under Win32 then you may be in a much better position. However asking someone to give you a full explanation of the windows windowing system is no mean feat. Here is an...
2,268,768
2,268,802
anyone know how to add command line args in vs2008
i have a program that runs like so: a.out 23421232 now if i use a.out it will tell me check params and gives an example and closes. I am curious if there is a way to add command line args when executing my code in vs2008?
VS doesn't normally produce an executable named a.out like most Unix compilers do. Instead, given an input XXX.cpp, it'll produce an executable named XXX.exe. Adding command line arguments is done by bringing up the project properties (Alt+F7), selecting "Debugging" and then entering the argument(s) in the "Command Arg...
2,268,790
2,269,256
How to debug application when third-party library provides no debug build?
I have an application I'm working on that uses two third party libraries, each with pre-compiled libs and dlls, one of which provides necessary .lib files for both debug and release builds (A[d].lib) and the other which provides only .lib files for release builds (B.lib). Compiling in Release mode (using MSVC9) works f...
Do you want full debug mode, or do you just want to be able to debug? If the later is the case, just go to the linker options, and turn on the generation of symbolic information (.pdb). This way you can use the debugger in your own code, step through the lines, and look at variables. If you get annoyed by the changes i...
2,269,003
2,270,101
C++ - What libraries or command line programs will I need to create a program that takes an AVI file and burns it to a DVD?
My goal is to create a program that will take an AVI file as input and then do whatever is necessary to burn it to a DVD. Currently, I use three separate programs to accomplish this. The first tool requires me to convert it from an AVI file to an MPEG. The second tool takes that MPEG and creates DVD files (a VIDEO_TS f...
I know you are using Windows, but here are the steps I take to create a DVD from multiple AVIs on linux. The main three programs are ffmpeg to do the transcoding, dvdauthor to build the DVD filesystem, and growisofs to make a DVD image out of the DVD filesystem. I think you can find windows binaries for each of them ...
2,269,546
2,269,613
How to construct a std::list iterator in loop with increment
I'm trying to do a double-loop over a std::list to operate on each pair of elements. However, I'm having some trouble initialising the second iterator. The code I'd like to write is: for(std::list<int>::iterator i = l.begin(); i != l.end(); ++i) { for(std::list<int>::iterator j = i+1; j != l.end(); ++j) { ....
How about: for (std::list<int>::iterator i = l.begin(); i != l.end(); ++i) { for (std::list<int>::iterator j = i; ++j != l.end(); ) { // ... } }
2,269,865
2,269,876
How to create a Taskbar on multiple monitors?
I have three monitors and I want too create a taskbar on all three of them in C++ ?
There are various solutions already available to do this; in the past I've used UltraMon but recently I have switched to DisplayFusion as it does a better job replicating the Windows 7 Taskbar.
2,269,918
2,269,979
C++ Win32, easiest way to show a window with a bitmap
It's only for 'debugging' purposes, so I don't want to spend a lot of time with this, nor it is very important. The program exports the data as a png, jpg, svg, etc... -so it's not a big deal, though it could be good to see the image while it is being generated. Also, the program is going to be used in a Linux server; ...
The biggest piece of work here is actually registering the window class and writing a minimal window procedure. But if this is debug only code, you can actually skip that part. (I'll come back to that later). If you have an HBITMAP, then you would use BitBlt or StretchBlt to draw it, but if you don't already have the...
2,270,047
2,270,061
How do I use errorno and _get_errno?
Calling system() to run an external .exe and checking error code upon errors: #include <errno.h> #include <stdlib.h> function() { errno_t err; if( system(tailCmd) == -1) //if there is an error get errno { //Error calling tail.exe _get_errno( &err ); } } First two...
A typical usage is like: if (somecall() == -1) { int errsv = errno; printf("somecall() failed\n"); if (errsv == ...) { ... } } which is taken from here.
2,270,073
2,271,649
How do I troubleshoot boost library/header inclusion via autoconf/automake?
I'm new to autom4te, and I'm trying to use autoconf/automake to build and link a C++ program on multiple architectures. Complicating the linking is the fact that the project requires boost (filesystem, system, program_options). I'm using boost.m4 (from http://github.com/tsuna/boost.m4/tree/), and it seems to locate all...
It does not compile because it the library are not properly set... The script does not configure correctly the -lboost_libraryname option. $(BOOST_PROGRAM_OPTIONS_LIB) -> $(BOOST_PROGRAM_OPTIONS_LIBS) in tyour makefil.am your_program_LDFLAGS The ax_boost_***.m4 script in the the following repository worked fine with ...
2,270,110
2,270,371
How to rotate Bitmap in windows GDI?
How would I go about rotating a Bitmap in Windows GDI,C++?
You can do it with GDI+ (#include <gdiplus.h>). The Graphics class has the RotateTransform method. That allows arbitrary rotations. Use Image::RotateFlip() if you only need to rotate by 90 degree increments, that's a lot more efficient.
2,270,138
2,270,210
Does passing an empty range (identical iterators) to an STL algorithm result in defined behavior?
Consider the following: std::vector<int> vec(1); // vector has one element std::fill(vec.begin(), vec.begin(), 42); std::fill(vec.begin()+1, vec.end(), 43); std::fill(vec.end(), vec.end(), 44); Will all of the std::fill usages above result in defined behavior? Am I guaranteed that vec will remain unmodified? I'm incli...
No, if doesn't cause undefined behavior. The standard defines empty iterator range in 24.1/7 and nowhere it says that supplying an empty range to std::fill algorithm causes undefined behavior. This is actually what one would expect from a well-thought through implementation. With algorithms that handle emtpy range na...
2,270,166
2,270,198
boost::filesystem::create_directories(); adding folders to strange locations
I'm using boost to create a directory to place some temp files in. int main( int argc, char* argv[] ) { std::cout << "Current Dir: " << argv[0] << std::endl; boost::filesystem::create_directories( "TempFolder" ); return 0; } Now if double click the exe, the folder "TempFolder" is created in the same direc...
I think it's because of the way you 'execute' your binary. In the first case you double click it and it will run in 'current' directory. In the second case you drop file on it which causes different action by Windows to execute your binary. In the second case the binary runs in your 'home' directory I believe. It's the...
2,270,472
2,270,490
How to parse HTML in C++?
How would I go about parsing HTML in C++ on my Webserver Application?
libxml2 has a HTML parser. libxml++ is a wrapper for libxml2, but I'm not sure if it exposes the HTMLparser functionality.
2,270,527
2,283,599
How to code a new Windows Shell?
How would I go about coding a new Windows Vista Shell?
Everything you need to do as shell has never been documented, so there are some issues with file change notifications etc. The basics are: SystemParametersInfo(SPI_SETMINIMIZEDMETRICS,...MINIMIZEDMETRICS) with (undocumented?) flag 8 Register as the shell (SetShellWindow,SetProgmanWindow,ShellDDEInit,RegisterShellHook ...
2,270,552
2,270,584
What is a packet UDP/TCP?
Im getting into Winsocks and is there any reference to tell me what a packet is. Like UDP/TCP Packets?
A good starting point for TCP/IP is here: http://en.wikipedia.org/wiki/Internet_Protocol_Suite, and for UDP here: http://en.wikipedia.org/wiki/User_Datagram_Protocol In addition, this looks like a pretty good introduction to Winsock in C++: http://www.madwizard.org/programming/tutorials/netcpp/
2,270,598
2,270,636
C++ template black magic
This needs only work in g++. I want a function template<typename T> std::string magic(); such that: Class Foo{}; magic<Foo>(); // returns "Foo"; Class Bar{}; magic<Bar>(); // returns "Bar"; I don't want this to be done via specialization (i.e. having to define magic for each type. I'm hoping to pull some macro/templa...
Try typeid(Foo).name() for a start. Parse as you see fit; will be implementation-dependent (but simply getting a string back is portable).
2,270,622
2,270,743
Program crash in x64, works fine in Win32
I'm working on an application which builds and runs fine in Win32. However, in x64, it builds but crashes on run. Looking at the code and narrowing down the problem, if I comment out the call to the below function, it runs with no problem. void vec3_copy (double* v1, const double* v2) { v1[0] = v2[0]; v1[1] = v2[...
The fact that it still crashes with memcpy confirms that the source of the bad pointer is elsewhere, as expected. How big is the application? It looks like somewhere along the line, a pointer was truncated to 32 bits or otherwise corrupted. Most likely you will need to spend some quality time with the debugger to tra...
2,270,726
2,270,745
How to determine the size of an array of strings in C++?
I'm trying to simply print out the values contained in an array. I have an array of strings called 'result'. I don't know exactly how big it is because it was automatically generated. From what I've read, you can determine the size of an array by doing this: sizeof(result)/sizeof(result[0]) Is this correct? Because f...
You cannot determine the size of an array dynamically in C++. You must pass the size around as a parameter. As a side note, using a Standard Library container (e.g., vector) allieviates this. In your sizeof example, sizeof(result) is asking for the size of a pointer (to presumably a std::string). This is because the ...
2,270,942
2,270,959
Problem referring to the exe path in _wsystem() in Windows XP
I am having problem referring to the file path in Windows XP (SP2). Actually I want to run an exe file from a specified path say "C:\users\rakesh\Documents and settings\myexe.exe" in my program...I am using the function _wsystem("C:\users\rakesh\Documents and settings\myexe.exe") to run the file.. The problem is that i...
Just like on the command line, the spaces need to be inside double quotes: _wsystem ("\"C:/users/rakesh/Documents and settings/myexe.exe\""); Note that forward slashes work just fine for path delimiters.
2,270,995
2,271,004
Exiting from C++ Console Program
I currently have a program which has the following basic structure main function -- displays menu options to user -- validates user input by passing it to a second function (input_validator) -- if user selects option 1, run function 1, etc function1,2,3,etc -- input is requested from user and then validated by ...
One possibility would be to do it by throwing an exception that you catch in main, and when you catch it, you exit the program. The good point of throwing an exception is that it lets destructors run to clean up objects that have been created, which won't happen if you exit directly from elsewhere (e.g., by using exit(...
2,271,016
2,271,162
Equivalent to toString() in Eclipse for GDB debugging
In Eclipse I can override the toString() method of an Object to pretty print it. This is especially useful because during a debug sessions as I can click on a variable and see the object in a human readable form. Is there any kind of equivalent for C++ during a gdb session. I'm also open to any IDEs that can emulate ...
In gdb, print command prints the contents of the variable. If you are using any IDE for C++, eg. Netbeans, Eclipse, VC++ then pointing on the variable shows the content. EDIT: See if the below code is what you are looking for. #include <string> using std::string; #define magic_string(a) #a template<typename T> class ...
2,271,046
2,271,055
If changing a const object is undefined behavior then how do constructors and destructors operate with write access?
C++ standard says that modifying an object originally declared const is undefined behavior. But then how do constructors and destructors operate? class Class { public: Class() { Change(); } ~Class() { Change(); } void Change() { data = 0; } private: int data; }; //later: const Class object; //object.Ch...
The standard explicitly allows constructors and destructors to deal with const objects. from 12.1/4 "Constructors": A constructor can be invoked for a const, volatile or const volatile object. ... const and volatile semantics (7.1.5.1) are not applied on an object under construction. Such semantics only come into ef...
2,271,376
2,272,424
Find a window using c++ and modifying controls
I would like to use c++ without mfc(and not clr) in order to modify textbox's and activate a button on a form outside of my project. I don't know where to start. I've done a lot of searching but can only find information for VB. A starting point would help. Thanks. I tried this and it doesn't seem to work. HWND fWindow...
Use spy++ or winspector to see the actual "text" of the window. (Strictly speaking, the caption of the window need not match it's window text. Especially true of "fancy" windows which paint their own caption.) The following works fine for me (using Calc.exe to test). HWND hwnd = NULL; hwnd = FindWindow(NULL,_T("Calcula...
2,271,385
2,271,404
Don't understand the const method declaration
Too much C# and too little C++ makes my mind dizzy... Could anyone remind me what this c++ declaration means? Specifically, the ending "const". Many thanks. protected: virtual ostream & print(ostream & os) const
A const method will simply receive a const this pointer. In this case the this pointer will be of the const ThisClass* const type instead of the usual ThisClass* const type. This means that member variables cannot be modified from inside a const method. Not even non-const methods can be called from such a method. Howe...
2,271,390
2,271,402
Expected constructor, destructor, or type conversion before '*' token
I honestly have no idea why this is happening. I checked, double-checked, and triple-checked curly braces, semicolons, moved constructors around, etc. and it still gives me this error. Relevant code follows. BinTree.h #ifndef _BINTREE_H #define _BINTREE_H class BinTree { private: struct Node { float da...
Because on the line: Node* BinTree::make( float d ) the type Node is a member of class BinTree. Make it: BinTree::Node* BinTree::make( float d )
2,271,907
2,271,925
Correct BOOST_FOREACH usage?
When using BOOST_FOREACH, is the following code safe? BOOST_FOREACH (const std::string& str, getStrings()) { ... } ... std::vector<std::string> getStrings() { std::vector<std::string> strings; strings.push_back("Foo"); ... return strings; } Or should I grab a copy of the container before calling BOOST_FOR...
And although BOOST_FOREACH is a macro, it is a remarkably well-behaved one. It evaluates its arguments exactly once, leading to no nasty surprises
2,271,980
2,271,985
Recursive functions in C/C++
If we consider recursive function in C/C++, are they useful in any way? Where exactly they are used mostly? Are there any advantages in terms of memory by using recursive functions? Edit: is the recursion better or using a while loop?
Recursive functions are primarily used for ease of designing algorithms. For example you need to traverse a directory tree recursively - its depth it limited, so you're quite likely to never face anything like too deep recursion and consequent stack overflow, but writing a tree traversal recursively is soo much easier,...
2,271,997
2,272,025
Is it possible to find out if a VNC connection is active
My application is running on windows XP, a VNC server is also running on the PC. I'd like to find out if someone is currently connected to the VNC server (e.g. to use simpler icons). I'm using UltraVNC. Is there a simple (preferably documented) way to to this? EDIT: Apparently someone voted to close because he/she thou...
check the status of port 5900
2,272,109
2,272,155
safe reading from a stream in a for loop using getline
I want to read from a stream using std::getline inside a for loop. The stream I mean is a class inherited from the std::basic_iostream. std::string line; for(;;){ try{ std::getline( myStreamObj, line ); if( line != "" ){ std::cout << line << std::endl; } ...
If you want to capture the errors via exceptions you need to set it using ios::exception. Otherwise an exception will not be thrown. You can check out the documentation here: http://www.cplusplus.com/reference/iostream/ios/exceptions/. You can also explicitly call ios::fail(), ios::bad() or ios::eof(). Docs here: http:...
2,272,200
2,272,291
undefined referance to LibSerial
So i'm writing a serial transmision program, and have just changed over to using C++, it been a while since I used C++ (I've been working with C recently, and before that java) Now I need to use LibSerial, (it seems much simpler to use than C's termios) my code is: //gen1.cpp #include "string2num.h" // a custom header...
This is the linker complaining that it cannot find the functions referenced by the libserial header file. If I look on my Linux system to see how the shared library is called: $ dpkg -L libserial0 ... /usr/lib/libserial.so.0.0.0 /usr/lib/libserial.so.0 On my system this implies I would add -lserial as a g++ option (ak...
2,272,316
2,272,467
how to capture mouse cursor in screen grab?
I'm using OpenGL to grab the contents of the Mac OSX screen - thsi works very well, except it does not grab the mouse cursor graphic. I need to somewhow get that cursor graphic, either as part of my screen capture routine, or separately. My question is either: How can I ensure that the mouse cursor image is included w...
You can use I/O Kit to read the pixels for the current cursor. See IOFramebufferShared.h and IOGraphicsLib.h for some of the relevant API.
2,272,735
2,272,772
Private/public header example?
Can someone please give me an example of how public and private headers work? I have done some reading on the net but I can't seem to find much useful information with sample codes. I was advised that I should use private headers to separate the public and private parts of my code for creating a static library. After s...
You have two header files MyClass.h and MyClass_p.h and one source file: MyClass.cpp. Lets take a look at what's inside them: MyClass_p.h: // Header Guard Here class MyClassPrivate { public: int a; bool b; //more data members; } MyClass.h: // Header Guard Here class MyClassPrivate; class MyClass { public: ...
2,272,922
2,276,166
vim omnicomplete vs. vim intellisense
Are Vim OmniComplete and Vim Intellisense mutually exclusive or complementary? I'm a bit confused by conflicting terminology and implementations, such as these C++ OmniComplete and C++ Intellisence plugins.
Vim Omnicomplete is a feature of Vim version 7, on all platforms. Vim Intellisense is a plugin for vim 6.1 and 6.2 on Windows only.
2,272,955
2,277,414
How to detect if HPET is available
how can I detect (using C++) wether my system has a HPET or not? Thx for your help, Tobias HPET = High Precision Event Timer
If your system has a HPET, then it should be listed in the device manager and therefore somewhere in the registry. I would see if there is a key in there somewhere that denotes a HPET. I'm not in win32 right now, but msdn mentions HKEY_LOCAL_MACHINE\Drivers\Active. http://msdn.microsoft.com/en-us/library/aa447470.aspx
2,273,091
2,273,105
C++ Is private really private?
I was trying out the validity of private access specifier in C++. Here goes: Interface: // class_A.h class A { public: void printX(); private: void actualPrintX(); int x; }; Implementation: // class_A.cpp void A::printX() { actualPrintX(); } void A::actualPrintX() { std::cout << x: } I built thi...
private is not a security mechanism. It's a way of communicating intents and hiding information that other parts of your program do not need to know about, thus reducing overall complexity. Having two different header files is not standards compliant, so technically you're entering undefined behaviour territory, but p...
2,273,146
2,273,199
Compile for x64 with Visual Studio?
Question: Assume a C++ hello world program, non .NET. With Visual Studio 2005/2008/2010, how can I compile a 64-Bit application ? I have a 64 Bit Windows, but by default, VS seems to compile 32 bit executables... On Linux with g++, I can use -m32 and -m64, but how can I compile a 64 bit solution with Windows ? Is it e...
There is a step-by-step instructions by Microsoft: http://msdn.microsoft.com/en-us/library/9yb4317s.aspx
2,273,187
2,273,360
Why is the delete operator required to be static?
I found this one question asking the same thing, however only the 'new' part was answered, so here goes again. Why is the delete operator required to be static? Somehow it doesn't make sense. The new operator makes perfect sense, just like the constructor can't be virtual, neither can the new operator. However, the des...
The answer in the language rules is really in 12.5 [class.free]. If you are deleting via a pointer to a base class then the destructor must be virtual or you get undefined behaviour. Otherwise, the implementation has to determine the dynamic type of the object being deleted. 12.5/4 says that when the delete isn't prefi...
2,273,264
2,273,281
Extracting 'parts' of a hexadecimal number
I want to write a function getColor() that allows me to extract parts of a hexadecimal number entered as a long The details are as follows: //prototype and declarations enum Color { Red, Blue, Green }; int getColor(const long hexvalue, enum Color); //definition (pseudocode) int getColor(const long hexvalue, enum Colo...
Generally: Shift first Mask last So, for instance: case Red: return (hexvalue >> 16) & 0xff; case Green: return (hexvalue >> 8) & 0xff; default: //assume Blue return hexvalue & 0xff; The ordering of the operations help cut down on the size of the literal constants needed for the masks, which gen...
2,273,285
2,273,298
pass by reference c++
My teacher in c++ told me that call by reference should only be used if I'm not going to change anything on the arrays inside the function. I have some really big vectors that I'm passing around in my program. All the vectors will be modified inside the functions. My matrices are of sizes about [256*256][256][50]... Is...
My teacher in c++ told me that call by reference should only be used if I'm not going to change anything on the arrays inside the function. It should be used when you are not changing something inside the function or you change things and want the changes to be reflected to the original array or don't care about the ...
2,273,330
2,273,352
Restore the state of std::cout after manipulating it
Suppose I have a code like this: void printHex(std::ostream& x){ x<<std::hex<<123; } .. int main(){ std::cout<<100; // prints 100 base 10 printHex(std::cout); //prints 123 in hex std::cout<<73; //problem! prints 73 in hex.. } My question is if there is any way to 'restore' the state of cout to its orig...
you need to #include <iostream> or #include <ios> then when required: std::ios_base::fmtflags f( cout.flags() ); //Your code here... cout.flags( f ); You can put these at the beginning and end of your function, or check out this answer on how to use this with RAII.
2,273,380
2,273,448
How to create a C-style array without calling default constructors?
I am writing a memory-managing template class in which I want to create a C-style array of fixed size, to serve as a heap. I keep the objects stored in an array like this: T v[SIZE]; As this only serves the role as a heap that can hold T objects, I don't want the T default constructor to get automatically called for e...
The standard containers use allocators to seperate allocation/deallocation from construction/destruction. The standard library supplies a single allocator which allocates on the heap. This code declares an array big enough to hold SIZE elements of type T with the correct allignment: typedef typename std::tr1::aligned_s...
2,273,475
2,274,301
Magic COLORREF/RGB value to determine when to use light/dark text
Years ago, in my long lost copy of Charles Petzold's Windows 3.0 Programming book, there was a magic COLORREF or RGB value documented that you could use to check whether you should draw text in a light colour or a dark colour. E.g. if the background colour was below this value, then use black text, if it was higher, u...
I can't tell about COLORREF but I've got good results using the luminance as threshold: Y= 0.3 * R + 0.59 * G + 0.11 * B with colours expressed as a decimal value between 0.0 and 1.0. If Y>=0.5 I considered the background "light" (and used dark text), if Y<0.5 I did the opposite. I remember I also used other form...
2,273,488
2,273,983
Graphics primitive generators
I'm looking for something that can generate primitives (e.g. rounded rectangles for dialog boxes etc) so I can load them into a DirectX textured Sprite. Functionality is like SPriG.
Its pretty easy and there are 2 ways : 1) If you are using DirectX10+ use Direct2D. 2) Use GDI+ to draw them onto a texture. Both are integrated with the system and do not need for any external library. Just pick and use. As far as Direct2D, I don't know all the details, but I can assure you can do whatever you want wi...
2,273,777
2,273,792
Is <value optimized out> in gdb a problem?
I have an application that only crashes in -O2 optimization (compiled with gcc 4.2.4). When I step through the code and get to the spot that crashes and try to inspect the value, I get a "value optimized out" in gdb. I read on the internet that this means that the value is stored in the register. I was wondering if m...
It's 99% likely to be a bug in your code and 1% likely to be a compiler code generation bug. So spend a proportionate amount of time looking for latent bugs in your code but be aware that you just may have found a code generation bug (in which case you'll need to study the compiler generated code carefully to see what ...
2,273,811
2,273,842
C++: returning by reference and copy constructors
References in C++ are baffling me. :) The basic idea is that I'm trying to return an object from a function. I'd like to do it without returning a pointer (because then I'd have to manually delete it), and without calling the copy-constructor, if possible (for efficiency, naturally added: and also because I wonder if I...
The best way to understand copying in C++ is often NOT to try to produce an artificial example and instrument it - the compiler is allowed to both remove and add copy constructor calls, more or less as it sees fit. Bottom line - if you need to return a value, return a value and don't worry about any "expense".
2,273,863
2,273,879
How do I use Xerces w/ in a Windows environment?
I have downloaded the source for Xerces and am trying to use it in a Greenhills project. I get the following error: could not open source file "xercesc/util/Xerces_autoconf_config.hpp" The code where the error hit is commented as: // If the next line generates an error then you haven't run ./configure #include <xerc...
you can't you will have to install some unix like environment like Cygwin.
2,273,865
2,279,490
Update system environment variable from c++
I am currently writing an unmanaged C++ program which works with a system environment variable. I am getting the value with GetEnvironmentVariable(...). Now I have an C# program which may change this variable at any time, e.g. like this: Environment.SetEnvironmentVariable("CalledPath", System.Windows.Forms.Application....
Thank you guys but I finally figured it out myself. Since the values I receive with GetEnvironmentVariable are not the current ones I read the values directly from the registry. The machine environment variables are stored in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment I read them v...
2,273,934
4,302,176
OpenGL Calls Lock/Freeze
I am using some dell workstations(running WinXP Pro SP 2 & DeepFreeze) for development, but something was recenlty loaded onto these machines that prevents any opengl call(the call locks) from completing(and I know the code works as I have tested it on 'clean' machines, I also tested with simple opengl apps generated b...
After some research, it seems that there is something actively blocking user->kernel mode calls for OGL, probably an option of DeepFreeze. DirectX works flawlessly though, so I've switched over to that.
2,274,181
2,279,930
Send custom information through Windows FileSystem Attributes
Before getting into the point, I'll give you an overview of what I want to do. Because I don't know if using Windows Filesystem attributes is the right option to do that. I have two components in the system. One of them is a ShellExtension that put an OverlayIcon when some condition is satisfied, and the other componen...
Why so complex? There's a proper interface for this. Call GetFileInformationByHandleEx(FileRemoteProtocolInfo) to get a FILE_REMOTE_PROTOCOL_INFO. Put your protocol-specific data in ProtocolSpecificReserved. That's 64 bytes big. The closest alternative to your current idea which might work would be to use FILE_ATTRIBUT...
2,274,188
2,274,252
fatal error LNK1104: cannot open file 'libboost_regex-vc90-mt-gd-1_42.lib'
i'm trying to use boost regex within my program the problem is i get this error... the only installation step i did was to add: "C:\Program Files\boost\boost_1_42" into the Additional Include Directories... i'm using VS2008... trying to implement this: #include <iostream> #include <string> #include <boost/regex.hpp> u...
Some Boost libraries have to be built; this is one of them. Here's how you can build them: Make a new file called boost_build.bat, and inside put: bjam toolset=msvc-9.0 variant=release threading=multi link=static define=_SECURE_SCL=0 define=_HAS_ITERATOR_DEBUGGING=0 bjam toolset=msvc-9.0 variant=debug threading=multi l...
2,274,356
2,274,399
What are the default return values for operator< and operator[] in C++ (Visual Studio 6)?
I've inherited a large Visual Studio 6 C++ project that needs to be translated for VS2005. Some of the classes defined operator< and operator[], but don't specify return types in the declarations. VS6 allows this, but not VS2005. I am aware that the C standard specifies that the default return type for normal functions...
operator< returns a bool by default. operator[] returns int by default (I think), but it should almost certainly be changed to return whatever the collection contains. For the String example you gave above, that would be a char or wchar_t.
2,274,428
2,274,457
How to determine how many bytes an integer needs?
I'm looking for the most efficient way to calculate the minimum number of bytes needed to store an integer without losing precision. e.g. int: 10 = 1 byte int: 257 = 2 bytes; int: 18446744073709551615 (UINT64_MAX) = 8 bytes; Thanks P.S. This is for a hash functions which will be called many millions of times Also th...
You need just two simple ifs if you are interested on the common sizes only. Consider this (assuming that you actually have unsigned values): if (val < 0x10000) { if (val < 0x100) // 8 bit else // 16 bit } else { if (val < 0x100000000L) // 32 bit else // 64 bit } Should you need to test for other sizes...
2,274,661
2,274,831
Throwing non-const temporaries by reference
Is there any problem with throwing an object constructed on the stack in a try-block by non-const reference, catching it and modifying it, then throwing it by reference to another catch block? Below is a short example of what I'm refering to. struct EC { EC(string msg) { what = msg; } string where; string w...
There's no such thing as "throwing by reference". It is simply impossible. There's no syntax for that. Every time you try to "throw a reference", a copy of the referenced object is actually thrown. Needless to say, there are no attempts to throw by reference in your code. It is possible to catch a previously thrown exc...
2,274,686
2,299,215
C++ for Wireless Sensor Networks
Similar to: Why are RTOS only coded in C, but: Besides the numerous myths about C++, why is it not used as much as C/nesC (TinyOS) for WSN? Knowing C++ can be used for Simulating Wireless Sensor Networks with OMNeT++ it is hard not to think that it can also be used in real-time embedded systems as C is to accomplish ev...
I believe the answers to the following question apply here. Is there any reason to use C instead of C++ for embedded development?
2,274,769
2,274,815
C++ pointers to class instances
I have an (for C++ programmers better than me) simple problem with classes and pointers. I thought about posting example code describing my problem but I found it easier to just explain it in words. Assuming I have three classes: Class A: The main class - it contains an instance of both B and C. Class B: This class co...
Wouldn't you simply pass a pointer or reference to he B object? class C { public: void DoSomethingWithB( B& b) { b.Greet( ); // will work fine } }; class A { public: B b; // Not caring about visibility or bad class/variable names here C c; void StartTest( ) { c.DoSomethingW...
2,274,854
2,274,894
What are the possible reasons the system() function can not find the executable?
if( system("tail -500 log.txt") == -1) { //Error calling tail.exe on log //errno is a system macro that expands int returning //the last error. strerror() converts the error to it's //corresponding error message. printf("Error calling tail.exe with system(): %s",strerror( errno )); ...
From the docs on system() that you linked: ENOENT Command interpreter cannot be found. So the problem isn't that it can't find tail.exe, the problem is that it can't find the command interpreter. This suggests that something larger is going wrong. We'll need more information to diagnose the real problem. Also from...
2,275,076
2,275,095
Is std::vector copying the objects with a push_back?
After a lot of investigations with valgrind, I've made the conclusion that std::vector makes a copy of an object you want to push_back. Is that really true ? A vector cannot keep a reference or a pointer of an object without a copy ?! Thanks
Yes, std::vector<T>::push_back() creates a copy of the argument and stores it in the vector. If you want to store pointers to objects in your vector, create a std::vector<whatever*> instead of std::vector<whatever>. However, you need to make sure that the objects referenced by the pointers remain valid while the vect...
2,275,132
2,275,164
opengl problem with QT
I'm using QT with opengl to make a chart in order to use it in different simulated physical experiments, but I'm facing the following problem. I can't see my chart line unless I minimized my form window and then maximized it, and I should do that all the time as long as my line chart is being drawn in order to get the ...
It looks like you aren't doing a repaint until minimize/maximize. I suggest using a timer to get the job done. Posting your code will help!!
2,275,184
2,275,237
What is the best tutorial for learning MPI for C++?
I plan to use MPI for my C++ code. I have installed MPICH2 on my computers. But I do not know much about MPI and hope to find some materials to read. I hope you experts can recommend some good materails to me. Any advice will be appreciated.
I'm assuming you already know how to program C++ pretty well and have a basic understanding of parallel programming (or at least know how you want to parallelize your code). I would check out the book Using MPI first. Using MPI 2 is the follow on book that discusses using the new bits in MPi-2. Both books were writte...
2,275,225
2,275,245
Find boundaries of an array of objects with only the boundaries of the objects
New Programmer here. Trying space invaders. I have a 2 dimensional array of objects stored in a one dimensional array (using modulo to determine rows and columns). Each object will return its boundaries in graphical space. I need to determine the boundaries (top, bottom, left, right) of the whole array for collision de...
The overall boundary box is overall_top = min(all of top) overall_bottom = max(all of bottom) overall_left = min(all of left) overall_right = max(all of right)
2,275,251
2,311,973
Debugged Program Window Won't Close
I'm using VS 2008 on a 64-bit XP machine. I'm debugging a 32-bit C++ DLL via a console program. The DLL and EXE projects are contained in the same SLN so that I can modify the DLL as I test. What happens is that every once in a while I kill the program with Debug | Stop Debugging (Shift-F5). VS stops the program, but t...
It's KB978037. Uninstalling it resolves the issue. More info here
2,275,373
2,275,454
Disjoint Set ADT Implementation in C++
I have problem in implementing a disjoint set ADT in C++ due to the fact that our teacher only explained the union and find operations. I fully understand the concepts of union and find but I am still confused about how to implement them. Could someone please give me an idea of the implementation and also explain what ...
You have way too many requirements, we're not here to do your homework for you. Have a look at http://en.wikipedia.org/wiki/Disjoint-set_data_structure
2,275,520
2,275,932
Creating a prefixed sequence in one line
Given the initialized variables unsigned a, unsigned b with b > a and std::vector<std::string> strings of size b-a. How can I fill strings with the elements e.g. "x3" "x4" "x5" "x6" (in case a=3 and b=7) for arbitrary a and b with one C++ command (meaning one semicolon at all :))?
Not too challenging... std::transform( boost::make_counting_iterator(a), boost::make_counting_iterator(b), strings.begin(), "x" + boost::lambda::bind(boost::lexical_cast<std::string, unsigned int>, boost::lambda::_1));
2,275,601
2,366,234
Documenting namespaces with Doxygen
I'm having issues with Doxygen recognizing namespaces and modules. I believe the issue surrounds whether to place the \addtogroup within the namespace or outside the namespace. Example 1, outside the namespace: /*! * \addtogroup Records * @{ */ //! Generic record interfaces and implementations namespace Records ...
I have performed an experiment using Doxygen and the two examples and here are the results. The class names in the examples have been renamed to avoid confusion with Doxygen. Example 1, Outside Namespace /*! * \addtogroup Records * @{ */ //! Generic record interfaces and implementations namespace Records { //!...
2,275,653
2,275,700
Object construction/Forward function declaration ambiguity
Observation: the codes pasted below were tested only with GCC 4.4.1, and I'm only interested in them working with GCC. Hello, It wasn't for just a few times that I stumbled into an object construction statement that I didn't understand, and it was only today that I noticed what ambiguity was being introduced by it. I'l...
This is known as "C++'s most vexing parse". See here and here.
2,275,829
2,640,961
scons setting CXXFLAGS in one module affects another one
in dirA/SConscript I have: Import('env') probeenv = env.Clone() probeenv['CXXFLAGS'] += ['-fno-rtti','-Wnon-virtual-dtor'] ... stuff that uses probeenv in dirB/SConscript I have Import('env') sipenv = env.Clone() ... stuff that uses sipenv Now, c++ files in dirB that gets compiled, gets the CXXFLAGS from dirA - how ...
This seems to be a scons bug if CXXFLAGS is not set in "main" SConstruct. The workaround is to simply set it to an empty list there. SConscript: env['CXXFLAGS'] = []
2,275,905
2,275,933
Move C++ app with Boost from Linux to Windows with Visual Studio 6
I made a small program with Boost in Linux 2 yrs ago. Now I want to make it work in Windows. I found there are few .a files in my libs folder. I am wondering how to make it works in Windows? do I need to build Boost in Windows to get library or I can download somewhere? I am using Visual Studio 6.
Yes, you'll need to recompile for different platforms. Coincidentally, I posted instructions on this not long ago. I hugely recommend you do not use Visual Studio 6. It's very dated, and terribly non-conforming. You can get the newer versions for free, as Express. You won't be missing anything.
2,276,007
2,276,048
Which IDE for C++ software can I use for targeting Windows, Linux and OSX?
I was reading today question on IDEs fo C++, and there are very good ones like Netbeans. My question is about creating a software in C++ on Windows Environment, but let users install and run my software also on Linux and OSX. Does netbeans has a compiler to do the job, or is there any good IDE which has a compiler for...
QtCreator. It's awesome, slick and everything. While it is not as feature rich as some competitors, it does many things just right that others don't. I would say it is the one truly cross-platform IDE that is competitive to single-platform solutions. And it comes with tight integration of a very powerful and clean cros...
2,276,325
2,276,452
Prevent memory fragmentation
Can anyone point me to a source or outline how the algorithm for the low-fragmentation heap works?
First decide which 'multiples' you want to use for the allocated memory chunks. I typically use 8 bytes. At startup of the application, make a vector where each element in the vector points to a 'pool' of memory chunks. The first index in the vector will be for memory allocations of 8 bytes or less. The second index...
2,276,329
2,276,409
Why can one specify the size of an array in a function parameter?
I don't understand why the following example compiles and works: void printValues(int nums[3], int length) { for(int i = 0; i < length; i++) std::cout << nums[i] << " "; std::cout << '\n'; } It seems that the size of 3 is completely ignored but putting an invalid size results in a compile error. What ...
In C++ (as well as in C), parameters declared with array type always immediately decay to pointer type. The following three declarations are equivalent void printValues(int nums[3], int length); void printValues(int nums[], int length); void printValues(int *nums, int length); I.e. the size does not matter. Yet, it st...
2,276,481
2,276,514
Error loading type library/DLL
When I use the following code I get an compilation error #import <dwmapi.lib> #include <dwmapi.h> I get the following error: fatal error C1083: Cannot open type library file: 'c:\program files\microsoft sdks\windows\v7.0a\lib\dwmapi.lib': Error loading type library/DLL. Intellisense says: 2 IntelliSense: ca...
dwmapi .lib is a type library? YOu sure its not just a plain old dll. A com lib is either .DLL or .tlb. I think its a plain old dll. So you dont #import it you need instead #pragma comment(lib,"dwmapi.lib")
2,276,725
2,276,988
Reading file with cyrillic
I have to open file with cyrillic symbols. I've encoded file into utf8. Here is example: en: Couldn't your family afford a costume for you   ru: Не ваша семья позволить себе костюм для вас How do I open file: ifstream readFile(fileData.c_str()); while (!readFile.eof()) { std::getline(readFile, buffer); ... ...
there is some symbol before text 'en' That's a faux-BOM, the result of encoding a U+FEFF BYTE ORDER MARK character into UTF-8. Since UTF-8 is an encoding that does not have a byte order, the faux-BOM shouldn't ever be used, but unfortunately quite a bit of existing software (especially in the MS world) does nonethele...
2,276,797
2,336,704
gdb Input/Output error remote debugging to Android
I'm trying to debug an android app that call native code to do some GL rendering. The native code is existing code that I'm trying to port (and that I don't really know that well). I've got the existing code compiling, linking, and installing correctly, and I've got some native functions that call in to that code tha...
Essentially, at this point with NDK 1.6, I've found that there just isn't support for this kind of debugging strictly with the NDK. However, if you use the PDK (platform development kit), you can do this kind of debugging with native code. We haven't tried the PDK, because generating a map file worked well enough for...