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 |
|---|---|---|---|---|
1,976,598 | 1,976,647 | Template Return Types / Cast as function of Template | I'm working with some generated classes with broken polymorphism. For every generated class T, there are a handful of T_type_info, T_writer, T_reader classes which are only related to T conceptually.
What I'm trying to do is something like this:
template <class T> class Wrapper
{
public:
template <class W> W topic... | Could this not be achieved with a traits system?
template <typename T> struct my_traits
{
};
template <> struct my_traits<MyClass>
{
typedef MyWriter writer_type;
};
template <typename T> struct Wrapper
{
typename my_traits<T>::writer_type topic_cast();
};
|
1,976,719 | 1,977,185 | learning c++ on linux mint ( for .net developer ) | My goal is to hop on to C++ programming language by doing a homework project on linux mint and learn some linux & c++ at the same time.
I intend to write a small desktop application to show current network traffic ( like DU meter in windows). I have following questions:
I noticed in mint there is an application called... | The mint distribution is based on Ubuntu/Debian, so I assume that my Ubuntu approach also works on mint.
First
you need some tools, libraries and headers:
# install the standard toolchain (g++, make, etc.)
sudo aptitude install build-essential
# install the build dependencies for a desktop based networking tool
sudo a... |
1,976,850 | 1,976,921 | 3d max integration with c++, Cal3D where to start? | okay i'm making a game using c++ (for the engine) and openGL, now i've had lots of trouble using cal3d library for importing my 3d max models into my c++ project,
as a matter of fact i dunno where to even start, i can't find any decent guide and their documentation is pure shit really. i've been searching and trying st... | Rather than write your own exporter, consider using one of the built-in exporters for FBX, COLLADA, Crosswalk (.XSI), the Quake/Doom3 .MD3/.MD4 format, or even OBJ. It'll be much easier to parse the resulting file format on your end than to write and maintain a brand-new exporter.
|
1,976,867 | 1,977,094 | Starting a program fails with error code 1 | I made an application and a dll, which are working this way:
I have to register the dll. After registering the dll if i right click on an .exe file, the pop-up menu appears, and i have inserted into this menu one line ("Start MyApp"), and if i click there, it should start MyApp. MyApp has one parameter which is the ful... | As others have said, your problem is here:
file_exists( "RunAs.ini" );
readfile( "RunAs.ini" );
Neither of the function calls provides a path. You're expecting the current working directory to be the folder where your application is located, but it doesn't have to be (in fact, you should never assume that it is). Th... |
1,976,983 | 1,977,006 | Why won't my C++ program link when my class has static members? | I have a little class called Stuff that I want to store things in. These things are a list of type int. Throughout my code in whatever classes I use I want to be able to access these things inside the Stuff class.
Main.cpp:
#include "Stuff.h"
int main()
{
Stuff::things.push_back(123);
return 0;
}
Stuff.h:
#... | Mentioning a static member in a class declaration is a declaration only. You must include one definition of the static member for the linker to hook everything up properly. Normally you would include something like the following in a Stuff.cpp file:
#include "Stuff.h"
list<int> Stuff::things;
Be sure to include Stuff... |
1,977,174 | 1,977,236 | C++ library to interface .dmg files on Mac | I want to write a C++ program that spawns off a thread to execute a .dmg file and monitor its completion (success/fail) on Snow Leopard. Would this be as trivial as fork/exec a shell script on Linux? Would I need a 3rd party C++ library to interface .dmg files?
| A .dmg file on OS X is a container for an image of a volume or single file system so it's not clear what you mean by execute a .dmg file. If you mean mount the file systems contained in the .dmg file, the easiest way to do that is with the hdiutil command:
hdiutil attach /path/to/file.dmg
If you need to parse the inf... |
1,977,212 | 1,977,974 | Asynchronous request using wininet | I have already used wininet to send some synchronous HTTP requests. Now, I want to go one step further and want to request some content asynchronously.
The goal is to get something "reverse proxy"-like. I send an HTTP request which gets answered delayed - as soon as someone wants to contact me. My thread should contin... |
My thread should continue as if there
was nothing in the meanwhile, and a
callback should be called in this
thread as soon as the response
arrives.
What you're asking for here is basically COME FROM (as opposed to GO TO). This is a mythical instruction which doesn't really exist. The only way you can get yo... |
1,977,339 | 1,977,633 | C++ range/xrange equivalent in STL or boost? | Is there C++ equivalent for python Xrange generator in either STL or boost?
xrange basically generates incremented number with each call to ++ operator.
the constructor is like this:
xrange(first, last, increment)
was hoping to do something like this using boost for each:
foreach(int i, xrange(N))
I. am aware of the ... | Boost has counting_iterator as far as I know, which seems to allow only incrementing in steps of 1. For full xrange functionality you might need to implement a similar iterator yourself.
All in all it could look like this (edit: added an iterator for the third overload of xrange, to play around with boost's iterator fa... |
1,977,486 | 1,977,681 | changing value in a stl map in place | I understand that when we insert values into the STL map, a copy is made and stored.
I have code that essentially does a find on the map and obtains an iterator.
I then intend to use the iterator to change the value in the map.
The results are not what I would expect ie: the value is not changed when accessed from anot... | Hmm... both methods seem to work fine for me. Here's the entire example that I used:
#include <iostream>
#include <map>
#include <string>
#include <boost/tuple/tuple.hpp>
typedef boost::tuple<int, std::string> value_type;
typedef std::map<int, value_type> map_type;
std::ostream&
operator<<(std::ostream& os, value_ty... |
1,977,576 | 1,977,612 | Efficiently finding multiple items in a container | I need to find a number of objects from a large container.
The only way I can think of to do that seems to be to just search the container for one item at a time in a loop, however, even which an efficient search with an average case of say "log n" (where n is the size of the container), this gives me "m log n" (where ... | Hash tables have basically O(1) lookup. This gives you O(m) to lookup m items; obviously you can't lookup m items faster than O(m) because you need to get the result out.
|
1,977,737 | 1,977,866 | OpenGL Rotations around World Origin when they should be around Local Origin | I'm implementing a simple camera system in OpenGL. I set up gluPerspective under the projection matrix and then use gluLookAt on the ModelView matrix. After this I have my main render loop which checks for keyboard events and, if any of the arrow keys are pressed, modifies angular and forward speeds (I only rotate thro... | glRotate() rotates the ModelView Matrix around the World Origin, so to rotate around some arbitrary point, you need to translate your matrix to have that point at the origin, rotate and then translate back to where you started.
I think what you need is this
float x, y, z;//point you want to rotate around
glTranslatef... |
1,977,742 | 1,977,885 | Inter-thread communication. How to send a signal to another thread | In my application I have two threads
a "main thread" which is busy most of the time
an "additional thread" which sends out some HTTP request and which blocks until it gets a response.
However, the HTTP response can only be handled by the main thread, since it relies on it's thread-local-storage and on non-threadsafe ... | This may be one of those times where one works themselves into a very specific idea without reconsidering the bigger picture. There is no singular mechanism by which a single thread can stop executing in its current context, go do something else, and resume execution at the exact line from which it broke away. If it we... |
1,977,783 | 1,977,798 | Link a member function directly to C method declared in a header | Can I link a member function like this in some way?
redeclaring the method as a member and get it call the Mmsystem.h method to not have to wrap it?
#include <windows.h>
#include <Mmsystem.h>
namespace SoundLib {
public class CWave
{
public:
// WaveIn call
external UINT waveOutGetNumDevs(VOID);
};
}
| No, you have to wrap it. Additionally, your code has some errors, such as external versus extern (though that was theoretical anyway) and public before your class.
|
1,977,917 | 1,979,921 | How to convert DirectShow Filter to C++\C#? | We have some filter for DS. It works - uses standard win dll's.
We want to convert that filter to some sort of program that doesn't rely on using DS. We want it to call dlls in the right order, do all what DS is doing but not be in any way dependable on DS - only on filter dll's.
So... How to convert DirectShow Filter ... | A better solution is to use the filter within a single-purpose graph, in which you have a custom source feeding the filter from the app, and a custom sink receiving the output and delivering it to the app. There's an example of this on www.gdcl.co.uk. I know this isn't quite what you are asking for, but your dependenci... |
1,978,297 | 1,978,761 | Qt, Signals without naming? | Is there any way to use the signals without MOC and without the connecting via names? My one problem with Qt is that you have something like
this->connect(this->SaveBtn, SIGNAL(click()), SLOT(SaveClicked()));
And there is no error detection to tell that is wrong other then finding out the button doesn't work or searchi... | There is error detection, the connect function returns false when it fails to connect, and a warning is output on standard error (or, on Windows, to the weird place which DebugView reads from). Also you can make these warnings into fatal errors by setting QT_FATAL_WARNINGS=1 in your environment.
It's not pointless to ... |
1,978,709 | 1,978,859 | Are memory leaks "undefined behavior" class problem in C++? | Turns out many innocently looking things are undefined behavior in C++. For example, once a non-null pointer has been delete'd even printing out that pointer value is undefined behavior.
Now memory leaks are definitely bad. But what class situation are they - defined, undefined or what other class of behavior?
| Memory leaks.
There is no undefined behavior. It is perfectly legal to leak memory.
Undefined behavior: is actions the standard specifically does not want to define and leaves upto the implementation so that it is flexible to perform certain types of optimizations without breaking the standard.
Memory management is wel... |
1,978,754 | 1,979,161 | What's a good convex optimization library? | I am looking for a C++ library, and I am dealing with convex objective and constraint functions.
| I am guessing your problem is non-linear. Where i work, we use SNOPT, Ipopt and another proprietary solver (not for sale). We have also tried and heard good things about Knitro.
As long as your problem is convex, all these solvers work well.
They all have their own API, but they all ask for the same information : value... |
1,978,883 | 1,988,213 | How to use SDL with OGRE? | When I go to use OGRE with SDL (as described in this article), I seem to be having trouble with a second window that appears behind my main render window. Basically, the code I'm using is this:
SDL_init(SDL_INIT_VIDEO);
SDL_Surface *screen = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
Ogre::Root *root = new Ogre::Root... | I ended up figuring this out on my own. The problem ends up being that OGRE's Mac GL backend does not honor the currentGLContext option, so the best solution is to change to SDL 1.3 (directly from Subversion, as of time of writing) and use the SDL_CreateWindowFrom call to start getting events from a window created by ... |
1,978,967 | 1,979,720 | How to get Python code to work with C++ App? | I have the following python 3 file:
import base64
import xxx
str = xxx.GetString()
str2 = base64.b64encode(str.encode())
str3 = str2.decode()
print str3
xxx is a module exported by some C++ code. This script does not work because calling Py_InitModule on this script returns NULL. The weird thing is if I create a stub... | Py_InitModule() is for initializing extension modules written in C, which is not what you are looking for here. If you want to import a module from C, there is a wealth of functions available in the C API: http://docs.python.org/c-api/import.html
But if your aim is really to run a script rather than import a module, yo... |
1,978,975 | 1,981,071 | How to solve a problem in using RAII code and non-RAII code together in C++? | We have 3 different libraries, each developed by a different developer, and each was (presumably) well designed. But since some of the libraries are using RAII and some don't, and some of the libraries are loaded dynamically, and the others aren't - it doesn't work.
Each of the developers is saying that what he is doin... | At first this looks like a problem of dueling APIs, but really it's just another static destructor problem.
Generally it's best to avoid doing anything nontrivial from a global or static destructor, for the reason you've discovered but also for other reasons.
In particular: On Windows, destructors for global and static... |
1,979,335 | 1,979,349 | Calculating the balance factor of a node in avl tree | I want to calculate the balance factor of a node in avl tree without using any recursive procedure. How can i do that? Please tell me method or provide C++ code snippet.
| You can save the balance factor as a part of the information each node saves.
Specifically, you can save the height of the left and right subtrees, and update the values with every insertion/deletion on the insertion/deletion path.
Example:
class Node {
public:
// stuff...
int GetBF() { return lHeight - rHeig... |
1,979,989 | 1,980,011 | Is using "operator &" on a reference a portable C++ construct? | Suppose I have:
void function1( Type* object ); //whatever implementation
void function2( Type& object )
{
function1( &object );
}
supposing Type doesn't have an overloaded operator &() will this construct - using operator & on a reference - obtain the actual address of the object (variable of Type type) on all de... | Yes, and the reason is that on the very beginning of evaluating any expression, references are being replaced by the object that's referenced, as defined at 5[expr]/6 in the Standard. That will make it so the &-operator doesn't see any difference:
If an expression initially has the type "reference to T" (8.3.2, 8.5.3)... |
1,980,145 | 1,981,590 | Callback, specified in QueueUserAPC , does not get called | In my code, I use QueueUserAPC to interrupt the main thread from his current work in order to invoke some callback first before going back to his previous work.
std::string buffer;
std::tr1::shared_ptr<void> hMainThread;
VOID CALLBACK myCallback (ULONG_PTR dwParam) {
FILE * f = fopen("somefile", "a");
fprintf(f... | Yeah, QueueUserAPC is not the solution here. Its callback will only run when the thread blocks and the programmer has explicitly allowed the wait to be alertable. That's unlikely.
I hesitate to post the solution because it is going to get you into enormous trouble. You can implement a thread interrupt with SuspendTh... |
1,980,326 | 1,982,329 | A way to do c++ "typedef struct foo foo;" for c | Going by gcc version 4.4.2, it appears that saying
typedef struct foo foo;
// more code here - like function declarations taking/returning foo*
// then, in its own source file:
typedef struct foo
{
int bar;
} foo;
is legal in C++ but not in C.
Of course I have a body of code that compiles fine in C++ by using the ... | One of the differences between C++ and C is that in C++ it is legal to make a repetitive typedef in the same scope as long as all these typedef are equivalent. In C repetitive typedef is illegal.
typedef int TInt;
typedef int TInt; /* OK in C++. Error in C */
This is what you have in your above code. If you are trying... |
1,980,571 | 1,980,687 | How could I refactor this code with performance in mind? | I have a method where performance is really important (I know premature optimization is the root of all evil. I know I should and I did profile my code. In this application every tenth of a second I save is a big win.) This method uses different heuristics to generate and return elements. The heuristics are used sequen... | To my mind if you do not need to modify this code much, eg to add new heuristics then document it well and don't touch it.
However if new heuristics are added and removed and you think that this is an error prone process then you should consider refactoring it. The obvious choice for this would be to introduce the Sta... |
1,980,642 | 1,980,908 | Static template field of template class? | I've got this code to port from windows to linux.
template<class T, int Size>
class CVector {
/* ... */
};
template<int n, int m>
class CTestClass {
public:
enum { Size = 1 << n };
private:
static CVector<int, Size> a; // main.cpp:19
};
template<int n, int m>
CVector<int, CTestClass<n, m>::Size> CTestClass<n, m>:... | This works with gcc 3.4 & 4.3 as well as VC8:
template<class T, int Size>
class CVector {
/* ... */
};
template<int n, int m>
class CTestClass {
public:
enum { Size = 1 << n };
typedef CVector<int, Size> Vector;
private:
static Vector a;
};
template<int n, int m>
typename CTestClass<n,m>::Vector CTestC... |
1,980,761 | 1,980,878 | Why is this error: reference to ‘statusBar’ is ambiguous.. coming? Is this a bug? | I created a QMainWindow using QT Designer.
As we know, it has statusBar by default.
By default, QT Designer gave its objectname as "statusBar".
Now, when I tried to call like:-
statusBar()->showMessage(tr("File successfully loaded."), 3000);
as we have a function with prototype: QStatusBar * QMainWindow::statusBar () ... | Ask for a specific version of the method statusBar():
Ui_MainWindow::statusBar()->showMessage(tr("File successfully loaded."), 3000);
|
1,981,286 | 1,983,054 | How to check if file is/isn't an image without loading full file? Is there an image header-reading library? | edit:
Sorry, I guess my question was vague. I'd like to have a way to check if a file is not an image without wasting time loading the whole image, because then I can do the rest of the loading later. I don't want to just check the file extension.
The application just views the images. By 'checking the validity', I mea... | The Unix file tool (which has been around since almost forever) does exactly this. It is a simple tool that uses a database of known file headers and binary signatures to identify the type of the file (and potentially extract some simple information).
The database is a simple text file (which gets compiled for efficie... |
1,981,400 | 1,981,416 | Functional Programming in C++ | Can someone guide me how do functional programming in C++? Is there some good online material that I can refer?
Please note that I know about the library FC++. I want to know how to do that with C++ standard library alone.
Thanks.
| Update August 2014: This answer was posted in 2009. C++11 improved matters considerably for functional programming in C++, so this answer is no longer accurate. I'm leaving it below for a historical record.
Since this answer stuck as the accepted one - I'm turning it into a community Wiki. Feel free to collaboratively ... |
1,981,413 | 1,982,338 | Why is typeid not compile-time constant like sizeof | Why is typeid(someType) not constant like sizeof(someType) ?
This question came up because recently i tried something like:
template <class T>
class Foo
{
static_assert(typeid(T)==typeid(Bar) || typeid(T)==typeid(FooBar));
};
And i am curious why the compiler knows the size of types (sizeof) at compile time, but n... | When you are dealing with types, you'd rather use simple metaprogramming techniques:
#include <type_traits>
template <class T>
void Foo()
{
static_assert((std::is_same<T, int>::value || std::is_same<T, double>::value));
}
int main()
{
Foo<int>();
Foo<float>();
}
where is_same could be implemented like th... |
1,981,568 | 1,981,587 | memset, memcpy with new operator | Can I reliably use memset and memcpy operators in C++ with memory been allocated with new?
Edited:
Yes, to allocate native data type
Example
BYTE *buffer = 0;
DWORD bufferSize = _fat.GetSectorSize();
buffer = new BYTE[bufferSize];
_fat.ReadSector(streamChain[0], buffer, bufferSize);
ULONG header = 0;
memcpy(&header, ... | So long as you are only using new to allocate the built-in and/or POD types, then yes. However, with something like this:
std::string * s = new string;
memset( s, 0, sizeof(*s) );
then you would be looking at disaster.
I have to ask though, why you and others seem so enamoured with these functions - I don't believe I ... |
1,981,576 | 1,981,957 | Convert Hex Char To Int - Is there a better way? | I have written a function to take in the data from a Sirit IDentity MaX AVI reader and parse out the facility code and keycard number. How I am currently doing it works, but is there a better way? Seems little hackish... buff & buf are size 264
buf and buff are char
Data received from reader:
2009/12/30 14:56:18 epc0... | Here's an easy way to get at the data you want. I do work in the access control business so this was something that interested me...
template<typename TRet, typename Iterator>
TRet ConvertHex(Iterator begin) {
unsigned long result;
Iterator end = begin + (sizeof(TRet) * 2);
std::stringstream ss(std::string... |
1,981,628 | 1,981,629 | Check if a binary number has a '0' or a '1' at a specific position | I'd like to check if a binary number has a '0' or a '1' at a specific position.
example:
if the binary number is: 101000100
checking at position zero (that is at
the rightmost '0') should result in
'0'.
checking at position 2 should result
in '1'.
checking at position 3 should result
in '0'.
checking at position 6 sho... | This will filter out the bit you're looking for:
number & (1 << position)
If you really need a 1 or 0 response, you can use this to make it a boolean value:
!!(number & (1 << position))
Or even better (thanks Vadim K.):
(number >> position) & 1
|
1,981,723 | 1,981,746 | Unix socket: hostent makes memory leaks | I am writing client for TCP connection and conversion from IP to socket_addr makes memory leaks.
There is following process:
#include <netdb.h>
#include <sys/socket.h>
#include <sys/types.h>
/** there is some code like method header etc. */
hostent * host = gethostbyaddr( ip, 4, AF_INET ); // ip is char[4], I use IPv... | You don't say what platform you are on, but typically the memory returned by gethostbyaddr will be allocated and managed by the sockets library you are using - you don't free it yourself. Whatever you are using to diagnose leaks is probably giveing false positives.
For example, this man page http://www.opengroup.org/on... |
1,981,804 | 1,981,918 | Can getline() be used to get a char array from a fstream | I want to add a new (fstream) function in a program that already uses char arrays to process strings.
The problem is that the below code yields strings, and the only way i can think of getting this to work would be to have an intermediary function that would copy the strings, char by char, into a new char array, pass t... | You can pass a string as the first parameter to translateWord by making the first parameter a const char *. Then you call the function with inputStr.c_str() as the first parameter. Do deal with the second (output) parameter though, you need to either completely re-write translateWord to use std::string (the best soluti... |
1,982,131 | 1,983,382 | Is Loop Hoisting still a valid manual optimization for C code? | Using the latest gcc compiler, do I still have to think about these types of manual loop optimizations, or will the compiler take care of them for me well enough?
| If your profiler tells you there is a problem with a loop, and only then, a thing to watch out for is a memory reference in the loop which you know is invariant across the loop but the compiler does not. Here's a contrived example, bubbling an element out to the end of an array:
for ( ; i < a->length - 1; i++)
swa... |
1,982,178 | 1,983,183 | Intel C++ compiler as an alternative to Microsoft's? | Is anyone here using the Intel C++ compiler instead of Microsoft's Visual c++ compiler?
I would be very interested to hear your experience about integration, performance and build times.
| The Intel compiler is one of the most advanced C++ compiler available, it has a number of advantages over for instance the Microsoft Visual C++ compiler, and one major drawback. The advantages include:
Very good SIMD support, as far as I've been able to find out, it is the compiler that has the best support for SIMD i... |
1,982,508 | 1,982,545 | C# and C++ in relation to C | I've never programmed using C or whatever but I use this site a lot so as you can imagine I run into them quite a lot. And due to the fact I don't really understand the languages this is a question Google can't really answer.
So in simple terms what are the differences between each of these languages. I assume they are... | They're loosely related in terms of syntax.
In general, C++ added a huge number of capabilities to C, mostly object orientation and generic programming constructs. However, it did so in a way to try to maintain as much backwards compatibility with C as possible.
C#, on the other hand, is a very different animal. It c... |
1,982,595 | 1,982,675 | boost asio io_service.run() | I was just going over the asio chat server example. My question is about their usage of the io_service.run() function. The documentation for the io_service.run() function says:
The run() function blocks until all work has finished and there are no
more handlers to be dispatched, or until the io_service has been
s... | "until all work has finished and there are no more handlers to be dispatched, or until the io_service has been stopped"
Notice that you DO install a handler, named handle_accept, that reinstalls itself at each execution. Hence, the io_service.run will never return, at least until you quit it manually.
Basically, at the... |
1,982,743 | 1,982,761 | C++: Get data from MIDI message (DWORD) | I've written a simple MIDI console application in C++. Here's the whole thing:
#include <windows.h>
#include <iostream>
#include <math.h>
using namespace std;
void CALLBACK midiInputCallback(HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) {
switch (wMsg) {
case MIM_MOREDATA:... | To access the data you need to use dwParam1 and dwParam2 and call the macros HIWORD and LOWORD to get the high and low word from them. Respectively use HIBYTE and LOBYTE to get the data out of those words. In case of MIM_DATA, unfortunately that's byte encoded MIDI data, so you'll have to find the specific meanings for... |
1,982,788 | 1,982,873 | writing pexpect like program in c++ on Linux | Is there any way of writing pexpect like small program which can launch a process and pass the password to that process?
I don't want to install and use pexpect python library but want to know the logic behind it so that using linux system apis I can build something similar.
| You could just use "expect". It is very light weight and is made to do what youre describing.
|
1,982,986 | 1,983,410 | Scrolling different Widgets at the same time | I have different types of QWidgets into a DockWindow:
1 Qwt plot
1 QWidget
3 QGraphicsView
And I need scrolling all of them at the same time with the same scrollbar when I zoom in. I know two solutions for this:
Create one scrollbar and connect it to each widget.
Create one scrollArea and manipulate all the widgets.... | I would try to make it so that each of the items that needs to scroll in concert is inside its own QScrollArea. I would then put all those widgets into one widget, with a QScrollBar underneath (and/or to the side, if needed).
Designate one of the interior scrolled widget as the "master", probably the plot widget. Th... |
1,983,141 | 1,983,298 | Problem in setting up boost library on ubuntu | I have compiled and installed my boost library in '/media/data/bin' in ubuntu 9.10.
And I have setup the INCLUDE_PATH, LIBRARY_PATH env:
$ echo $INCLUDE_PATH
/media/data/bin/boost/include:
$ echo $LIBRARY_PATH
/media/data/bin/boost/lib:
But when I compile the asio example, I get the following error:
$ g++ blocking_tcp... | What is wrong with
sudo apt-get install libboost-dev
after which you don't need to set any -I and -L flags. If you need Boost 1.40, you can still rebuild the current Debian unstable package.
|
1,983,303 | 1,983,525 | Using bts assembly instruction with gcc compiler | I want to use the bts and bt x86 assembly instructions to speed up bit operations in my C++ code on the Mac. On Windows, the _bittestandset and _bittest intrinsics work well, and provide significant performance gains. On the Mac, the gcc compiler doesn't seem to support those, so I'm trying to do it directly in assembl... | inline void SetBit(*array, bit) {
asm("bts %1,%0" : "+m" (*array) : "r" (bit));
}
|
1,983,639 | 1,983,663 | Linking Error When Implementing Templated Based Operator Assignment Function | I try to implement the following function :
template<typename T>
class a
{
private:
T var;
friend bool operator==(const a<T> &, const a<T> &);
};
template<typename T> inline bool operator==(const a<T> &r1, const a<T> &r2)
{
return r1.var==r2.var;
}
int main () {
a<int> var0;
a<int> var1;
var0 ... | What you have declares the friend op== as a non-template, but you implement it as a template. That is why the definition is not found when linking.
How I usually overload op== for class templates:
template<class T>
struct A {
friend bool operator==(A const& a, A const& b) {
return a.var == b.var;
}
private:
... |
1,984,295 | 1,984,635 | setCentralWidget() causing the QMainWindow to crash.. Why? | MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
this->setupUi(this);
this->setupActions();
this->setWindowTitle(tr("CuteEdit"));
label = new QLabel(tr("No Open Files"));
this->setCentralWidget(label);
label->setAlignment(Qt::AlignCenter);
}
By above code,... | JimDaniel is right in his last edit. Take a look at the source code of setCentralWidget():
void QMainWindow::setCentralWidget(QWidget *widget)
{
Q_D(QMainWindow);
if (d->layout->centralWidget() && d->layout->centralWidget() != widget) {
d->layout->centralWidget()->hide();
d->layout->centralWidget()->deleteL... |
1,984,492 | 1,984,596 | runtime determine type for C++ | I am wondering if type can be determined as runtime information in C++.
(1) Although my question is quite general, for simplicity, I will start from a simple example:
#include <stdio.h>
#include <iostream>
#include <cstring>
using namespace std;
int main(int argc, char * argv[])
{
if (strcmp(argv[1]... | 1a: No, types are not objects or values in C++ (as they are, for example, in Python). You can, however, use various values selected by the value of argv[1].
1b: Sorry, just can't do that.
2: dynamic_cast and typeid (both operators) are the only tools currently provided by the language to query type (not unusual, most ... |
1,984,657 | 1,984,736 | how to know whether disk is basic or dynamic? | In windows is it possible to know what kind of disk we are dealing with from a c/c++ program? forget about gpt or mbr, how to know whether it is basic or dynamic? Program input can be drive letter or any info related to disk, output should be dynamic or basic.
No need of a direct way of doing, even if it is lengthy pro... | There is a way in windows, but it's not straight forward.
There is no direct API to determine if a disk is Basic or Dynamic, however all dynamic disks will have LDM Information.
So if a drive has a partion with LDM information on it, then it's going to be a dynamic disk.
the DeviceIoControl() method with the IOCTL_DISK... |
1,984,877 | 2,211,539 | Profiling C++ with Xcode | is it possible to profile C++ apps with Xcode so one gets;
memory leaks like with valgrind
possible errors before running the program
Thanks, I am very new to mac and xcode
Where can one find a good tutorial for this?
| Regarding memory leaks, run XCode and then launch Start with Performance Tool -> Leaks
Alternatively and necessarily for old pre-Panther users of XCode, it is possible to debug with guard malloc, detailed explanation in the Mac development docs, but here is a quick walk-through.
|
1,985,157 | 1,985,226 | Issue writing to Excel file using C++ | We have a requirement to parse a file and write the data to an excel file using C++. I did a search and able to find a project which serves my purpose. http://www.codeproject.com/KB/office/ExcelFormat.aspx
Please find a few lines of code below where exactly the errors occur.
typedef std::ctype CT;
CT const& ct = std... | It is difficult to answer without further information. In any case I would try
CT const & ct = std::use_facet<CT>( std::locale() );
|
1,985,521 | 1,985,529 | Explaining the declaration/definition of HRESULT | I just looked at the definition of HRESULT in VS2008. WinNT.h has the following line:
typedef __success(return >= 0) long HRESULT;
What exactly does it mean? It doesn't even look like C or C++ to my untrained eye
| It is an annotation. In short,
__success(expr)
means that expr describes the conditions under which a function is considered to have succeeded. For functions returning HRESULT, that condition is that the return value (since HRESULT is a long) is non-negative. All functions returning HRESULT have this annotation applie... |
1,985,705 | 1,985,918 | Need help on asynchrous non-blocking file loading with boost::asio and boost::iostreams ( or something different? ) | I'm coding in c++, and I'm trying to load an image file asynchronously. After some research, I found some mentions about using boost::asio and boost::iostreams to do it. However, the documentation and example for boost::asio is mostly socket related, so it doesn't help me much.
Here is what I need:
Load a file asynchr... | You can do what you want with a little more scaffolding, but in order for the callback to be executed on your main thread, the main thread must be waiting on something which signals that the callback is ready. Here's one way to do it. I'm assuming that your main thread already has some form of execution loop.
Add a t... |
1,985,881 | 1,985,960 | How to install and use libtool shared library (.lo files)? | So after I ran libtool and got out a libfoo.lo and foo.o file from my library source, how do I convert the libfoo.lo file into a normal Linux shared library, like libfoo.so.1.0.0 so I can install and link to it on my target system?
| From the outputs mentioned in the question, it looks like you ran libtool with --mode=compile mode. You will need to run libtool again with --mode=link to produce .a and .so libraries.
libtool is just a simple wrapper for gcc, ln ar and ranlib which is needed to produce libraries. All it does is run gcc adding the nece... |
1,985,978 | 1,986,048 | Combining a vector of strings | I've been reading Accelerated C++ and I have to say it's an interesting book.
In chapter 6, I have to use a function from <algorithm> to concatenate from a vector<string> into a single string. I could use accumulate, but it doesn't help because string containers can only push_back characters.
int main () {
using na... | Assuming this is question 6.8, it doesn't say you have to use accumulate - it says use "a library algorithm". However, you can use accumulate:
#include <numeric>
int main () {
std::string str = "Hello World!";
std::vector<std::string> vec(10,str);
std::string a = std::accumulate(vec.begin(), vec.end(),... |
1,986,199 | 1,986,369 | Change string locale | I'm not very familiar with locale-specific conversions so I may be using the wrong terminology here. This is what I want to have happen.
I want to write a function
std::string changeLocale( const std::string& str, const std::locale& loc )
such that if I call this function as follows:
changeLocale( std::string( "1.01"... | Something like this ought to do the trick
#include <iostream>
#include <sstream>
#include <locale>
int main (int argc,char** argv) {
std::stringstream ss;
ss.imbue(std::locale("fr_FR.UTF8"));
double value = 1.01;
ss << value;
std::cout << ss.str() << std::endl;
return 0;
}
Sho... |
1,986,325 | 1,990,104 | Operator overloading for a class containing boost::numeric::ublas::matrix<double> | I have a class which contains a few boost::numeric::ublas::matrix's within it. I would like to overload the class's operators (+-*/=) so that I can act on the set of matrices with one statement.
However this seems to require temporary instances of my class to carry values around without modifying the original class.... | If you're using boost already, I'd strongly suggest using boost::operators along with your example.
You'll get several benefits:
You'll only need to overload the +=/-=/= operators, and get the +/-/ operators for free.
You'll have a optimal implementation of the freely implemented operators.
You'll get rid of the probl... |
1,986,418 | 1,986,485 | 'typeid' versus 'typeof' in C++ | I am wondering what the difference is between typeid and typeof in C++. Here's what I know:
typeid is mentioned in the documentation for type_info which is defined in the C++ header file typeinfo.
typeof is defined in the GCC extension for C and in the C++ Boost library.
Also, here is test code test that I've create... | C++ language has no such thing as typeof. You must be looking at some compiler-specific extension. If you are talking about GCC's typeof, then a similar feature is present in C++11 through the keyword decltype. Again, C++ has no such typeof keyword.
typeid is a C++ language operator which returns type identification in... |
1,986,424 | 1,986,783 | Continue C++ project in VB.Net? | I was given a half-finished project to finish. It was written in C++ using Visual Studio 2005.
Is it possible to somehow continue the project in VB.Net? If it is, can you guide me?
Thanks
| If the app isn't done, then I don't recommend trying to do the "rest" in VB unless there's a reasonable segmentation of the existing and new code such that you could turn the existing C++ stuff into a library to be used by the VB code. But only if it makes any kind of sense (think encapsulation here -- is the code sui... |
1,986,641 | 1,987,792 | Why is it important for C / C++ Code to be compilable on different compilers? | I'm
interested in different aspects of portability (as you can see when browsing my other questions), so I read a lot about it. Quite often, I read/hear that Code should be written in a way that makes it compilable on different compilers.
Without any real life experience with gcc / g++, it seems to me that it supports... | For most languages I care less about portability and more about conforming to international standards or accepted language definitions, from which properties portability is likely to follow. For C, however, portability is a useful idea, because it is very hard to write a program that is "strictly conforming" to the st... |
1,986,660 | 1,986,684 | C++ length of file and vectors | Hi I have a file with some text in it. Is there some easy way to get the number of lines in the file without traversing through the file?
I also need to put the lines of the file into a vector. I am new to C++ but I think vector is like ArrayList in java so I wanted to use a vector and insert things into it. So how wou... | You would need to traverse the file to detect the number of lines (or at least call a library method that traverse the file).
Here is a sample code for parsing text file, assuming that you pass the file name as an argument, by using the getline method:
#include <string>
#include <vector>
#include <fstream>
#include <io... |
1,986,918 | 1,986,963 | Why don't we have <cstdfloat> in C++? | Why doesn't C++ have <cstdfloat> header for floats like it has <cstdint> for integers?
EDIT :
By <cstdfloat> I mean header that provides typedefs for float and double. Much like qreal typedef in Qt. Hope my question is clear now.
| Often an application needs exactly 16 bits for an integer for, say, a bitfield, but having exactly 16 bits for a float is kind of useless. Manipulating bits in an integer is easy, so having exactly 16 is nice. Manipulating bits in a float requires casting it to an integer, making a float16 type rather extraneous.
By th... |
1,986,966 | 1,986,974 | Does "&s[0]" point to contiguous characters in a std::string? | I'm doing some maintenance work and ran across something like the following:
std::string s;
s.resize( strLength );
// strLength is a size_t with the length of a C string in it.
memcpy( &s[0], str, strLength );
I know using &s[0] would be safe if it was a std::vector, but is this a safe use of std::string?
| A std::string's allocation is not guaranteed to be contiguous under the C++98/03 standard, but C++11 forces it to be. In practice, neither I nor Herb Sutter know of an implementation that does not use contiguous storage.
Notice that the &s[0] thing is always guaranteed to work by the C++11 standard, even in the 0-lengt... |
1,986,969 | 1,986,986 | static initialization in c | I have a function which is passed a list of ints, until one value is "-1" and calculates the minimum.
If the function gets called couple times, it is supposed to return the minimum between all calls.
So I wrote something like that:
int min_call(int num, ...)
{
va_list argptr;
int number;
va_start(argptr, n... | Yes, C++ allows for statics to be lazily initialized at runtime. Effectively C++ turn static initialization into this:
static int XX_first_time = 1;
if (XX_first_time)
{
// run the initializer
XX_first_time = 0;
}
While this is convenient, it is not thread safe. The standard does not require this to be thre... |
1,987,284 | 1,987,307 | Native C++ and C# interop | So I'm architecting an application that does necessarily C++ work, but MFC/ATL is too messy for my liking, so I had this brilliant idea of doing all the "thinking" code in native C++ and all the pretty UI code in C#. The problem, though, is interoperability between the two of them. Before I get too carried away with th... | The easiest way to handle this is to use C++/CLI, and expose your logic as .NET types.
It's very easy to wrap a native C++ class in a ref class that's usuable directly from a C# user interface.
That being said - this was my plan, originally, in my current project. My thinking was that I'd need the native code for some... |
1,987,286 | 1,987,290 | Get type of variable | If I understand correctly, typeid can determine the actual type in polymorphism, while typeof cannot.
Is it also true that their returns are used for different purposes: the return of typeof is used as type keyword that can define variable, but the return of typeid cannot?
Is there any way to both get the actual type f... | c++0x will have decltype which can be used like this:
int someInt;
decltype(someInt) otherIntegerVariable = 5;
but for plain old c++, unfortunately, no.
I suppose that decltype won't really be much help either though since you want the polymorphic type, not the declared type. The most straight forward way to do what y... |
1,987,413 | 1,987,495 | Inclusion of unused symbols in object files by compiler in C vs C++ | This might be a dumb question, but maybe someone can provide some insight.
I have some global variables defined in a header file (yes yes I know that's bad, but this is just a hypothetical situation). I include this header file in two source files, which are then compiled into two object files. The global symbols are n... | In C, identifiers have three different types of "linkage":
external linkage: roughly, this is what people mean by "global variables". In common terms, it refers to identifiers that are visible "everywhere".
internal linkage: these are objects that are declared with static keyword.
no linkage: these are objects that a... |
1,987,541 | 4,427,060 | Cannot marshal a struct that contains a union | I have a C++ struct that looks like this:
struct unmanagedstruct
{
int flags;
union
{
int offset[6];
struct
{
float pos[3];
float q[4];
} posedesc;
} u;
};
And I'm trying to Marshal it like so in C#:
[St... | I'm not 100% sure about this but I believe that the Union means that the same memory is used for both members. In the case of the C++ structure, an int[] or a posedesc structure. So the size of the structure will be sizeof(int) + sizeof(posedisc). Meaning, Union doesn't mean you'll have both an int[] and a posedisc you... |
1,987,602 | 1,987,647 | Pure virtual method called | I understand why calling a virtual function from a constructor is bad, but I'm not sure why defining a destructor would result in a "pure virtual method called" exception. The code uses const values to reduce the use of dynamic allocation - possibly also the culprit.
#include <iostream>
using namespace std;
class Act... | You have Undefined Behavior. As the parameter to Button's ctor is a const& from a temporary, it is destroyed at the end of that line, right after the ctor finishes. You later use _action, after Action's dtor has already run. Since this is UB, the implementation is allowed to let anything happen, and apparently your ... |
1,987,679 | 1,987,716 | C++0x static initializations and thread safety | I know that as of the C++03 standard, function-scope static initializations are not guaranteed to be thread safe:
void moo()
{
static std::string cat("argent"); // not thread safe
...
}
With the C++0x standard finally providing standard thread support, are function-scope static initializations required to be ... | it seems the initialization would be thread safe, since in the case the object is dynamically initialized upon entering the function, it's guaranteed to be executed in a critical section:
§ 6.7 stmt.decl
4. ...such an object is initialized the first time control passes through its declaration... If control enters the d... |
1,988,192 | 1,988,667 | ACE_Mutex::acquire problem | I have a mutex in my class with the following definition:
ACE_Mutex m_specsMutex;
When i use the acquire() method that takes no parameters everything works just fine. But when i use it with a time value (as follows) it just immediately returns with -1 value. I'm sure that this mutex hasn't been acquired anywhere else ... | Browing through the doxygen docs for ACE_Mutex, I don't understand how your code could possibly compile. The time-out value (tv) is passed either by reference or a pointer so that acquire() can update the absolute time at which the mutex was acquired. You cannot pass an expression. Try it like this:
ACE_Time_Value t... |
1,988,385 | 1,988,571 | How are open source projects commonly organized and deployed? | I am looking for documentation on how to commonly do the technical part of publishing the source of first open source projects, in particular with library-intensive stuff in C/C++, Java, Python.
To give an example, if I built a C++ project with an IDE like Netbeans and various libraries like Xerces-C and Boost, I would... | Let's look at one of open-source features. If you want to learn how it's deployed, download a couple of similar open-source projects and learn from them. So, find one that's done like yours and study its sources.
Why should it help? The thing is that open-source projects have to be able to build on users' machines e... |
1,988,459 | 1,988,477 | global low level keyboard hook being called when SendInput is made. how to prevent it? | I have a win 32 application written in c++ which sets the low level keyboard hook. now i want to sendInput to any app like word / notepad. how do i do this?
i have already done enough of using findwindow / sendmessage. for all these, i need to know edit controls. finding the edit control is very difficult.
since SendIn... | If I understood your problem correctly, you should ignore "injected" key events in your hook procedure, like this:
LRESULT CALLBACK
hook_proc( int code, WPARAM wParam, LPARAM lParam )
{
KBDLLHOOKSTRUCT* kbd = (KBDLLHOOKSTRUCT*)lParam;
// Ignore injected events
if (code < 0 || (kbd->flags & LLKHF_INJECTED)) {
... |
1,988,642 | 1,988,650 | set visual studio 2008 compiler for c not c++ | I have installed visual studio 2008 and i want to create some simple applications using C language. I do this by creating c++ console applications but i want the compiler to work for C not C++. Any way to accomplish this or i need another compiler if i want to deal with C?
| Use .c file extension instead of .cpp, those files will be compiled as C-only code by default in a C/C++ Visual Studio project.
|
1,988,685 | 2,125,751 | Is it possible to specify specific flags/define for DLL/SO build? | How can I specify some unique flags for DLL only builds. By default libtool adds -DDLL_EXPORT which is fine for most projects that follow GNU conventions, but if I work, for example, with Boost I may need to specify for my library flags: -DDLL_EXPORT -DBOOST_ALL_DYN_LINK for DLL only builds, also sometimes I want condi... | You can disable building shared library by default with
LT_INIT([disable-shared])
then you can use AM_CONDITIONAL combined with --enabled-shared and set the extra definitions if shared library is explicitly requested. IOW, enable building static or shared, but not both at the same time.
|
1,988,814 | 1,988,851 | Changing a pointer to an array in C | I have got a structure and in it a pointer to a 2D array. But when I try to assign an actual 2D array to that pointer I do not succeed - compiler says that my pointer is a pointer to a 1D array.
Here's my code:
typedef GLfloat Vertex2f[2];
typedef GLfloat TextureCoordinate[2];
typedef struct {
GLuint texture_name... | You have two problems. First is that tempVerticesArray is const. You can't assign a pointer to a const value (&tempVerticesArray) to a pointer to a non-const variable (ballSprite.vertices) without a typecast, so the compiler is complaining. You should modify the vertices data member to be of the type const Vertex2f ... |
1,988,849 | 2,030,130 | Using enums with Pococapsule (C++ IoC-container) | Is there a way of supplying enum values as method-args in pococapsule without resorting to factory-methods?
Let say I have a class that take an enum value in its constructor
class A
{
A(myEnum val);
}
Using Pococapsule xml configuration:
I would like to express something like this:
<bean id="A" class="A">
<met... | (repost, as the XML code was filtered out in previous reply)
In C/C++ enums are able to be passed as int implicitly, therefore, you can simply have type="long" in the method-arg element.
You can also use the DSM feature to define your own extend schema that supports your specific enum (it should be similar to the user... |
1,988,914 | 1,989,073 | Avoid excessive function parameters: class-centered or function-centered approach? | How would you fix the following bad code that passes too many parameters around?
void helper1(int p1, int p3, int p5, int p7, int p9, int p10) {
// ...
}
void helper2(int p1, int p2, int p3, int p5, int p6, int p7, int p9, int p10) {
// ...
}
void foo(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8... | Short Answer:
Happy New Year! I'd avoid option #1 and only go with option #2 if the parameters can be separated into clear and logical groups that make sense away from your function.
Long Answer
I have seen many examples of functions as you described from coworkers. I'll agree with you on the fact that it's a bad code... |
1,988,973 | 1,988,979 | How to reinterpret the bits of a float as an int | What is the Java equivalent of following C++ code?
float f=12.5f;
int& i = reinterpret_cast<int&>(f);
| float f = 12.5f;
int i = Float.floatToIntBits(f);
|
1,988,978 | 1,989,082 | Overloading for_each for specific iterator types | I'm using a typedef to define the type of a container in my program so that I can easily switch between using normal STL containers and STXXL containers, along the lines of:
typedef stxxl:vector<Data> MyContainer;
or
typedef std:vector<Data> MyContainer;
One difficulty is that STXXL provides a special version of std:... | You can specialize templates in std (17.4.3.1), but you can't add overloads. Your definition is an overload, not a specialization of the standard for_each template, and in any case functions can't be partially specialized. So it's undefined to put any definition in namespace std that might do what you want.
ADL is supp... |
1,989,222 | 1,989,433 | How to calculate quantization error from 16bit to 8bit? | Does anyone know how to calculate the error of quantizing from 16bit to 8bit?
I have looked at the Wikipedia article about Quantization, but it doesn't explain this.
Can anyone explain how it is done?
Lots of love,
Louise
Update: My function looks like this.
unsigned char quantize(double d, double max) {
return (unsi... | It is there in the Wikipedia article, expressed as signal to noise ratio. But I guess the real question is, in what units do you want the result? As a signal to noise power ratio, it's 20 log(2^8) = 55 dB
You probably need to read this: http://en.wikipedia.org/wiki/Decibel
|
1,989,552 | 2,118,537 | GCC error with variadic templates: "Sorry, unimplemented: cannot expand 'Identifier...' into a fixed-length argument list" | While doing variadic template programming in C++11 on GCC, once in a while I get an error that says "Sorry, unimplemented: cannot expand 'Identifier...' into a fixed-length arugment list." If I remove the "..." in the code then I get a different error: "error: parameter packs not expanded with '...'".
So if I have t... | There is a trick to get this to work with gcc. The feature isn't fully implemented yet, but you can structure the code to avoid the unimplemented sections. Manually expanding a variadic template into a parameter list won't work. But template specialization can do that for you.
template< char head, char ... rest >
st... |
1,989,708 | 1,989,780 | Type casting with printf statements under Mac OSX and Linux | I have some piece of code that behaves differently under Mac OSX and Linux (Ubuntu, Fedora, ...). This is regarding type casting in arithmetic operations within printf statements. The code is compiled with gcc/g++.
The following
#include <stdio.h>
int main () {
float days = (float) (153*86400) / 86400.0;
printf ("%... | try this:
#include <stdio.h>
int main () {
float days = (float) (153*86400) / 86400.0;
printf ("%f\n", days);
float foo = days / 30.6;
printf ("%d\n", (int) foo);
printf ("%d\n", (int) (days / 30.6));
printf ("%d\n", (int) (float)(days / 30.6));
return 0;
}
Notice what happens? The double to float conver... |
1,989,796 | 1,999,622 | Qt question to fullscreen flash application | I am using Qt to develop an application and inside we have access to select flash streaming videos like youtube. Is there a way to programmaticly full screen the flash application without requiring interaction from the user?
I am using a "QWebView" control.
| I would say: locate the button for the fullscreen application on the page, and send a click using QEVent. Tricky, but might work.
If the button is inside the flash application, you will have difficulties to locate it but if you succeed, you can probably send the click to the flash application area.
|
1,989,805 | 1,989,837 | Different outputs after debugging and compiling C++ programs | I'm running CodeBlocks on the MingW compiler in an XP virtual machine. I wrote in some simple code, accessible at cl1p , which answers the algorithm question at CodeChef (Well it only answers it partly, as I have not yet included the loop for multiple test cases.
However, my problem is, that while running it in debug m... | For one thing, this:
//save entire array in prev
prevrow = new int [i+1];
prevrow = currow;
copies the pointer, not the whole array.
|
1,989,819 | 23,449,090 | Theory on error handling? | Most advice concerning error handling boils down to a handful of tips and tricks (see this post for example). These hints are helpful but I think they don't answer all questions. I feel that I should design my application according to a certain philosophy, a school of thought that provides a strong foundation to build ... | A couple of years ago I thought exactly about the same question :)
After searching and reading several things, I think that the most interesting reference I found was Patterns for Generation, Handling and Management of Errors from Andy Longshaw and Eoin Woods. It is a short and systematic attempt to cover the basic id... |
1,989,842 | 1,989,885 | Storing several data into a file | Can somebody give me some tips about storing a lot of data into a file?
For example: I'm creating an audio sequencer with C++, and I want to save all the audio sample names (the file paths), info about the audio tracks in the project (name, volume, mute, solo, etc.) and where the samples are placed on the timeline into... | When you want to save different information in the same file, there are two popular ways to go: fixed-length fields and delimited fields. With fixed length field, each part is stored in the same size chunk. So if you wanted to store 5 things, and you store them in 80-character blocks, you can go to offset 160 in the ... |
1,989,908 | 1,989,973 | Interlocked*64 on WinXP 32bit | How should I implement these 64-bit interlocked functions on WinXP? Of course I can use full mutex, but I think it's needlessly heavyweight for this task. There must be some better way.
| You shouldn't. This is much more complex than you think.
If you insist, your best bet is to use a critical section to make sure you get the barriers right.
If you really think a critical section is too heavy weight, read up on memory barriers
|
1,989,969 | 1,990,028 | C++ multiple inheritance off identically named operator | Is it possible to inherit identically named operator which only differ in return type, from two different abstract classes.
If so, them:
what is the syntax for implementing operators
what is the syntax for using/resolving operators
what is the overhead in general case, same as for any other virtual function?
if you c... | The return type of a function is not part of it's signature, so you can't have two operator+(i,j)'s in block_matrix - that would be an ambiguous call. So multiple inheritance is sort of a red herring here on this point. You just can't do that.
What are you really trying to do, and why?
In any event, for your other qu... |
1,989,977 | 1,990,160 | Writing data chunks while processing - is there a convergence value due to hardware constraints? | I'm processing data from a hard disk from one large file (processing is fast and not a lot of overhead) and then have to write the results back (hundreds of thousands of files).
I started writing the results straight away in files, one at a time, which was the slowest option. I figured it gets a lot faster if I build a... |
Can I somehow estimate a convergence value for the amount of data that I should write from the hardware constraints?
Not in the long term. The problem is that your write performance is going to depend heavily on at least four things:
Which filesystem you're using
What disk-scheduling algorithm the kernel is using
T... |
1,990,012 | 1,990,025 | Daemon writing output to file twice instead of once in C++ | I've written a daemon that writes the word "Beat" to a file, followed up the current date and time at 15 second intervals. However, each time I check the output file, the daemon appears to be outputting twice like this:
Beat: Fri Jan 1 18:09:01 2010
Beat: Fri Jan 1 18:09:01 2010
where it should only have on entry.
... | It's because you fork() at the beginning, creating two running instances of the daemon...
|
1,990,032 | 1,990,052 | Using C++, how do I correctly inherit from the same base class twice? | This is our ideal inheritance hierarchy:
class Foobar;
class FoobarClient : Foobar;
class FoobarServer : Foobar;
class WindowsFoobar : Foobar;
class UnixFoobar : Foobar;
class WindowsFoobarClient : WindowsFoobar, FoobarClient;
class WindowsFoobarServer : WindowsFoobar, FoobarServer;
class UnixFoobarClient : Unix... | It would work, although you'd get two copies of the base Foobar class. To get a single copy, you'd need to use virtual inheritance. Read on multiple inheritance here.
class Foobar;
class FoobarClient : virtual public Foobar;
class FoobarServer : virtual public Foobar;
class WindowsFoobar : virtual public Foobar;
cl... |
1,990,135 | 1,990,153 | Is it better to use `#ifdef` or inheritance for cross-compiling? | To follow from my previous question about virtual and multiple inheritance (in a cross platform scenario) - after reading some answers, it has occurred to me that I could simplify my model by keeping the server and client classes, and replacing the platform specific classes with #ifdefs (which is what I was going to do... | Preferably, contain the platform dependant nature of the operations within the methods so the class declaration remains the same across platforms. (ie, use #ifdefs in the implementations)
If you can't do this, then your class ought to be two completely separate classes, one for each platform.
|
1,990,156 | 1,990,162 | CPP | .h files (C++) | I was just wondering what the difference between .cpp and .h files is? What would I use a header file (.h) for and what would I use a cpp file for?
| In general, and it really could be a lot less general:
.h (header) files are for declarations of things that are used many times, and are #included in other files
.cpp (implementation) files are for everything else, and are almost never #included
|
1,990,277 | 1,990,308 | c++ Syntax of a constructor's initialization list with a data member struct? |
Possible Duplicate:
Member initialization of a data structure’s members
EDIT:
I typed the title in last, and it gave me a lsit of related problems, as it usually does. At the bottom of this list was the exact same problem. (Using the exact same code ;)).
Member initialization of a data structure's members
AraK answ... | I see you found your solution, but please note that you could also get away with writing a class wrapper for SDL_rect, or even a global function SDL_rect createRect( int x, int y, int w, int h )
|
1,990,283 | 2,076,474 | C++ Dialog box With timer | I couldn't find a simple tutorial on how to make a dialog box with decrementing timer. I don't need the timer to be accurate or actually reflect my program's inner timer.
| Ended using SetTimer : http://msdn.microsoft.com/en-us/library/ms644906%28VS.85%29.aspx
Thanks!
|
1,990,526 | 1,990,607 | Compiling Festival on MingW32 | I'm trying to compile Festival on MingW32, so I can have a Windows binary. I couldn't find the Windows binary on their site. Anyone have one they can post?
If not, here's what I have so far. I did the ./configure and make for it and have the following message:
$ make
config/config:43: ../speech_tools/config/config:... | Windows binaries are available here
|
1,990,535 | 1,990,550 | Win32 files locked for reading: how to find out who's locking them | In C++ (specifically on Visual C++), sometimes you cannot open a file because another executable has it opened and is not sharing it for reads. If I try to open such a file, how can I programatically find out who's locking the file?
| In Windows 2000 and higher, you cannot do this without using a kernel-mode driver. Process Explorer and other similar tools load a driver automatically to accomplish this. This is because the file handles are in kernel space and not accessible by user-mode applications (EXE files).
If you are really interested in doing... |
1,990,645 | 1,990,687 | general boost asio stream reads question | I'm a little confused about how reading data into a stream works in asio. My main questions are:
What happens if there are multiple asynchronous writes from one computer going on at the same time, and only one asynchronous read on the receiving computer. Over a TCP protocol, is there any chance that the data will get ... |
What happens if there are multiple asynchronous writes from one computer going on at the same time, and only one asynchronous read on the receiving computer. Over a TCP protocol, is there any chance that the data will get interleaved?
If you call async_write while another asynchronous write operation is in progress, ... |
1,990,665 | 1,990,670 | memory overhead of pointers in c/c++ | I'm on a 64bit platform, so all memory adrs are 8 bytes.
So to get an estimate of the memory usage of an array, should I add 8 bytes to the sizeof(DATATYPE) for each entry in the array.
Example:
short unsigned int *ary = new short unsigned int[1000000]; //length 1mio
//sizeof(short unsinged int) = 2bytes
//sizeof(shor... | No, you don't get a pointer for each and every array index. You get a single pointer pointing to the array, which is a contiguous block of memory, which is why the address of any index can be calculated from the index itself plus the array address.
For example, if the variable a known by the memory location 0xffff0012 ... |
1,990,864 | 1,990,869 | how to convert a hexadecimal string to a corresponding integer in c++? | i have a unicode mapping stored in a file.
like this line below with tab delimited.
a 0B85 0 0B85
second column is a unicode character. i want to convert that to 0x0B85 which is to be stored in int variable.
how to do it?
| You could use strtol, which can parse numbers into longs, which you can then assign to your int. strtol can parse numbers with any radix from 2 to 36 (i.e. any radix that can be represented with alphanumeric charaters).
For example:
#include <cstdlib>
using namespace std;
char *token;
...
// assign data from your fil... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.