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 |
|---|---|---|---|---|
5,102,705 | 5,102,743 | c++ Setting a pointer variable in parent class from child and use it in parent class | i'm sorry for the title. I seem to have a problem. I'm just a beginner and i'm sorry if this was asked before.. i couldnt find a straight answer on this one. (when i search class, pointer and child i get results about passing parent or child pointers... i do not want to pass the (this) child or parent pointer, i just w... | I'm guessing this is because you are pointing to a temporary:
window = &BasicWindow()
Once that function exits, window points to "crap" and bad things will happen.
presumably, what you want to do is to create a new instance of the window - i.e.
window = new BasicWindow();
Don't forget to cleanup!
|
5,102,738 | 5,102,778 | C++ [] operator overload problem | I'm still new to C++ so I daily run into new problems.
Today came the [] operator's turn:
I'm making myself a new generic List class because I don't really like the std's one. I'm trying to give it the warm and fuzzy look of the C#'s Collections.Generic List, so I do want to be able to access elements by index. To cut ... | Since myList is a pointer myList[0] doesn't invoke operator[], it returns Collections::List<int>*. What you want is (*myList)[0]. Or better still, Collections::List<int>& myRef = *myList; and then use myRef[0] (Other option is not allocate the memory for myList on the heap, you can create it on stack using Collections:... |
5,102,846 | 5,102,883 | problem initializing global variables | I have recently begun learning the Win32 API using this tutorial:
http://www.winprog.org/tutorial/ (though I'm using C++, not C as in the tutorial)
I'm currently experimenting with the "edit box"-function where I'm trying to compare the text written in the edit box with another line of characters.
Code:
#define IDC_MA... | Look into the very important concept of scope. refer this page http://www.cplusplus.com/doc/tutorial/variables/
c++ Code:
case WM_CREATE:
{
HFONT hfDefault;
HWND hEdit;
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSC... |
5,103,057 | 5,117,635 | boolean options from boost program options | I am using boost program options to get boolean values from command line argument. I would like my argument to be specified as "Y", Yes", "N", "No".
Actually my code did it using a temporary string that
will be parsed by boost program options
checked against "Y", "Yes", "N" or "No"
assigned to the boolean variable me... | You are going to be parsing a string one way or another. There are a couple options, mostly depending on how often you are going to be querying this value. Here is an example of something similar to what I recently used; CopyConstructable and Assignable so it works well with STL. I think I needed to do a few extra thin... |
5,103,170 | 5,106,510 | Is it possible I write a (Windows or Linux) service by QtService? | Is it possible I write a (Windows or Linux) service by QtService ?
I think QtService is only for connecting to a service , not for writing it. yes ?
if you have an example, please give me.
| Yes, that is the exact intention of QtService. Please see the example http server.
|
5,103,298 | 5,107,201 | How can we do video recording using VNC | How can we do video recording using VNC? I want to record all the session. we have multiple clients and server. So efficiency is important too.
Anyone has any idea of some opensource project which can handle this. I can think of vncrec only but haven't used it. So nyone who used this project.
| Here is some info (Debian centric) about recording and transcoding VNC sessions into movie files including how to use vncrec and other options.
|
5,103,443 | 5,103,749 | How to check what shared libraries are loaded at run time for a given process? | Is there a way to check which libraries is a running process using?
To be more specific, if a program loads some shared libraries using dlopen, then readelf or ldd is not going to show it.
Is it possible at all to get that information from a running process? If yes, how?
| Other people are on the right track. Here are a couple ways.
cat /proc/NNNN/maps | awk '{print $6}' | grep '\.so' | sort | uniq
Or, with strace:
strace CMD.... 2>&1 | grep -E '^open(at)?\(.*\.so'
Both of these assume that shared libraries have ".so" somewhere in their paths, but you can modify that. The first one g... |
5,103,532 | 5,103,566 | Copy std::map data to another map | I have a map that's defined like this
struct A
{
int A;
int B;
};
typedef map<int,A> Amap;
Then I have Amap1 and I want copy it to Amap2
A a....;
Amap Amap1,Amap2;
Amap1[1]=a1;
Amap1[2]=a2;
Amap1[3]=a3;
Amap2.insert(Amap1.begin(), Amap1.end());
Sometimes this work properly, sometimes this copies only t... | Copying one map to another can be done with operator = or the copy constructor.
E.g
map<X, Y> mp1;
//fill mp1 with data
map<X, Y> mp2(mp1); //mp2 is a copy of mp1 (via copy-construction)
map<X, Y> mp3;
mp3 = mp2; // mp3 is also a copy of mp2 (via copy-assignment)
|
5,103,543 | 5,103,590 | How does overloading of const and non-const functions work? | The STL is full of definitions like this:
iterator begin ();
const_iterator begin () const;
As return value does not participate in overloading resolution, the only difference here is the function being const. Is this part of the overloading mechanism? What is the compiler's algorithm for resolving a line like:
vector... | In the example you gave:
vector<int>::const_iterator it = myvector.begin();
if myvector isn't const the non-const version of begin() will be called and you will be relying on an implicit conversion from iterator to const_iterator.
|
5,103,613 | 5,580,588 | Getting the size of a QGraphicsView | I want to know the size of a certain QGraphicsView. Its size isn't fixed because the widget is part of a grid layout. I tried using this->ui->myGraphicsView->width() and its height equivalent but these values aren't accurate.
How can I get the current size of a QGraphicsView?
| Constantly received 100x30 as the size of my QGraphicsView as well. It turned out I was asking for the size of the QGraphicsView before it was shown.
After moving my initialization code to showEvent, I got the correct dimensions.
|
5,103,682 | 5,103,744 | How to sort QList<MyClass*> using Qt library (maybe qSort())? | class MyClass {
public:
int a;
bool operator<(const MyClass other) const {
return a<other.a;
}
....
};
....
QList<MyClass*> list;
| Make your own comparator, that will work with pointers and then use qSort: http://qt-project.org/doc/qt-5.1/qtcore/qtalgorithms.html#qSort-3
|
5,103,886 | 5,216,986 | How to set which Boost unit test to run | I am trying to use boost-test, and in particular boost unit testing.
I clearly don't understand how is the main function generated and called, all the tutorial says is to define a module and write a test
#define BOOST_TEST_MODULE EnfTraderTest
BOOST_AUTO_TEST_CASE(CalculateExpectedPriceTest){BOOST_ERROR("Oops");}
But, ... | The simplest way to do this is to write your tests into one .cpp-file, and define the macro BOOST_TEST_MODULE before you include unit_test.hpp. You can then compile that .cpp-file and execute it. If you have tests in several .cpp-files, just link them all together, but take care that either BOOST_TEST_MODULE or BOOST_T... |
5,104,205 | 5,104,249 | what is an Equivalent to this line of code in c++ using the QT library ? | Given the declarations
class DBuffer
{
//...
};
typedef QList<DBuffer*> DBuffers;
QList<int> fds;
QMap<int, DBuffers> buffers;
what does the line of code in the function given below mean.
function()
{
// what does this line mean? what is "&bufs"
DBuffers &bufs=buffers[fds[i]];
}
| The & in the declaration indicates this variable is a reference, i.e. bufs doesn't create a new copy of the output but just refers to the object that is assigned to it. Reference types in this context can be thought of as alias for the object they are assigned to.
The RHS of the expression is pretty straight forward: l... |
5,104,329 | 5,105,192 | Unable to write a std::wstring into wofstream | I'm using Qt/C++ on a Linux system. I need to convert a QLineEdit's text to std::wstring and write it into a std::wofstream. It works correctly for ascii strings, but when I enter any other character (Arabic or Uzbek) there is nothing written in the file. (size of file is 0 bytes).
this is my code:
wofstream customers... | Add
#include <locale>
and at the start of main,
std::locale::global(std::locale(""));
|
5,104,344 | 5,115,235 | How can I get past a "Library not loaded:" issue? | I started playing with the Kinect and I would like to use skeleton tracking using OpenNI.
Since my knowledge of c++ is limited, the easiest option is to use the ofxOpenNI addon for OpenFrameworks.
I've downloaded the addon, and successfully compiled the example, but the application can't load a dylib:
[Session started ... | Sounds like the libs, though present, aren't compatible with your system -- it finds them but can't load them.
And indeed, checking the README on the OpenNI github page, in the section "Release Notes", we find the following:
* MacOSX: Only OSX 10.6 (Snow Leopard) with an Intel based CPU is currently supported.
You hav... |
5,104,454 | 5,104,515 | reallocating memory in efficient way | A new, presumably larger block, can be obtained and initialized with the old block, and then the old block
be freed.
purpose of that code ; reallocating the old memory area with new size
typeName is Object
Object *oldArray = objects ; // objects is pointer to old data block
objects = new Object[ newCapacity ] ;
f... | Use std::vector<Object>. It will do this automatically for you.
|
5,104,489 | 5,104,952 | diff between ADT list and linked list | What is the ( real | significiant ) difference (s) between ADT list implementation and linked list implementation
with respect to queue ?
Moreover,
Can you suggest any website with visual example of these type of lists ?
| It is REALLY hard to understand this question, but in an attempt to ask what the actual question is, I believe to have figured it out. So my assumption is, that the question is: "What is the difference between std::list and std::queue. @fatai: Please correct me, when I am wrong.
The std::list is a doubly-linked list. E... |
5,104,640 | 5,104,669 | What is void* and to what variables/objects it can point to | Specifically, can it point to int/float etc.?
What about objects like NSString and the like?
Any examples will be greatly appreciated.
| void* is such a pointer, that any pointer can be implicitly converted to void*.
For example;
int* p = new int;
void* pv = p; //OK;
p = pv; //Error, the opposite conversion must be explicit in C++ (in C this is OK too)
Also note that pointers to const cannot be converted to void* without a const_cast
E.g.
const int * ... |
5,104,699 | 5,104,836 | Where is the boost vec(x,y,z) function defined | I have seen this function vec(....) in many boost libraries. It constructs a vector with the values you place in it using some template meta-magic to do the type inference. So for example:
vec(1,2) returns vector<int> filled with 1,2
vec(1.1,2.2,3.3) returns vector<float> filled with 1.1,2.2,3.3
Its really useful for ... | Are you you are referring to the boost::assign library?
It not the construction you mention but it is similar.
|
5,104,736 | 5,109,165 | heap corruption in c++ | I'm getting an error in runtime when I run my code in visual c++ 2010.
void dct2(){
float** G = new float*[len];
for(int u = 0; u < len; u++){
G[u] = new float[len];
for(int v = 0; v < len; v++){
G[u][v] = 0;
for(int x = 0; x < len; x++){
for(int y = 0; y ... | I started converting all arrays to std::vector and in the midway i ran the code. That didn't solve my problem but i found the cause of the error. it was in this function:
void cpy(int** arr, int x, int y){
for(int i = x; i < x + len; i++){
for(int j = y; j < y + len; j++){
mat[i][j] = arr[i][j];... |
5,104,861 | 5,115,614 | Putting restrictions in overloading new and delete | Is it possible to put some restrictions in overloading operators new and delete?
My overloaded new is linked in a different file to my test program.
The scenario is:
if(condition is satisfied)
call overloaded new
else
call the actual new defined in new.h
| There are three ways to provide an operator new.
replacing one or more of the four non placement default operators new,
providing overload to the default operator new (thus with an additional parameter, those may be called with the placement new syntax),
providing operator new class members, those will be called only ... |
5,104,979 | 5,105,074 | how to call a C++ COM function with BSTR parameter in VBScript | In my COM component written in C++, there is function:
HRESULT f(BSTR id)
How to call this function in VBScript?
Thanks in advance!
| In order to invoke COM components from VBScript, your object must implement the IDispatch interface. Once you do this, you can do something like:
Set myObj = CreateObject("yourObject")
myObj.f "Hello, world!"
Mapping between the VARIANT argument passed in from vbscript and the BSTR argument expected by the implementat... |
5,105,079 | 5,115,297 | DirectX: Small distortion between 2 sprite polygons | Hello I use the same way to render sprites with directx from a long time but here I am rendering the screen in a texture and then render it with a big sprite on the screen.
For the camera I use that:
vUpVec=D3DXVECTOR3(0,1,0);
vLookatPt=D3DXVECTOR3(0,0,0);
vFromPt=D3DXVECTOR3(0,0,-1);
D3DXMatrixLookAtRH( &m... | To render to full screen best way is to not define any camera positions.
If you use as input positions
SimpleVertex vertices[] =
{
{ XMFLOAT3( -1.0f, 1.0f, 0.5f ), XMFLOAT2( 0.0f, 0.0f ) },
{ XMFLOAT3( 1.0f, 1.0f, 0.5f ), XMFLOAT2( 1.0f, 0.0f ) },
{ XMFLOAT3( 1.0f, -1.0f, 0.5f ), XMFLOAT2( 1... |
5,105,089 | 5,105,439 | How to make variable size string for sprintf | I want to make variable size string "msg" like this.
char *msg;
sprintf(msg,"Msg",variable)
i dont want to use string .
What would be the best solution
| C strings are fixed size. <string> is variable size. If you don't want to use string but still have a variable size, you will have to tell us why you don't want to use <string>, or we will just tell you that it is the solution to your problem.
Perhaps you simply don't know your way around <string>, perhaps you only kno... |
5,105,217 | 5,105,283 | c++ reading formated tabulated data from file using BOOST / STL/ etc | What is the best way for me to create a formated data reading/writing function for a tabulated text file. Say some calls like :
readElement(i,j)
insertRow(elem[])
readColHeaders()
I was wondering if any existing wrapper can do that ?
internal format is tab-spaced data OR CSV.
Thnx-Egon
| There are lots of csv readers but I never found something nice.
The easiest is to use boost::tokenize to fill a vector<vector<string> > from your file. A fancier way is to use boost::spirit (but the learning curve is a rollercoaster).
To generate sur a file, iterating on a vector<vector<string> > is quite trivial.
|
5,105,239 | 5,105,691 | Prioritized Auto-Reset Event | I have this problem:
Thread1 may set an auto-reset event, and there are many threads that may wait for the event. Is there any way I can specify the priority of the waiting threads for the specific event, that is, if say the event is set and both A and B are waiting for it, I want to make sure that B will work, and A w... | The problem as you describe it requires real-time scheduler and synchronizer. While I understand that such things exist in the Windows API, I have tried very hard to avoid knowing about them.
My recommendation, unless the rest of the system is a true real-time system, would be to roll your own solution using a priorit... |
5,105,360 | 5,132,634 | Makefile/double compilation | Recently I noticed (after others have extended the project) that the compile time significantly increased. I was suggested to make use of c++ precompiled headers. The "include" parts are moved to a separate file "precompiled.h"
#include <iostream>
#include <stxxl/vector>
#include <stxxl/priority_queue>
#include <stxxl... | You need to change the precompiled.o: precompiled.h rule to precompiled.h.gch: precompiled.h so GCC knows it's the precompiled header
|
5,105,382 | 5,108,487 | Multiple producers, single consumer | I have to develop a multithreaded application, where there will be multiple threads, each thread generates custom event log which need to be saved in queue (not Microsoft MSMQ).
There will be another thread which reads log data from queue and manipulates it, with certain information to save log information into a file.... | This kind of thing is very easy to do using the BlockingCollection<T> defined in System.Collections.Concurrent.
Basically, you create your queue so that all threads can access it:
BlockingCollection<LogRecord> LogQueue = new BlockingCollection<LogRecord>();
Each producer adds items to the queue:
while (!Shutdown)
{
... |
5,105,476 | 5,105,545 | Attempting to pass string to std::ifstream as argument | I'm attempting to use a string retrieved from a vector to pass a filename to ifstream for opening.
vector<string> files;
//Populate vector
std::ifstream ifile(files[0] ,std::ios::binary);
When compiled This returns:
error: no matching function for call to 'std::basic_ifstream >::basic_ifstream(std::basic_string, std... | Try this:
std::ifstream ifile(files[0].c_str(), std::ios::binary);
|
5,105,650 | 5,105,769 | Generating member types for containers | When I define my own containers, I have to provide a dozen of member types, for example:
typedef T& reference;
typedef const T& const_reference;
typedef T* iterator;
typedef const T* const_iterator;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef T value_type;
... | There is boost::iterator for this specific need.
I hope this tutorial will make things clear http://www.boost.org/doc/libs/1_46_0/libs/iterator/doc/iterator_facade.html#tutorial-example
|
5,105,832 | 5,105,850 | C++ - What does const represent here? | If I get a C++ statement as follows:
double getPrice() const;
What doesn const represent here?
Thanks.
| This is for member functions (in classes or structs). It means that the method won't change the state of the instance it operates on (won't change any member variables for example).
|
5,105,918 | 5,106,221 | Obtaining const_iterator from iterator | Is there a metafunction f that maps an iterator to its corresponding const_iterator?
I.e. f<std::vector<T>::iterator>::type should yield std::vector<T>::const_iterator.
| I am not aware of such a metafunction.
Not all iterators have a corresponding const_iterator. E.g. insert_iterator. So such a metafunction would need to decide what it is going to do in such cases.
|
5,105,950 | 5,106,056 | Porting DLL code from Borland C++ Builder 6 to Microsoft Visual C | I need help with some old C++ code from/for DLL wich was written in borland c++ builder 6, I must recompile it in VS2008 or VS2010. Since all our test have shown that MSVC optimizes code more than 4 times better(for speed) then borland builder does... And our software has kind of real-time requirements.
I have rewritte... | Either std::bind or boost::bind should do the trick. Also see the questions "std::bind a member function to an object pointer" and "boost::bind and class member function". You may also want to look at boost::function or std::function as well.
|
5,106,170 | 5,106,239 | How do I know if std::map insert succeeded or failed? | I have a map in a multithreaded app mapping a class called uuid to pointer.
What I want to know if an insert operation succeeded for failed.
e.g.
_mymap.insert(hint, MyMap::value_type(entry.uuid, itemptr));
Does it throw an exception or something if it fails?
| In fact the insert method which takes a hint parameter does not return whether the insert succeeded or not. One way to check if insert actually happened would be to check the size of the map before and after insertion. If it is the same, then insert has failed (i.e. the key was already present). I know it sounds ugly, ... |
5,106,196 | 5,106,227 | C++ - What does volatile represent when applied to a method? | If I have a C++ method declaration as follows:
class A
{
public:
double getPrice() volatile;
};
What does volatile represent here?
What could it be used for?
You might be interested in this Dr Dobbs article by Andrei Alexandrescu. I was :)
Edit:
That article was written a while back and now it seems that the comm... | It is a volatile member which, just like a const member can only be called on const objects, can only be called on volatile objects.
What's the use? Well, globally volatile is of little use (it is often misunderstood to be applicable for multi-threaded -- MT -- programming, it isn't the case in C++, see for instance h... |
5,106,264 | 5,106,303 | uncompress from zlib.h - error - undefined reference to `uncompress_gzip' | I have code in which, I have got compressed data and I need to uncompress it.
I am using zlib for this
I have done:
#include <zlib.h>
in my .cpp file.
Now, when I compile it, I get the error:
undefined reference to `uncompress_gzip'
Do, I need to link with some lib?
Thanks,
sg
| You need to link it to zlib. Without knowing what compiler you are using, I'll just use GCC:
gcc my.cpp -lz
|
5,106,280 | 5,106,345 | String concatenation using preprocessor | is it possible to concatenate strings during preprocessing?
I found this example
#define H "Hello "
#define W "World!"
#define HW H W
printf(HW); // Prints "Hello World!"
However it does not work for me - prints out "Hello" when I use gcc -std=c99
UPD This example looks like working now. However, is it a normal featu... | Concatenation of adjacent string litterals isn't a feature of the preprocessor, it is a feature of the core languages (both C and C++). You could write:
printf("Hello "
" world\n");
|
5,106,297 | 5,106,384 | Calculating two numbers from command line c++ | This is my code :
#include <iostream>
using namespace std;
int main (int argc, char* argv[])
{
int frstNumb = atoi (argv[1]);
int scndNumb = atoi (argv[2]);
int sum = 0;
sum = frstNumb + scndNumb;
}
Okay, now its working for integers. What do I must do so I can put e.g. "2.5 and 1.2" in my parameters? This pr... | Yep-- you want atoi().
int frstNumb = atoi(argv[1]);
int scndNumb = atoi(argv[2]);
I'd suggest googling atoi() to see how it works, it will probably help you in the future.
|
5,106,410 | 5,106,667 | c++ function with max_element & iterator = 3x slower | The program I am developing gets three times slower when I call the following function.
It wouldn't be bad if it was not called a couple million of times.
double obterNormLarguraBanda(const std::vector<double>& v, int periodos)
{
int aa;
double maximo, minimo, valor;
std::vector<double>::const_iterator ini... | max_element and min_element are both iterating through the range, when the entire step could be done in one function.
I believe some compilers have a minmax_element function in their STL, but I do not believe it is in the standard. You could write your own. I originally wrote this as an untemplated version, but if you ... |
5,106,473 | 5,106,540 | Problem with tstring typedef | I am having a problem with trying to typedef myself a nice handy tstring (see below)
#ifndef _NISAMPLECLIENT_H_
#define _NISAMPLECLIENT_H_
#include <windows.h>
#include <stdlib.h>
using namespace std; // ERROR here (1)
#ifdef _UNICODE
#define CommandLineToArgv CommandLineToArgvW
#else
#define CommandLineToArgv Comman... | Include the string header (#include <string>, not string.h ;)).
Also, don't ever use:
using namespace ...
... in headers unless you want to call down the wrath of your fellow developers ;)
Side-note: in C++ most of the traditional C standard headers have counter-parts without .h extension but with a leading c. In your... |
5,106,650 | 5,106,717 | Multiple inclusion in multiple files | I am making a small game.
In BattleRecord.h:
#ifndef _CHARACTER_H_
#define _CHARACTER_H_
#include "Character.h"
#endif
class BattleRecord
{
public:
Character Attacker;
Character Defender;
Status status;
int DamageDealt;
int GoldEarned;
int ExpGained;
};
In Character.h:
#ifndef _EQUIPMENT_... | You're using inclusion guards wrong. They should appear in the file that you intend to prevent multiple inclusions only, and they should cover the entire file. (not just the includes).
For example, in BattleRecord.h
#ifndef _BATTLE_H_
#define _BATTLE_H_
#include "Character.h"
class BattleRecord
{
public:
Character... |
5,106,965 | 5,236,728 | Destructing an object of a class inheriting from QObject | I have a class inheriting from QObject, and it overrides the eventFilter() method. It looks something like this:
struct A
{
void DoSomething()
{
}
};
struct B : public QObject
{
Q_OBJECT
B( QObject *parent, A &a_ ) ) : QObject( parent ), a( a_ )
{
}
bool eventFilter( QObject * watched, QEvent * event ... | Since B is an event filter, you would need to find the object (or objects) that it is filtering on and remove it from those objects. At that point, you should be able to delete B without any problem. When a QObject-derived class is deleted, Qt stops tracking it and won't try to delete it later.
|
5,106,999 | 5,107,125 | array questions (homework) | I am stuck on the last few problems of an array exercise. Could anyone lend a hand?
Write C++ statements that do the following:
store 5 in the first column of an array and make sure that the value in each subsequent column is twice the value in the previous column.
print the array one row per line.
print the array on... | For #1, run a loop that starts at zero and goes until the number of rows. In each iteration just assign 5 to array[row][0]=5 (since coloumn 0 is the first coloumn).
Now run a loop from 1 to the number of coloumns. Inside, run another loop for each row. just assign array[row][col]=array[row][col-1]*2.
For #3, simply rev... |
5,107,171 | 5,115,432 | Portable thread class implemented in C++ | When writing C programs that need to share a file scope variable between the application and an interrupt routine/a thread/a callback routine, it is well-known that the variable must be declared volatile, or else the compiler may do incorrect optimizations. This is an example of what I mean:
int flag;
void some_interr... | Well, that edit makes all the difference of the world. Semaphores introduce memory barriers. Those make volatile redundant. The compiler will always reload int flag after any operation on a semaphore.
Fred Larson already predicted this. volatile is insufficient in the absence of locks, and redudant in the presence of l... |
5,107,350 | 9,422,595 | Using unsigned byte textures with DirectX 10 / 11 | I am attempting to do some processing in the pixel shader on a texture. The data for the texture is coming from a memory chunk of 8 bit data. The problem I am facing is how to read the data in the shader.
Code to create the texture and ressource view:
In OnD3D11CreateDevice:
D3D11_TEXTURE2D_DESC tDesc;
tDesc.Height = 4... | Oh my this is a really old question, I thought it said 2012!
But anyway as it's still open:
Due to the nature of GPU's being optimised for floating point arithmetic, you probably wont get a great deal of performance advantage by using a Texture2D<int> over a Texture2D<float>.
You could attempt to use a Texture2D<float>... |
5,107,461 | 5,112,792 | How do I calculate the Hash of a large file with gcrypt, in c++ | I have file that I need to hash, this file can be too large to read into memory at one time, so I need a way using gcrypt to hash the file in more manageable sized chunks how can I do this?
Thank you
| I found how to do this:
The gcrypt handle is valid and builds upon its input so that whether you write five 1k chunks to the handle or one 5k chunk of data the hash is the same either way. The hash itself is not finalized until you attempt to read it, so you can sit in a loop reading chunks of a large file at a time o... |
5,107,503 | 5,337,116 | Why does this code return an intersection point on the wrong side of the box at some angles? | At some angles this will show an intersection on the wrong side (back when it should be front OR left when it should be right).
What is wrong?
inline bool GetIntersection(f32 fDst1, f32 fDst2,
vector3df P1, vector3df P2, vector3df &Hit) {
if ( (fDst1 * fDst2) >= 0.0f)
return 0;
if ( fDst1 =... | This is related to problems with floating point precision. You can't compare floating points by using == if you want a stabile algorithm, e.g. the following is forbidden:
if ( fDst1 == fDst2)
return 0;
What you need to do is to replace all these == comparisions with feq( ) below:
static const double cEpsilon... |
5,107,694 | 42,507,529 | How do I add a reference to an unmanaged C++ project called by a C# project? | One solution (the.sln)
One C++ project (mycppproject.vcxproj in 2010or mycppproject.vcproj in 2008) which compiles a native DLL exporting some function(s). In debug this builds c:\output\Debug\mycppproject_d.dll and in release this builds c:\output\Release\mycppproject.dll.
One C# console application (mycsharpconsole.c... | Visual Studio doesn't support referencing an unmanaged C++ project from a managed C# one, but MSBuild supports referencing any project from any other project.
You can manually add a reference to your project by editing the .csproj file by hand. In the file, find your existing set of ProjectReference elements (or add a ... |
5,107,766 | 5,219,586 | How to jump to matching #if/#elif/#endif statements? | In Visual C++ 6.0 (1998 vintage), there is a useful command Ctrl K / Ctrl J to cycle through paired conditional statements, jumping from one to the next:
#if
...
#elif
...
#endif
I can't find an equivalent keyboard command to do this in Visual Studio 2010. Anyone know if it's possible?
Note: it is used in an .rc2 fi... | This is a command called Edit.GoToBrace and you can change the keyboard shortcut from the Tools. See this In the Visual Studio editor is there a keyboard command to jump to the matching bracket?.
|
5,108,111 | 5,108,295 | What does add_lvalue_reference do? | I have this class that makes a path for a montecarlo simulator where it takes creates paths of integers from an array of available ints. So for example we could have a path of length 3 drawn from the array containing {0,1,2,3,4} and this would for example generate 3,1,2 and 1,4,0.
//This path generator just generates a... | Copying pseudo-random number generators means you'd get the same stream of "random" numbers from each, which is not desirable, so you need a reference there.
However, you could just say randgen&.
According to [dcl.ref] in draft 3225, just randgen& will create an lvalue reference no matter what's passed in (type, lvalue... |
5,108,359 | 5,108,395 | How do I define a template function within a template class outside of the class definition? | Given:
template <class T>
class Foo
{
public:
template <class U>
void bar();
};
How do I implement bar outside of the class definition while still having access to both template parameters T and U?
| IIRC:
template<class T> template <class U>
void Foo<T>::bar() { ...
|
5,108,704 | 5,108,738 | Define template function only for classes derived from a single base | I have a base class Base, that a lot of other classes will be derived from. I would like to define:
template<typename Derived>
ostream &operator<< (ostream &o, Derived &derived) {
}
But only for classes derived from Base. I need all previously defined operator<< to be used for other types. How to do that? Is that poss... | http://www.boost.org/doc/libs/1_46_0/libs/utility/enable_if.html
http://www.boost.org/doc/libs/1_42_0/libs/type_traits/doc/html/boost_typetraits/reference/is_base_of.html
template<typename Derived>
typename enable_if<is_base_of<Base, Derived>, ostream&>::type
operator<< (ostream &o, Derived &derived)
{
}
|
5,108,789 | 5,110,768 | SWIG Python and C++ std::string null-termination problem |
Possible Duplicate:
How Python can get binary data(char*) from C++ by SWIG?
I have a SWIG based C++ interface that can called from Python. There is a function in it, that has one std::string argument. It looks like this:
WrapperGet(const std::string& key);
If it is called from Python with a string argument that con... | I've had to deal with this in the past, and I just grabbed the std::string conversion template from SWIG and tailored it a bit to use PyString_FromStringAndSize when creating a Python string from a std::string and the std::string constructor that accepts a size argument when going the other way.
That was with a really ... |
5,108,864 | 5,192,895 | How to make a simple non-blocking popup window in a console C++ program? | I try to figure out in which C++ GUI toolkit (+stdlib+libc) it would be easiest to implement such a useful function in a normal command-line application:
void ShowStringWindow(string& s) {
// ...
}
ShowStringWindow should display a window with an editable box containing string s.
It should return immediately, so the... | To do this with Qt, you need to:
Create a mutex for the string
variable.
Create a thread, obviously.
Create a QApplication object, in that
thread. (on the first call)
Set the "setQuitOnLastWindowsClosed"
to false on the QApplication. (on the first call)
Create the dialog and "exec" it.
After the "exec" function retur... |
5,109,104 | 5,109,142 | Is a DLL loaded entirely or only some functions? | When a program uses a dynamic shared library, does it load the DLL entirely (so you can almost erase the DLL from disk during application is running) or does it load only a part of the DLL according to its need at each time during the runtime life of the application?
| DLL gets loaded entirely. DLLs are same as EXEs in almost all aspect; the only big difference between them is, DLLs are not executable. It doesn't have main() function - the start of a program.
|
5,109,273 | 5,109,491 | MMGR Questions, code use and thread-saftey | 1) Is MMGR thread safe?
2) I was hoping someone could help me understand some code. I am looking at something where a macro is used, but I don't understand the macro. I know it contains a function call and an if check, however, the function is a void function. How does wrapping "(m_setOwner (FILE,_LINE_,FUNCTION),fal... | 1) The C++03 standard does not mention threads. However, in all platforms with thread support I know of, the default memory allocator (new and delete) is thread safe.
Edit: In general, if things are not marked as thread-safe, you should assume they aren't, especially when there implicit global data (such as heap manag... |
5,109,417 | 5,110,889 | Access Violation when writing to pointer variables in dynamically allocated classes | Ok so the title doesn't explain my situation very well so I'll try to explain a little better here:
Here is part of my class structure:
ObjectView (abstract class)
ShipView : ObjectView (child of object view)
In a method I create a new ShipView:
ShipView *shipview (in header file).
shipview = new ShipView(in main pa... | If
_ObjectData = new Model[mesh->mNumVertices];
crashes while
Model *_ObjectData = new Model[mesh->mNumVertices];
doesn't, it certainly looks like your object hasn't been initialized.
My psychic debugger suggests that you have declared a different variable, also called shipview, which is what you're calling Initialize... |
5,109,499 | 5,109,710 | Searching range of values in a Vector of Structs C++ | I am writing a program to search range of values in a vector of structs, after trying for almost a day, I am still out of luck
Here is what I am doing, I know it is wrong
{in Function}
vector::iterator it=find_if(ip_records[ip].begin(),ip_records[ip].end(), find_it("2011-01-24 20:59.20", "2011-01-24 20:59.30"));
{D... | You didn't initialize the end member variable in the initialization-list:
find_it(string start, string end):start(start), end(end) {}
//note this ^^^^^^^^
Now, it initializes it!
|
5,109,687 | 5,116,318 | Exposing a full (C language) pthread interface from a C++ library based on c++0x std::thread | Is it conceptually possible to write a small wrapper library based on std::thread (and perhaps other C++0x parts) that exposes the full pthread interface to a C program?
(If you're wondering how this could be useful: in the hypothetical world where a mainstream OS kernel was written in C++ with a fully C++0x compliant ... | Yes, such an implementation should be possible. I even wrote a simple version at one point, just to prove I could.
There are a few things which are tricky, but most stuff (e.g. mutexes, condition variables, threads) would be a simple wrapper.
Asynchronous cancellation is one of the tricky things --- it requires support... |
5,109,720 | 5,109,872 | Implement the C standard library in C++ | Say an OS/kernel is written with C++ in mind and does not "do" any pure C style stuff, but instead exposes the C standard library built upon a full-fledged C++ standard library. Is this possible? If not, why?
PS: I know the C library is "part of C++", but let's say it's internally based on a C++-based implementation.
S... | I see no reason why you couldn't do it, but I also see no reason why someone would use such an implementation. It's going to use a lot more memory, and be at least somewhat slower, than a normal implementation...although it might not be much worse than glibc, whose implementation of stdio is already essentially C++ any... |
5,109,737 | 5,109,774 | STL cloning a vector | !Hi
I have a hard time trying to copy vector of pointers to Point.
I have a
vector<Point*> oldVector
and I want to copy this vector into other vector. So I used a copying constructor. I did this that way
vector<Point*> newVector = vector<Point*>(oldVector.begin(),oldVector.end());
Unfortunately I get an exception/er... | That would be either
vector<Point*> *newVector = new vector<Point*>(oldVector.begin(),oldVector.end());
or
vector<Point*> newVector(oldVector.begin(),oldVector.end());
When creating objects, you only use assignment when allocating from the heap. Otherwise, you simply place the constructor argument(s) inside parenthes... |
5,109,805 | 5,114,770 | How to connect to muliple databases using same queries | I am developing a large scale application in C++. The application also maintains a database (currently I am using MySQL), I use OTL for database connectivity. Now what i want to do is to provide support for using database from multiple vendors. E.g User A use MySQL and user B use PostGres. I think upon implementing it ... | Suppositions:
Suppose i have following two tables in my database
Project
Docs
Docs
And currently i am supporting only following two databases:
1) Post Gres
2) Oracle
Implementation:
I implement this logic in following three phases
1) Data Base Adapter: Only this class is exposed to outer world and this contians the ... |
5,110,000 | 5,110,046 | STL Vector and template function problem | I would like to do a function that manipulates a vector in order to select one, and return it. (The best would be to return an iterator that points that selection.)
Alright, I have this code here in my header :
class Ecran { // That means Screen in french :P
// Other definitions...
template<typename T>
sta... | The problem you're getting is a linker error, and if I had to guess I would assume that your problem is that you've split up your implementation into a .h/.cpp pair. For regular C++ classes, this is the correct approach, but when dealing with templates you must put all of the code, including the implementation, into t... |
5,110,006 | 5,110,070 | Creating a deep copy of a doubly-linked list node | I have my node defined something like:
class LLNode
{
public:
std::shared_ptr<LLNode> prev;
std::shared_ptr<LLNode> next;
std::shared_ptr<int> data;
LLNode(void)
: prev(std::shared_ptr<LLNode>(nullptr)),
next(std::shared_ptr<LLNode>(nullptr)),
data(std::shared_ptr<int>(nullptr))
{
}
... | You are doing the mistake that you are trying to copy the whole chain/list from a single node. That does not make that much sense to do in copy ctor of a list node. Make the copy ctor just copy the members' values, do not recurse. Copying the whole chain/list is the job for a LinkedList class.
|
5,110,122 | 6,964,788 | Is it possible to create smaller memory-mapped views on a 2GB+ file? | I have written a C++ class for Windows and Linux that creates a memory-mapped view for an file of arbitrary size n. The code for the class constructor can be seen here. I am currently testing the code on Windows 32 bit XP.
I have found for file sizes 0 < n <= 1.7GB , the constructor returns a valid pointer to a memory... | I can't see your pastebin link, but I can suggest a simple solution with a c++ class declaration. I think the implementation should be obvious from the comments:
class ShiftingMemMap
{
public:
// constructs a dynamically shifting memory map of a file...
ShiftingMemMap ( const char* fileName, size_t view_size = ... |
5,110,206 | 5,110,270 | What does boost::asio::ip::tcp::resolver::iterator do? | I'm starting with boost asio programming in C++ and when looking over the examples I just can't understand what does boost::asio::ip::tcp::resolver::iterator do.
Code:
boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
tcp::resolver::query query(argv[1]);
tcp::resolver::iterator endpoint_iterat... | boost::asio::ip::tcp::resolver::iterator iterates through the address list of the host that you specified (hosts can have multiple addresses).
Like an std::string::iterator iterates through its characters, boost::asio::ip::tcp::resolver::iterator iterates through its address list.
The following code:
while (error && en... |
5,110,306 | 5,110,472 | Loading data into a vector of structures | I am trying to load some data from a text file into a vector of structures. My question is, how do you indicate the size of the vector? Or should I be using a the vector push_back function to do this dynamically, and if so, how does this work when populating a structure?
The full program is outlined below:
My structur... | A vector is expandable, but only through push_back(), resize() and a few other functions - if you use emps[i] and i is greater than or equal to the size of the vector (which is initially 0), the program will crash (if you're lucky) or produce weird results. If you know the desired size in advance, you can call e.g. emp... |
5,110,529 | 5,111,407 | class template partial specialization parametrized on member function return type | The following code, which attempts to specialize class template 'special', based on the return type of member function pointer types, results in a compile error with VC9:
template<class F> struct special {};
template<class C> struct special<void(C::*)()> {};
template<class R, class C> struct special<R(C::*)()> {};
str... | This is a bug.
template <class C> struct special<void(C::*)()>; // specialization 1
template <class R, class C> struct special<R(C::*)()>; // specialization 2
According to 14.5.4.2, the partial ordering of these two class template specializations are the same as the partial ordering of these imaginary function... |
5,110,582 | 5,171,357 | C++ template library for calculate continuous signals | I'm looking for a C++ template library which implements operations on continuous signals represented in integer types with their resolutions (fixed point numbers).
e.g: foo, bar, baz are int with 10, 5 and 2 count/unit resolution
foo = 4;
bar = 3;
baz = foo * bar;
printf("%d %d %d\n", foo, bar, baz);
results:
40 15 2... | This is an old C++ library that supports mixing numbers of different precisions. The precisions have to be power of 10.
http://www.efgh.com/software/fixed.htm
If you want math functions (sin, cos, tan) you can try out this library:
http://www.trenki.net/content/view/17/1/
This does not allow you to mix precisions.
Disc... |
5,111,173 | 5,111,292 | C++ SMTP that allows file attachments | I am looking to create an SMTP that allows for file attachments, however, I am finding it difficult to locate a tutorial. I have found one close thing, which is https://stackoverflow.com/questions/58210/c-smtp-example , however, this fails to compile in VS2005/2010 because of the include files that are used.
I would li... | Building on my answer to a previous question, using the Microsoft ATL classes which are included in the paid versions of Visual Studio.
CSMTPConnection smtp;
if (!smtp.Connect(m_strEmailServer))
return false;
// start generating the email message; remember to call CoInitialize somewhere in the app before this
CM... |
5,111,318 | 5,111,351 | Resources for becoming more proficient with C++? | I am an undergraduate student and I recently was hired for a co-op for this summer and next fall. From what I understand I will be writing a lot of C++ which I am comfortable with but I don't have a huge amount of experience actually writing C++ in particular.
I wanted to take the time to really dive into C++ and beco... | TopCoder was featured on This Developers Life recently and the algorithm challenges are a great way to hone your skills in various languages including C++
Getting involved in Open Source projects is a regular suggestion.
Good books from many authors are listed conveniently in many places including Amazon.com
|
5,111,347 | 5,111,448 | C++ free() changing other memory | I started noticing that sometimes when deallocating memory in some of my programs, they would inexplicably crash. I began narrowing down the culprit and have come up with an example that illustrates a case that I am having difficulty understanding:
#include <iostream>
#include <stdlib.h>
using namespace std;
int main... | You will have to ask your libc implementation why it changes. In any case, why does it matter? This is a memory area that libc has not allocated to you, and may be using to maintain its own data structures or consistency checks, or may not be using at all.
|
5,111,357 | 5,111,679 | MS Visual Studio to Linux - compiling and debugging in VirtualBox | So, is there any way to make Visual Studio
- compile C++ app for linux using gcc.
- When i hit debug - run application in VirtualBOX ( or other VM software ) using gdb.
Edit: don't offer me other IDE - i know about Eclipse, KDevelop, NETBeans, Anjuta ...
| You might want to look at WinGDB.
It looks like you are exact match for their target audience.
Note 1: I have no experience with this product. I just happen to know about its existence.
Note 2: If you decide to use this product, I would like to know about your experience.
Good luck...
|
5,112,034 | 5,112,091 | How to retrieve a single character from a QTextEdit? | I have the following character array:
char mychars[SIZE];
I would like to copy one character from a QTextEdit into that array.
I tried:
mychars[i] = this->ui->QTextEdit;
mychars[i] = this->ui->QTextEdit->inputContext();
But I get errors like:
error: invalid conversion from ‘QTextEdit*’ to ‘char’
| You can retrieve the text in your QTextEdit using:
QString text = this->ui->QTextEdit->toPlainText();
EDIT:
if(text.size()>0){
mychars[0] = text[0].toAscii(); // assuming your text is ascii
}
|
5,112,187 | 5,112,221 | How to check (non-trivial) equivalence of lists of numbers, fast? | I have a list of integers, for example 1,2,2,3,4,1. I need to be able to check for equivalence (==) between different lists.
However, I do not mean a simple number wise comparison. Each of these lists actually denotes a set partition, where the position in the list denotes the index of an element and the number denot... | Try iterating through the two sequences in parallel, keeping a map (either std::map or an array) from values in the first array to values in the second and vice versa. If you get to a pair that is not in your table, add it, unless there is something in the table for either that first or second number (since that would... |
5,112,305 | 5,116,399 | Whyever **not** declare a function to be `constexpr`? | Any function that consists of a return statement only could be declared
constexpr and thus will allow to be evaluated at compile time if all
arguments are constexpr and only constexpr functions are called in its body. Is there any reason not to declare any such function constexpr ?
Example:
constexpr int sum(int x, i... | Functions can only be declared constexpr if they obey the rules for constexpr --- no dynamic casts, no memory allocation, no calls to non-constexpr functions, etc.
Declaring a function in the standard library as constexpr requires that ALL implementations obey those rules.
Firstly, this requires checking for each func... |
5,112,443 | 5,161,650 | Qt/MFC Migration Framework tool: properly exiting DLL? | I'm using the Qt/MFC Migration Framework tool following this example:
http://doc.qt.nokia.com/solutions/4/qtwinmigrate/winmigrate-qt-dll-example.html
The dll I build is loaded by a 3rd party MFC-based application. The 3rd party app basically calls one of my exported DLL functions to startup my plugin and another funct... | I GOT THIS WORKING! After many frustrating hours working on this I got it working. I was using the code provided in the Qt/MFC Migration documentation which has:
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason,
LPVOID /*lpvReserved*/ )
{
static bool ownApplication = FALSE;
i... |
5,112,598 | 5,112,930 | Converting a MPL Vector to a Static Array | I wrote some code to generate a boost::mpl::vector to use as a lookup table for a factorial function, as a test for a more general library function with which a developer may be able to generate a lookup table in the form of a static array of primitives. The function (which would most probably be implemented as a prepr... | http://www.boost.org/doc/libs/1_46_0/libs/preprocessor/doc/index.html
#define MACRO(z, i, data) \
mpl::at_c<data,i>::value
static const data[] = { BOOST_PP_ENUM(N, MACRO, factorialTable) };
|
5,112,633 | 5,112,719 | Converting from LPCWSTR to LPCSTR | I'm having trouble trying to cast a LPCWSTR to an LPCSTR.
Some Background
I am programming a VC++ 2010 application, and have already run into the situation where I had to convert from type System::String^ to std::string. I used this code to do so:
private: std::string toss(System::String^ s)
{
msclr::intero... | Edit: completely misread the question so disregard my earlier answer, sorry. If you need to later pass this string into a Windows API, do you have a reason for using std::string and not std::wstring?
Additional edit: there's some confusion on my part here. What is the type of existingstr and what is the signature of ... |
5,112,670 | 5,112,774 | Desperately need Borland C++ library called cg16.lib | I have an old project from the 1990's I desperately need to compile. The linker keeps asking for the Code Guard library cg16.lib but I don't have the install disks for this anymore.
Does anyone have cg16.lib?
I am compiling with version 4.5 of Borland C++. Its an ancient product but still works!
ANSWER
cg16.lib refers ... | I would have thought use of code guard would be optional. You should be able to remove it from the linker settings for the project and compile just fine?
|
5,112,852 | 5,112,879 | Intermittent segmentation faults with straightforward C++ program | I'm currently working through Thinking in C++, and chapter 9, exercise 15 gives instructions to time the difference between inline and non-inline constructors. In doing so, I created a metric shedload of object instances in an array, but when I get up to a certain point, the program begins segfaulting intermittently. ... | If sizeof(B) is 4 bytes, that puts the size of that array (b) at 8374200 bytes. That's pretty close to what I'm guessing is your default maximum thread stack size of 8 MiB (8388608 bytes). So it looks like you're overflowing your stack.
|
5,112,992 | 5,113,033 | Why is buffering in C++ important? | I tried to print Hello World 200,000 times and it took me forever, so I have to stop. But right after I add a char array to act as a buffer, it took less than 10 seconds. Why?
Before adding a buffer:
#include <iostream>
using namespace std;
int main() {
int count = 0;
std::ios_base::sync_with_stdio(fa... | For the stand of file operations, writing to memory (RAM) is always faster than writing to the file on the disk directly.
For illustration, let's define:
each write IO operation to a file on the disk costs 1 ms
each write IO operation to a file on the disk over a network costs 5 ms
each write IO operation to the memo... |
5,113,282 | 5,113,296 | Implementing interfaces by inheritances | I have a common interface that many classes in my project inherit (FWIW it's a ref-counting interface). This interface is inherited by both classes and other interfaces. Instead of re-implementing the interface in every class, I'd like to just have a corresponding implementation class that all the other classes inherit... | You could try always virtually inheriting from IBar. That way, you cut out the middleman, so to speak, and always directly inherit from it regardless if you also inherit from one of its decendents.
Eg:
class IBar {
public:
virtual void Bar() = 0;
};
class CBar : public virtual IBar { // implementation class fo... |
5,113,311 | 5,113,326 | Convert an integer to base 10. Given number can be in any base | I came across this question:
"Given an integer, write a program that converts the given number to a number (in base 10). The given number could be in any base, but the base is unknown."
Provide an algorithm
Thanks in advance.
| Use strtol to convert from whatever base to your computer's native integer format. Then use itoa to convert to a base 10 representation.
|
5,113,365 | 5,113,385 | Do built-in types have default constructors? | After reading this article I made a point that int () yields 0 because the temporary int is value initialized and not because int() calls the default constructor for int. (The article is flawed according to my understanding.)
I also said that primitive (built-in) types don't have constructors. The original author asked... | A constructor is a member function (constructors are fully specified in clause 12 of the C++ Standard, which covers special member functions like constructors and destructors).
A member function can only be defined for a class type (C++03 9.3/1 says "Functions declared in the definition of a class, excluding those decl... |
5,113,507 | 5,113,882 | How to make a C# console utility attach to a C++ exe? | I've got a Win32 C++ game side project and I'd like to create a C# process that can be dynamically attached. The C++ process could then send debug data to the C# process and the C# console could send debug commands to the C++ process. I know this can be done, but I'm not sure how to do it. Anyone know?
| There are plenty of ways to communicate cross-process. For your purposes, I would recommend you use Sockets to communicate between the two, as this will also allow you to communicate between machines if you like; and the semantics of using Sockets are similar in both languages.
On the C# Side, you can get started with ... |
5,113,539 | 5,120,269 | Automatically including object files using Boost.build | I'm using the latest version of boost-build found in boost 1.46. Given main.cpp which depends on a.h and b.h, using the boost-build's ability to auto-detect dependencies my jam file is simply
exe my_prog : main.cpp ;
But, if there is an implementation file, b.cpp, the object b.o is not produced nor linked in. I'd li... | Is there any reason this won't work?
exe my_prog : main.cpp b.cpp ;
Doing it the way you want sounds painful and unpleasant, especially for someone new to boost-build. Plus there may be times when you only need the header, and not the cpp.
If your code is impeccably organized, and you only need the files in the curre... |
5,113,541 | 5,113,555 | Wouldn't be better if Windows used directx to draw stuff? | Windows uses GDI to draw it's windows. Directx is way faster than GDI.
Wouldn't be smart if they used Directx to draw all of the stuff?
| I'm not an expert, but the Aero interface that comes with Windows 7 requires a DirectX 9 compatible graphics processor with a Windows Display Driver Model (WDDM) driver, Pixel shader 2.0 in hardware, and a minimum of 128 MB of Video RAM.
So I suspect DirectX is indeed used, at least partially, to render things in Windo... |
5,113,590 | 5,114,660 | C: Utility to analyze .obj files, to measure size of some of the functions in exact bytes? | I needed to look-up the exact byte size of few C functions.
Any recommendation of any utility which is able to analyze .obj files generated by the gcc compiler?
| I only have a GCC v4 here for testing, but I don't think this particular feature of binutils has changed recently.
test.c:
int foo()
{
return 42;
}
Compiled:
$ gcc -c test.c -o test.o
Disassembled:
$ objdump -D test.o
...
0000000000000000 <foo>:
0: 55 push %rbp
1: 48 89 e5 ... |
5,113,901 | 5,121,105 | OpenGL (glut)- increase pixel placement precision | I am trying to write program that displays a window with simulated "tv static". I have it mostly working but when I expand the window grid lines form. I have no idea what could be causing this as this is my first OpenGL (glut) program. Any suggestions? thanks in advance
#include <GLUT/glut.h>
#include <stdlib.h>
#inclu... | Your screen is width*height size, but you are actually drawing (width+1)*(height+1) points. Also, your boundary pixels are drawn right on the boundary lines, so I'm not sure they'll be visible.
Solution:
for (int y = 0; y < maxy; ++y) {
for (int x = 0; x < maxx; ++x) {
glColor3d(rand() / (float) RAND_MAX,ra... |
5,114,102 | 5,114,120 | Figuring out obscure pointer typedef | typedef solution_type (*algorithm_ptr_type) (
problem_type problem,
void (*post_evaluation_callback)(void *move, int score)/* = NULL*/
);
Please help me! Thank you
| This means, algorithm_ptr_type is a pointer to a function returning solution_type and whose parameters are:
problem of type problem_type
post_evaluation_callback which is again a function pointer taking two parameters (void* and int) , and returning void.
And the same can be written as (easy and readable syntax):
... |
5,114,264 | 5,115,181 | Help with hit test function | I'm making a Gui where Widgets have children, and children are both clipped in the hit test, and in rendering, to the parent's rectangle. However it is not always like this. A widget can choose not to clip its children. In this case, the children are bound to the parent's parent rectangle. My rendering currently reflec... | Give your AguiWidget a hitTest, and let it recurse into its children when positive.
Then when clicking on a clipped area, the gitTest of the parent (clipping) widget will fail, and the hit test will never be performed for the clipped Widget.
|
5,114,330 | 5,114,566 | C++: sscanf behavior | Can someone help me understand this piece of code:
char *line = new char[2048];
char *probableCauseStr = new char[512];
char *additioanl_text = new char[512];
long holdPeriod = 0;
while( !f.eof() ) {
f.getline( line, 2048 );
//
// find the ',' seperator
... | p is used to find the first comma and replace it with \0 (which is the end-of-string for C-style strings, in particular for sscanf). Then p is incremented to point at the next character.
So a string like
"Hello world, 100000"
becomes
line -> "Hello world"
p -> " 100000"
Then the two sscanfs are tried, checking for wh... |
5,114,473 | 5,114,547 | How to Set the Initial Focus of the control in the particular window? | I created an application in which I use window procedure to keep track of all the controls in the window.
My question is, how do I initially set the focus to the first created control in the window?
| There are two ways to set the initial focus to a particular control in MFC.
The first, and simplest, method is to take advantage of your controls' tab order. When you use the Resource Editor in Visual Studio to lay out a dialog, you can assign each control a tab index. The control with the lowest tab index will autom... |
5,114,550 | 5,114,724 | Need help choosing database server | Good day everyone.
Recently I was given a task to develop an application to automate some aspects of stocks trading. While working on initial architecture, the database dilemma emerged. What I need is a fast database engine which can process huge amounts of data coming in very fast. I'm fairly experienced in general pr... | The technology is irrelevant. This is about hardware.
Need super-fast selection by foreign
keys and by combination of foreign key
and one of the columns (presumably
DATETIME)
So you need something like a supermicro 72 disc computer system filled with SSD's and 256gb memory as cache. Simple as that. Addd process... |
5,114,683 | 5,114,852 | Loading DLL not initializing static C++ classes | I have a DLL that is being loaded at run-time. The DLL relies on a static variable for internal workings (it is a std::map), this variable is defined within the DLL.
When I call the first function from the DLL after loading, I get a SegFault from the DLL, the map was never initialized. From everything I have read from ... | When you linked your DLL, was the /ENTRY switch specified? If so, it'll override the linker's default which is DllMainCRTStartup. As a result, _CRT_INIT won't be called and, in turn, the global initializers won't be called which will result in uninitialized global (static) data.
If you are specifying /ENTRY for your ... |
5,114,778 | 5,114,890 | Passing new data to an asynchronous, threaded function that may still be using the old data | I am having some problem related to C/C++:
Suppose I have some class
class Demo
{
int constant;
public:
void setConstant(int value)
{
constant=value;
}
void submitTask()
{
// need to make a call to C-based runtime system to submit a
// task which will be executed "asyn... | If you don't want to wait for the C code to finish before you make the next call then you can't reuse the same memory location over and over. Instead, create an array and then pass those locations. For this code, I'm going to assume that the number of times the for loop will run is n. This doesn't have to be known u... |
5,115,001 | 5,115,499 | Qt phonon media object error | #include "mainwindow.h"
#include "ui_mainwindow.h"
#include <Phonon/MediaSource>
#include <QUrl>
#include <Phonon/MediaObject>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pu... | I guess that there are one or more functions declared in the header file but their bodies haven't been built yet.
for example:
//headerfile
class MyClass
{
public: MyClass();
private: void function1();
void function2();
};
//source file
MyClass::MyClass(){}
void MyClass::function1(){ /*do somethin... |
5,115,077 | 5,115,129 | C++ implicit type conversion in Visual Studio 2010 | I had a function: void foo(bool boolParam = true)
And I changed it to: void foo(const char* charParam, bool boolParam = true)
To avoid searching I just compiled the code hoping that the compiler will give an error (or at least an warning) where the function was called because of wrong parameter type, but instead of thi... | The behavior is entirely correct, because (as you note) the conversion from false (a valid null pointer constant) to pointer is implicit. Try a std::string instead.
|
5,115,148 | 5,115,182 | In C++ How can I tell the difference between integers and characters? | I am currently learning C++ and I have been asked to make a program which will calculate the interest that would be paid on a deposit of a given size. One of the requirements is that we display an error message when non-integer data is entered.
I however cannot work out how to detect if non-integer data has been entere... | You don't have to check yourself. The expression (std::cin >> YourInteger) evaluates to a bool, whcih is true if and only if YourInteger was succesfully read. This leads to the idiom
int YourInteger;
if (std::cin >> YourInteger) {
std::cout << YourInteger << std::endl;
} else {
std::cout << "Not an integer\n";
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.