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 |
|---|---|---|---|---|
7,064,904 | 7,083,311 | c++ openssl encryption fails sometimes | i want to encrypt and decrypt strings in my c++ appication and use openssl for that.
since i don't know exactly how to do it, i used this code from the internet:
LPCTSTR encrypt(LPCTSTR inString, LPCTSTR inKey, LPCTSTR outString)
{
const unsigned char* inStringC = (const unsigned char*)in... | char* works differently within byte oriented encryption than for strings. Normally it holds null terminated strings. In this case it doesn't, it holds a byte array of definate length (3 in your case). The bytes in it can have any value including 00h, the null termination character, depending on the key, the data and th... |
7,064,927 | 7,064,992 | VBOs or another way? | I've just finished my basic OpenGL model loader, and now I want to move over to VBOs instead of glBegin() and glEnd(). I read in an article that even VBOs are deprecated.
My question is: Are VBOs really deprecated and is there a better way to draw objects in OpenGL? Should I be using display lists perhaps?
| Vertex Buffer Objects are not deprecated. In fact, I believe they are the only (non-deprecated) way to render in OpenGL 3.0 and above.
See the OpenGL page on Vertex Buffer Object.
Legacy Note: Versions of OpenGL prior to 3.0 allowed the use of
client-side data for vertex rendering, but GL 3.0 deprecated this.
Core... |
7,065,200 | 7,065,247 | constexpr question, why do these two different programs run in such a different amount of time with g++? | I'm using gcc 4.6.1 and am getting some interesting behavior involving calling a constexpr function. This program runs just fine and straight away prints out 12200160415121876738.
#include <iostream>
extern const unsigned long joe;
constexpr unsigned long fib(unsigned long int x)
{
return (x <= 1) ? 1 : (fib(x - 1... | joe is an Integral Constant Expression; it must be usable in array bounds. For that reason, a reasonable compiler will evaluate it at compile time.
In your second program, even though the compiler could calculate it at compile time, there's no reason why it must.
|
7,065,419 | 7,065,502 | How do I debug an existing C++ executable with pdb but without source code | I work in already compiled (in debug mode) C++ project. I have its exe file and pdb file.
I can run the exe from command line.
How can I debug the project? (I so not have its .sln file.)
I work in Visual Studio, but I also have a cygwin in the system.
| Open the executable from Visual Studio, in the same way as you would open a project or a solution. That will allow you to debug it.
(It creates an empty place-holder solution around your exe, which you can use to change environment variables or command-line arguments when you run the exe to debug it.)
|
7,065,433 | 7,067,685 | Problem debugging with Eclipse CDT - Execution and GUI not aligned | I am using Eclipse CDT to debug a C++ project in Ubuntu. The GUI, i.e the small arrow showing the next line of source code to be executed, is not aligned with the actual execution. Specifically, it is about 30 lines below the actual executing line. I'm identifying what the actual line is by examining values of local va... | It seems pretty likely that the source that Eclipse is showing, and the source that was actually used to compile the executable are different versions of the same file.
You can ask GDB (Eclipse has a console window for GDB) what source was actually used to build the executable, and where GDB found the source it is show... |
7,065,446 | 7,065,524 | What is the sense of a shared_ptr to a container? | What actually is the point of declaring a boost::shared_ptr to a container like std::vector or std::list?
Here is an example utilizing BOOST_AUTO.
void someFunction()
{
...
BOOST_AUTO(sharedPtrToContainer, boost::make_shared<std::vector<T>>());
...
}
Is there any sense if you only need the container locally? Wha... |
What actually is the point of declaring a boost::shared_ptr to a container like std::vector or std::list?
Exactly the same point as using a shared pointer to any object type; it allows you to share ownership of the object with other scopes. It doesn't make any difference that the object happens to be a container.
Is... |
7,065,734 | 7,065,885 | Overload operator<< (unsigned char typedef as byte) | I want to overload (hijack?) ostream and basic_ostream<unsigned char> so that it stops attempting to display an octet (unsigned char) as a printable character.
I've been living with cout and friends putting smiley faces on the screen for far too long. And I'm tired of working around with casts: hex << int(0xFF & b) << ... | The problem is that there already is a
template<class charT, class traits>
std::basic_ostream<charT,traits>&
operator<<(std::basic_ostream<charT,traits>&, charT);
in namespace std. Since basic_ostream<> is also in this namespace, ADL picks it up when you output an unsigned char. Adding your own overload might make c... |
7,065,865 | 7,066,026 | combining 3 functors into 1 | I have 3 functors and was wondering if these can be combined into 1, perhaps as a template.
is it possible? if so, how would I do it. thx!
struct less_than
{
bool operator()(double prev,double curr) const
{
return prev<curr;
}
};
struct great_than
{
bool operator()(double prev,d... | If you mean, specialized by the operator, then the answer is, no, not at the language level.
Luckily, the STL already provides functors for this (std::equal_to, etc.). You can either use these directly, or use them as arguments to your own function classes.
|
7,065,926 | 7,069,038 | How to find maximum of each subarray of some fixed given length in a given array | We are given an array of n elements and an integer k. Suppose that we want to slide a window of length k across the array, reporting the largest value contained in each window. For example, given the array
15 10 9 16 20 14 13
Given a window of length 4, we would output
[15 10 9 16] 20 14 13 ---> Outpu... | This older question discusses how to build a queue data structure supporting insert, dequeue, and find-min all in O(1) time. Note that this is not a standard priority queue, but instead is a queue in which at any point you can find the value of the smallest element it contains in O(1) time. You could easily modify th... |
7,066,081 | 7,066,229 | UTF8 scrambling during c++ file loading | I know loading unicode is a somewhat laboured point, but I can't see how to apply the solutions presented to others to my particular problem.
I have a Win7/C++/DirectX9 GUI library which can render text to the screen. I've never had a problem before since it has only be used with Western European language. Now I have t... | Forget about wifstream, it's just too hard to make it work. Do:
ifstream f(L"data/language.ini");
string str;
getline( f, str );
guiTitle->SetText( utf8_to_utf16(str).c_str() );
And use MultiByteToWideChar to implement utf8_to_utf16.
See also https://stackoverflow.com/questions/1049947/should-utf-16-be-considered-ha... |
7,066,393 | 7,066,445 | Port to Linux, or write wrappers for MFC? | Is it easier to separate the core functionality of a program and port it to Linux, or to write wrappers around the MFC functionality to get the original MFC program running in Linux?
Example:
Take your basic dialog based MFC application (several dialog windows), get it to run under Linux command line without modifica... | Try compiling it against Winelib and you won't have to rewrite most of the functionality.
In the light of your comments, Given the time and resources I would definitely separate the source code in to well defined layers:
An OS/platform dependent layer,
An OS Abstraction Layer,
An OS independent middleware &
An UI layer... |
7,066,462 | 7,066,503 | Why am I getting this segmentation fault on solaris? | So to start off this code works on all my redhat machines and some other solaris machines. The machine that is producing the fault is a solaris 64 bit. The code I have is as follows:
This is the frUUID class:
frUUID::frUUID()
{}
std::string frUUID::genUUID()
{
char uuidBuff[36];
uuid_t uuidGenerated;... | You're not leaving space for the trailing null byte in uuidBuff.
|
7,066,499 | 7,066,599 | Substring of char* to std::string | I have an array of chars and I need to extract subsets of this array and store them in std::strings. I am trying to split the array into lines, based on finding the \n character. What is the best way to approach this?
int size = 4096;
char* buffer = new char[size];
// ...Array gets filled
std::string line;
// Find th... | I'd create the std::string as the first step, as splitting the result will be far easier.
int size = 4096;
char* buffer = new char[size];
// ... Array gets filled
// make sure it's null-terminated
std::string lines(buffer);
// Tokenize on '\n' and process individually
std::istringstream split(lines);
for (std::string ... |
7,066,669 | 7,066,774 | How do I make a critical section with Boost? | For my cross-platform application I have started to use Boost, but I can't understand how I can implement code to reproduce behavior of Win32's critical section or .Net's lock.
I want to write a method Foo that can be called from different threads to control write operations to shared fields. Recursive calls within the... | With boost you can use boost::lock_guard<> class:
class test
{
public:
void testMethod()
{
// this section is not locked
{
boost::lock_guard<boost::recursive_mutex> lock(m_guard);
// this section is locked
}
// this section is not locked
}
private:
boost::recursive_mutex m_guard;
};
PS These class... |
7,066,677 | 7,066,799 | Binary data structure for fast searching | I'm looking for a binary data structure (tree, list) that enables very fast searching. I'll only add/remove items at the beginning/end of the program, all at once. So it's gonna be fixed-sized, thus I don't really care about the insertion/deletion speed. Basically what I'm looking for is a structure that provides fast ... | Look up the Unordered set in the Boost C++ library here. Unlike red-black trees, which are O(log n) for searching, the unordered set is based on a hash, and on average gives you O(1) search performance.
|
7,066,691 | 7,066,805 | Is std::ofstream movable? | I have this map which compiles fine in MSVC10 :
std::map<std::string, std::ofstream> m_logFiles;
But on ubuntu using g++ 4.5 with C++0x enabled, I get the following error message :
/usr/include/c++/4.5/bits/ios_base.h|785|error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
By using pointers instead of ob... | std::ofstream is movable. This program compiles for me using clang/libc++:
#include <string>
#include <fstream>
#include <map>
int main()
{
std::map<std::string, std::ofstream> m_logFiles;
}
Reference 27.9.1.11 [ofstream.cons].
|
7,066,723 | 7,084,109 | Should I use boost::property_map? | (Apologies for the title, I couldn't come up with a good one shorter than 140 characters...)
I'm writing a graph algorithm for the boost::graph library. Within my algorithm, I need to keep variables, weights and counters, about the nodes. The typical way to do this, as far as I can tell from documentation and looking a... | In a nutshell, create a map m and an associative property map pm using m and you won't generate a redundancy. More information follows.
boost::associative_property_map does not create a new map. It only references another map and makes it accessible through the boost property_map API (get & put).
See the documented ex... |
7,066,768 | 7,066,988 | Filling CMediaType and IMediaSample from AVPacket for h264 video | I have searched and have found almost nothing, so I would really appreciate some help with my question.
I am writting a DirectShow source filter which uses libav to read and send downstream h264 packets from youtube's FLV file. But I can't find appropriate libav structure's fields to implement correctly filter's GetMed... | You have to fill the right fields with the right values.
The AM_MEDIA_TYPE should contain the right MEDIASUBTYPE for h264.
And these are plain wrong :
pvi->bmiHeader.biWidth = videoRect.right;
pvi->bmiHeader.biHeight = videoRect.bottom;
You should use a width/height which is independent of the rcSource/rcTarget,... |
7,067,362 | 7,069,929 | Heap allocation error within static library | I have a working Visual Studio project.
I've created a static library with the files of the original project (except main.cpp), also
I've created a "tester" project (with the static lib linked to it) with only a main.cpp file from the original project.
Both compiles without any relevant error.
And tester runs appropria... | The error is that you should be allocating wide chars when you call GetRawInputDeviceInfo. From the manual
RIDI_DEVICENAME 0x20000007
pData points to a string that contains the device name.
For this uiCommand only, the value in pcbSize is the character count
(not the byte count).
In other words you should write
w... |
7,067,793 | 7,067,805 | What is this crazy C++11 syntax ==> struct : bar {} foo {};? | What could this possibly mean in C++11?
struct : bar {} foo {};
| First, we'll take a bog-standard abstract UDT (User-Defined Type):
struct foo { virtual void f() = 0; }; // normal abstract type
foo obj;
// error: cannot declare variable 'obj' to be of abstract type 'foo'
Let's also recall that we can instantiate the UDT at the same time that we define it:
struct foo { foo() { cout ... |
7,067,947 | 7,076,722 | Can std::wfstream passed by-reference AND will I be able to use write() and read() properly? | I use a self-made error/log-class for my project which is also be able to store/load itself into/from a file. To make it easier for me when handling more objects I want to pass a file stream by-reference to this function which then uses the write/read member of the stream.
Save with:
in.open(L"XError.err",std::ios::in ... | ok, used another answer to bypass my problem in some way:
int main()
{
HLib::_ErrorSaveStruct Ess = {0}; // just a namespace
Ess.IsUNICODE = true;
Ess.errState = 100;
Ess.ItemCount = 9999;
wchar_t* StringTest[1] = {L"WOORD"}; // same like (wchar_t[5])
FILE* iobuf = NULL;
// create new in binary read-write mod... |
7,068,129 | 7,068,216 | How to make the compiler choose the non-template version of a method for derived classes? | I'm writing a matrix class (CMatrix), with such derived classes as a 3d vector(CVector) and a rotation matrix(CRotMatrix). My CMatrix object could be multiplied by an another CMatrix-based object or by an any numerical value(scalar).
This code represents the essence of the problem I got:
template<class T> class CMatrix... | The reason is that the template operator is considered an exact match while the matrix version requires a conversion to parent reference. Thus the compiler pick the template as a better match.
First consider if you really need the child classes that you've created and that they provide the appropriate functionality/ove... |
7,068,183 | 7,068,812 | Writing 10,12 bit TIFF files with LibTIFF C++ | I'm trying to write 10,12 bit RGB TIFF files with LibTIFF.
The pixel data is saved locally in an unsigned short buffer (16bits)
1) If I set TIFFTAG_BITSPERSAMPLE to 10 or 12, not enough bits are being read from the buffer, and the output is incorrect. (I understand that it is just reading 10 or 12 bits per component, i... | The TIFF specification does not specify a way to store 10, 12 or 14 bits per channel in an image. Depending on the encoder and decoder, it may still be possible to work with such images, but it is effectively an implementation detail, as they are not required to do this.
If you want more than 8 bits of precision in a T... |
7,068,260 | 7,068,363 | Global qualification in base specifier | As a follow-up to " What is this crazy C++11 syntax ==> struct : bar {} foo {};? ", I'd expect the following C++0x code to compile:
struct x {};
struct :::x {} y {};
However, GCC 4.7.0 20110731 tells me:
error: global qualification of class name is invalid before ':' token
And when I take a step back towards sanity ... | This is just to do with parsing. From §2.5.3
If the input stream has been parsed into preprocessing tokens up to a given character, the next preprocessing token is the longest sequence of characters that could constitute a preprocessing token, even if that would cause further lexical analysis to fail.
Basically, it... |
7,068,586 | 7,068,687 | C++ Link Error Missing GetTickCount And How To Debug | I have been refactoring some header includes, and all of sudden I am left with this (changed some namespaces and class names) link error:
Error 1 error LNK2001: unresolved external symbol "public: class ABC::DEF::JKL __thiscall ABC::GHI::GetTickCount(void)const " (?GetTickCount@GHI@ABC@@QBE?AVJKL@DEF@2@XZ) Server.obj
... | Nevermind, winbase.h is so nice as to
#define GetCurrentTime() GetTickCount()
|
7,068,785 | 7,068,813 | Why isn't this code printing my array? | I have an integer array sorting program here but I have a problem: whenever I run the program I sometimes get a "The stack around the variable 'numbers' was corrupted" message and sometimes it just repeatedly prints out the number 8. Here's my code (compiled in Visual C++ 2010):
#include <iostream>
#include <cstdlib>
u... | First, you never increment numToPrint, therefore you are never going to print more than the value of numbers[0]. At the very least change your code to:
while(loopIterator < size){
cout << numbers[numToPrint++] << endl;
loopIterator++;
}
Secondly, since your while loop uses the test i < size, you are, on the l... |
7,068,945 | 7,071,030 | Updating a Managed Form from unmanaged code in Visual C++ | I have a Windows Form that runs a test, EngTest_F(), when you click a button on the form. This function is called from a native DLL. I've also created a backgroundworker in the managed form code that calls a function GetSicStatusMsg to update a textbox in the form.
In my native EngTest_F function, I have functions that... | It seems like your code is backwards. The UI thread should update the UI, and the background thread should do the long-running task (I guess that's EngTest_F()). One way to approach this is with a System.Windows.Forms.Timer component. Set up a timer with Interval=50 or so, which calls GetSicStatusMsg() to update the UI... |
7,068,988 | 7,069,064 | Is Pointer Casting To Satisfy Method Params A Dangerous Thing To Do? | This might be rather simple but I have a method that expects a parameter to be of type
BYTE **Ptr
And for various reasons I am using an int* (we'll call intPtr for this example) in the code that will call this method, so I was wondering if it is safe to do this:
MethodCall((BYTE**) &intPtr, ...
The method locks... | In general, this is not "safe". Whilst a pointer-to-T may be converted to a pointer-to-U and back again, modifying it via the pointer-to-U is, at best, implementation-defined.
In your example, the method will modify your int * to point at some memory, but there's no guarantee that that it will choose some memory that ... |
7,069,144 | 7,070,370 | How to Compose OSGi Based project with C++ based project? | I am extending a project that it has been initiated with C++ language. Now I am developing a new part of the project. and it will be based on OSGi (Java).
Now I want to know is there any stable method to compose the old project with new part? Is there any steps that can convert C++ objects to OSGi bundles (or with simi... | Although it isn't C++, but plain C, you might check out Apache Celix. Apache Celix is an implementation of the OSGi specification in C, without a dependency to any Java implementation or such. Currently Celix is still in the incubation phase.
Regarding communication between C and Java, one of the items on the (short te... |
7,069,386 | 7,159,597 | SkypeKit to make PC to phone calls | Can someone tell me if its possible to use the skypekit api to write a c++ win32 console application to make pc to phone calls only(nothing else) on windows 7 64 bit?
| I'm working on some stuff with the SkypeKit API and it should definitely be possible. There's an example application included that has the basic functionality for doing it.
|
7,069,456 | 7,069,577 | Is there a pragma directive for include directories? | As the title says: Is there a pragma directive for include directories using VS20** C++? I think about something like:
#pragma comment(include, "..\externals\blah\includes\")
So that I can use includes in this style, and blah.h also can use this style inside?
#include <blah.h>
I know that I can set include directorie... | I don't think there's any way to do this. include_alias is only useful on a file-by-file basis.
|
7,069,565 | 7,069,922 | How come allegro automatically handles minimize button, but not close button? | Here is a sample from Allegro5 tutorial: (to see the original sample, follow the link, I've simplified it a bit for illustratory purposes.
#include <allegro5/allegro.h>
int main(int argc, char **argv)
{
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
al_init()
display = al_create_... | Disclaimer: I don't know Allegro.
Minimizing a window at the most basic level only involves work from the process that deals with the windows (the Window Manager), not the process itself.
Terminating a program, usually requires files to be closed or memory to be freed or something else that only the process itself can ... |
7,069,614 | 7,069,931 | Why doesn't std::generate return state similar to std::for_each? | std::generate returns void:
template<typename ForwardIterator, typename Generator>
void generate(ForwardIterator first, ForwardIterator last, Generator gen);
While std::for_each returns Function:
template<typename InputIterator, typename Function>
Function for_each(InputIterator first, InputIterator last, Function f);... | One significant difference is that whilst for_each operates on the container content, generate simply overwrites it. So the function object passed to generate can collect no information about the container content, so there'd be little reason to return it afterwards (its final state is invariant of the container conte... |
7,069,653 | 7,069,732 | dynamically monitor program status | In Unix systems, it is possible to dynamically monitor the system by reading data from /proc. I am hoping to implement this kind of monitoring in my application, by dynamically saving "current status" into a file. However, I do not want IO delay my program, so it would be best to make the file virtual, i.e. not stored ... | Why not used shared memory and semaphores. Do a 'man shmget' as a starting point.
|
7,069,986 | 7,070,671 | compare-and-swap atomic operation vs Load-link/store-conditional operation | Under an x86 processor I am not sure of the difference between compare-and-swap atomic operation and Load-link/store-conditional operation. Is the latter safer than the former? Is it the case that the first is better than the second?
| x86 does not provide LL/SC instructions. Check out wikipedia for platforms that do. Also see this SO question.
|
7,070,105 | 7,070,126 | how to test whether auto pointer is null? | I'm new to auto pointer. I have this:
std::auto_ptr<myClass> myPointer(new MyClass(someArg));
How do I test whether I can instantiate myPointer successfully? I tried if (myPointer==NULL) and the compiler emitted an error:
no operator "==" matches these operands.
| What do you mean by "instantiate"?
On a standard-compliant implementation, either the construction of the MyClass succeeded, or an exception was thrown and the auto_ptr will no longer be in scope. So, in the example you provided, the value of the pointer represented by your auto_ptr cannot be NULL.
(It is possible that... |
7,070,165 | 7,070,204 | How to create an operator that copies one array to another in c++ | I need to create an operator that will copy the contents in one array to another. A.K.A an equal operator. I am thinking something along these lines:
operator=(string array[10][10], string array2[10][10])
{
int row = 0; int column = 0;
for(column=0; column<=9; column++)
{
fo... | You can't. For two reasons
An array is a built in type, operator overloading is allowed only if at least one of the arguments is a user-defined type
operator = is one of the 4 operators (along with [], (), and ->) that have to be members of the class that they are overloaded for1. An array is not a class.
What you ca... |
7,070,192 | 7,070,277 | Class implementation in a header file == bad style? |
Possible Duplicate:
In C++ why have header files and cpp files?
I was wondering if it is advisable to write a the whole class c++ in a header file ? and use include to include the class, in a similar way that java does its oop programming. Is it a bad style ? can anyone recommend me a "good" C++ oop style guide ? Al... | Including function definitions in a header file has some knock on effects and it's generally avoided. Functions defined in this manner are likely to be inlined, which will increase the size of your executable which can effect performance (in a positive or a negative way). Also, doing this can increase your build time... |
7,070,242 | 7,070,283 | Using same variables in several functions | In my code, due to efficiency consideration, I place a long function in it's own file (let's name it a.cpp). I have also created a second file named b.cpp which holds another function which uses the same variables names.
I have tried to create a header file for those variables but it didn't work. Is there a way to d... | Write extern double s; in both (or in a header). This is a declaration without being a definition.
Then write double s; in just one .cpp file — this is where the double object will physically "live".
More here.
|
7,070,346 | 7,070,383 | C++ Best way to get integer division and remainder | I am just wondering, if I want to divide a by b, and am interested both in the result c and the remainder (e.g. say I have number of seconds and want to split that into minutes and seconds), what is the best way to go about it?
Would it be
int c = (int)a / b;
int d = a % b;
or
int c = (int)a / b;
int d = a - b * c;
o... | On x86 the remainder is a by-product of the division itself so any half-decent compiler should be able to just use it (and not perform a div again). This is probably done on other architectures too.
Instruction: DIV src
Note: Unsigned division. Divides accumulator (AX) by "src". If divisor
is a byte value, result is... |
7,070,366 | 7,070,664 | Design problem: Updating database from a low latency C++ application | I am developing a low latency application in C++. I also need to update the databases of my processing and all state changes. In order to save on latency involved in calling Database updates, I am using local data structures (in-memory) in my application.
But I still need to update databases also. Should I use a separa... | For minimal latency, you'll definitely want a database thread (I"ll call it DBT).
However, if updates are frequent, you'll want to buffer changes, and have the DBT merge whatever updates it can before they get pushed to the actual database. If player.x = 1, then player.x = 2, the DBT can skip the first one.
If updates... |
7,070,740 | 7,139,738 | Pool Garbage Collection Strategy | I'n my application I'm using pools to speed up allocation of certain types of resources:
e.g.
tbb::concurrent_unordered_map<size_t, tbb::concurrent_bounded_queue<resource>> pools;
std::shared_ptr<resource> create_resource(size_t size)
{
auto pool = pools[size];
std::shared_ptr<resource> resource;
if(!pool... | I solved it by keeping statistics of pool usage and flush it every second.
|
7,070,814 | 7,070,845 | API method for getting window's controls | I've searched quite a while in MSDN, couldn't find it.
In fact, I don't even know how controls are called in API. they are not declared as a "Window", right? (No hwnd for them, I wasn't sure because I saw a method which seemed like it could return a control but it returns an hwnd.)
So lets say I have a window's handle.... | They're called Windows and HWNDs are handles to these windows, just like a fopen() returns a handle to a file.
These are all the functions you'll need. Try EnumChildWindows
|
7,070,940 | 7,071,027 | Linux and Solaris Unix : Coredump at the end of a function | We are observing a core dump quite randomly, under heavy load conditions. When we load the core file and look at the location of the core dump it is always pointing to the last line of the function, precisely the line number of the closing brace.
The function has some legacy goto statements. When we had similar issue... | I suspect you're overrunning a buffer in a growing-downwards stack (most stacks grow downwards; I don't know whether Linux or Solaris use downwards stacks on all architectures, but definitely some of them). At this point, it overwrites the return address, and the program counter jumps to an illegal address, generating ... |
7,071,106 | 7,073,367 | Sub-classing QCompleter, virtual slot in my sub-class not being called | I am sub-classing QCompleter to give it some special functionality. I want activated() to be fired when there is only one completion in the model with the given prefix, but that's not where I'm having a problem.
I have created a virtual setCompleterPrefix() in my sub-class but the compiler doesn't seem to notice it. In... | You can use the model returned by QCompleter::completionModel() and its signals to track the completion count:
InstantCompleter::InstantCompleter(QObject* parent) :
QCompleter(parent)
{
connect(completionModel(), SIGNAL(layoutChanged()), SLOT(completionModelChanged()));
}
// declared in the "private slots:" se... |
7,071,168 | 7,071,219 | Why does the C++ compiler give errors after lines instead of on them? | This question popped into my head today at work when I was having yet another domestic affair with my compiler. Despite my buff pinky (due to all the semicolon pressing I do at work), I managed to miss one before an if statement. Obviously, this resulted in a compile error:
error C2143: syntax error : missing ';' be... | The short answer to the more general question of "Why do C/C++ error messages suck" is "Sometimes C++ is really hard to parse" (it doesn't actually have a context free grammar). However, this isn't really a valid reason - one can still make tools that record better diagnostic information than most C++ compilers.
The mo... |
7,071,199 | 7,071,216 | G++ doesn't compile C++0x range-based for loop | I was experimenting with some of the new C++0x features with G++. Lambdas, auto, and the other new features worked like a charm, but the range-based for-loop failed to compile. This is the program I was testing:
#include <iostream>
#include <vector>
int main ()
{
std::vector<int> data = { 1, 2, 3, 4 };
for ... | You need GCC 4.6 and above to get range-based for loops.
GCC's C++0x status
$ cat for.cpp
#include <iostream>
int main()
{
for (char c: "Hello, world!")
std::cout << c;
std::cout << std::endl;
return 0;
}
$ g++ -std=c++0x -o for for.cpp
$ ./for
Hello, world!
$ g++ --version
g++ (GCC) 4.6.1 20110325 (prereleas... |
7,071,257 | 7,071,298 | Format timeval into "best units" | I am trying to write a benchmark program that takes about 20 minutes to complete because the actual functions need to be called at least 50 times.
I used the following code:
struct timeval start, end;
long mtime, seconds, useconds;
gettimeofday(&start, NULL);
usleep(2000);
gettimeofday(&end,NULL);
seconds =end.tv_sec -... | My guess is that your "best unit" requirement is basically "human usable units." If so, take the time and
millisecs mod 1000 gives number of milliseconds
millisecs div 1000 gives seconds (where div is integer division)
seconds mod 60 gives number of seconds
seconds div 60 gives minutes
and so on.
|
7,071,376 | 7,071,416 | Types conversion between different types in an implicit manner | I need an in implicit conversion from A* to C*;
i cannot change A's definition or implementation.
class A
{
};
struct B: public A
{
};
struct C: public B
{
};
when i write the following:
A* p;
C* q = p;
i am getting an error C2440; cannot convert from A* to C*.
what can i do giving the fact i cannot change A. both... | The only way you can do this is to use a cast:
// a C++ style static_cast:
C* q = static_cast<C*>(p);
// or the less verbose C-style cast
C* q = (C*)p;
Because C is a derivative of A and not every A is a C, it cannot be implicitly casted (like you could implicitly cast a C* to an A* because every C is an A (i.e. A ha... |
7,071,387 | 7,073,750 | Invalid write size of 4 with matrix class (using valgrind) | I have a simple matrix class I've made for use with opengl (es 2.0, afaik there isn't any built in version for that particular version of opengl).
It is basically nothing more than a vector which is resized to contain 16 floats in the constructor, (I chose a vector over just a 16 float array for the = operator it had),... | It's pretty clear from the snippet of Valgrind report you posted that you are accessing dangling storage for a vector.
Such access could easily arise if one thread is iterating over a vector, while another thread has resized it. For example, this is unsafe:
for (vector<float>::iterator it = matrix.begin(); it != matrix... |
7,071,437 | 7,071,462 | C++0x lambda vs blocks | I was exploring C++0x today, and I encountered the new lambda feature. My question is how are these different (in terms of use) from blocks and why might one prefer one over the other?
Thanks.
|
there is a a short syntax with C++0x lambdas to take every variable in
scope by reference. ([&]) The type of a lambda is also unspecified,
allowing potentially more optimal code.
Now, when you look at Apple blocks, it will require __block specifiers
added to variables you want to modify (the very fact that this ... |
7,071,497 | 7,146,423 | Problems with reading data from QTcpSocket | I've modified the threaded fortune-server from Qt examples.
The client connects to the server and then sends a header to authenticate.
tcpSocket = new QTcpSocket();
tcpSocket->connectToHost(addr, port);
QByteArray block = "someheader";
int x = tcpSocket->write(block);
qDebug() << x;
The client seems OK here and qDebug... | You can't use slots or socket signals with a thread without calling QThread::exec() to start an event loop within that thread/the run function.
Since your checkBytes slot belongs to QThread, it wouldn't be executed by the thread (there is a detailed article about QThreads here)
The closest example that seems to already... |
7,071,671 | 7,071,695 | Inheritance by dominance - is it really bad? | I'm one of those people that has to get their code to compile with 0 warnings. Normally I respect the compiler and if it issues me a warning I take it as a sign that I should touch up my code a little. If I have to tell a compiler to ignore a given warning, I twitch a little.
But this one I can't seem to get around, an... | When performing virtual inheritance, it is a bad idea to not explicitly override every member in the most derived class. Else, you are asking for your code to die a horrible death when someone changes one of your base classes that inherits from the virtual base. There's nothing actively wrong with this, your program wo... |
7,071,769 | 7,071,813 | Allegro compile error: undefined reference to "PathFindOnPathA@8" | I have set up Allegro 5.0.4 with MinGW 4.5.2 and I am using the GUN GCC compiler with Code::Blocks.
When I attempt to compile this:
#include <stdio.h>
#define ALLEGRO_STATICLINK
#include <allegro5/allegro.h>
int main(int argc, char **argv){
ALLEGRO_DISPLAY *display = NULL;
if(!al_init()){
fprintf(... | See this:
http://www.allegro.cc/forums/thread/608101/928306#target
When you static link, if you get an undefined reference, just Google the function name (PathFindOnPath) and look up the library it needs. In this case it is "Shlwapi.lib".
Or, I suppose it's libshlwapi.a on MinGW.
That is: add that library to your l... |
7,071,971 | 7,072,016 | Simply including SDL header causes linker error | I was going to migrate my game from glut to sdl.
It's working perfectly in glut but I wanted to use some sdl features.
So I go into my project properties, under the targets header I click the program that will be compiled, build phases, link binary with libraries, add SDL.framework
The exact same as I have done for Ope... | SDL uses a macro to rename your main(..) and should supply its own, usually implemented in SDLmain.m. It should be supplied together with the SDL.framework.
When you download the framework from here http://www.libsdl.org/download-1.2.php Read the ReadMeDevLite.txt in the devel-lite folder.
Another description
http://... |
7,072,329 | 7,072,351 | C++: Using a string parameter passed in to access something in a type | My goal is to access a class that is passed in as a parameter inside of myFunction.
Here's what I'm trying to do:
void myFunction(string myString)
{
callFunctionOn(OuterType::InnerType::myString);
}
I'm trying to call some function on something that's in a type. For example, my code in some other file might look ... | C++ doesn't have reflection built in, but it does have pointers to data, functions, and class members. So you can use a std::map or unordered_set to find the pointer with a particular name (you have to add all the name/pointer pairs into the map beforehand).
Your solution is likely to look something like:
namespace Ou... |
7,072,437 | 7,072,463 | compilation error in C++ | I have the following code in C++ and I got the compilation error:
a.cpp: In member function `virtual void Derived<T, D>::run(T&)':
a.cpp:13: error: expected primary-expression before "int"
a.cpp:13: error: expected `;' before "int"
Please help me find out what went wrong here. Thanks a lot.
#include <iostream>
templat... | In Derived<>::run(), change
d.operator()<int>();
to
d.template operator()<int>();
For further information, see this FAQ:
What is the ->template, .template and ::template syntax about?
|
7,072,567 | 7,072,655 | error LNK2019: unresolved external symbol - what am I doing wrong? | When I try and build my project I get the following errors:
1>Assignment1CoreTest.obj : error LNK2019: unresolved external symbol "struct point * __cdecl findLongPaths(struct point *,double)" (?findLongPaths@@YAPAUpoint@@PAU1@N@Z) referenced in function "public: void __thiscall Geometry_CoreUnitTest::test_method(void)"... | you are getting linker error.
Most probably you are not generating the object code for Geometry.cpp
this would work for now:
create an empty project;
copy the header files in the headerfiles folder
copy the cpp files in the cpp files folder
then build the project;
this will build your Geometry.cpp program as well.
|
7,072,768 | 7,073,225 | What is the canonical way to make a function accept any permutation of its argument list? | Suppose I have
class A,B,C;
const A a_def;
const B b_def;
const C c_def;
void f(A a=a_def, B b=b_def, C c=c_def);
This does, if I want to use the default parameters, only allow me to omit either just c, or b and c, or all three of them – but not just a or b alone. However, as the argument types cannot be mixed up, i... | Look into the Boost.Parameters Library. It uses some template heavy lifting to get it to work. http://www.boost.org/doc/libs/1_37_0/libs/parameter/doc/html/index.html
It works basically by making your 'named' parameters into types that can be created, and assigned.
|
7,072,893 | 7,075,351 | The problem of attachconsole | I need to make a windows GUI application can run in console, so I attach the console to the process when the application is invoked with a command line. However, after the application exit, the console prompt with the path doesn't show unless the ENTER key is pressed. Is there any way that the prompt with the path can ... | Short answer: This is not possible.
Long answer: Well, it is sort of possible if you are willing to relax your requirements a little bit. You basically have three options:
What you have done already. You can attach GUI application to a console but cmd.exe will not wait for your application to exit.
Create a GUI applic... |
7,073,053 | 7,073,104 | is there prettier syntax for a c++ iterator? | Is there a prettier / less-verbose way to use iterators in C++? From the tutorials I've seen, I either set up typedefs everywhere (which gets tedious to do for a lot of one-off for-loops):
typedef std::vector<std:pair<int, int> >::iterator BlahIterator;
or have verbose-looking for loops like:
for (std::vector<std:pair... | With boost, you can use the FOR_EACH macro.
typedef pair<int, int> tElem;
BOOST_FOREACH( tElem e, aVector )
{
cout << e.first << " " << e.second << '\n';
}
|
7,073,194 | 7,073,203 | Why can't arrays be passed as function arguments? | Why can't you pass arrays as function arguments?
I have been reading this C++ book that says 'you can't pass arrays as function arguments', but it never explains why. Also, when I looked it up online I found comments like 'why would you do that anyway?' It's not that I would do it, I just want to know why you can't.
|
Why can't arrays be passed as function arguments?
They can:
void foo(const int (&myArray)[5]) {
// `myArray` is the original array of five integers
}
In technical terms, the type of the argument to foo is "reference to array of 5 const ints"; with references, we can pass the actual object around (disclaimer: term... |
7,073,215 | 7,073,612 | Box2d - spawning bodies ontop of eachother | is it possible to spawn objects in the same location, but make their bodies not join together?
Basically i have a bunch of b2bodies that i spawn at a given time, and i need them to bounce off each other rather than stick to each other..
So this would create a sort of explosion of the created bodies because they repel... | Based from my experience, dynamic bodies with single fixtures would immediately repel each other the moment their physics simulation steps begin. Bodies with multiple fixtures would have problems if their fixtures crisscross each other because they would stick together.
I'm not sure if you can get explosion this way, b... |
7,073,344 | 7,078,061 | boost::spirit char/string mixing | I'm trying to get a handle on using boost::spirit to parse character tokens, and am having great difficulty. Here is the sample code I'm working on:
#include <boost/spirit/include/qi.hpp>
#include <iostream>
#include <string>
using namespace std;
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::asci... | For rules, attribute always need to be specified using the function declaration syntax:
qi::rule<Iterator, char(), ascii::space_type> tok1;
qi::rule<Iterator, char(), ascii::space_type> tok2;
which should solve your compiler problems.
Wrt your permutation problem: I'd suggest to do something like:
rule<Iterator, str... |
7,073,524 | 7,073,560 | C++: Using function pointers with member functions | I'm trying to pass a function to another function as a parameter, and they both happen to be member functions of the same class.
I'm getting a weird error and I can't figure out what the problem is.
Here are my functions:
void myClass::functionToPass()
{
// does something
}
void myClass::function1(void (*passedFunc... | You can pass function pointers to member functions. But that is not what your code is doing. You are confused between regular function pointers (void (*passedFunction)() is a regular function pointer) and pointers to member functions (&myClass::functionToPass is a pointer to a member function). They are not the same th... |
7,073,566 | 7,073,638 | Shared memory API, where a process can attach shared memory to other process | Can any one look into this and suggest me with an API.
We have APIs for a process which can create and/or attach a shared memory to its own process. But I don't find an API to attach a shared memory to one process by other process(for e.g., process A should call one API(like shmat()) to attach the shared memory to proc... | Shared memory doesn't belong to any particular process (unless you create it with a private IPC_PRIVATE key). It belongs to the system.
So, when you use shmget with a non-private key (and the IPC_CREAT flag), you will either create a shared memory block or attach to an existing one.
You need a way for both processes to... |
7,073,598 | 7,073,621 | How to resolve LNK2001 | I have a set of code written in VS 6. I am trying to write a CLI wrapper for that in VS 2008. I included one of the VS6 header files in the CLI code and compiled. While compiling I am getting LNK2001: unresolved external symbol "public: virtual void __thiscall Someclass::SomeMethod(SomeObject& os). When I searched fo... | Sounds like you've not included 'CPP File' in your project. That would also explain why you don't get an error when you have two bodies. To check this try putting a deliberate compile error in CPP File. If the compiler doesn't complain that would prove that you aren't compiling CPP File.
|
7,073,691 | 7,073,729 | C++ Snippet to C# Bitwise Operators | I am having a hard time porting this part of C++ to C#. I keep getting Operator '||' cannot be applied to operands of type 'long' and 'long' which makes sense. So what would the equivalent be?
while ((c <= combinations) && ((round_set & (1 << cList[c].one)) || (round_set & (1 << cList[c].two)) || (cUsed[c])))
... | C++, unlike C#, lets you treat an integer value as if it were a boolean value, ad-hoc, where any integer 0 is false, and any integer other than 0 is true. C# does not allow this.
To achieve the same effect in C# you must explicitely perform the check I just described, so instead of
if( (expr) || ... ) { }
you want
if(... |
7,073,793 | 7,073,819 | How to initialize const / non-const static reference member? | class Foo {
private:
int m_i;
public:
Foo(int i) : m_i(i) {}
};
class FooA
{
private:
const static Foo & m_foo;
static Foo & m_foo2;
};
Q1> how to initialize const static reference?
Q2> How to initialize non-const static reference?
Note:
You can make changes for class FooA in order to illustrate the ... | In the same way you initialize non-reference static members:
//Foo.cpp
const Foo & FooA::m_foo = fooObj1;
Foo & FooA::m_foo2 = fooObj2;
where fooObj1 and fooObj2 are global variables of type Foo.
Note fooObj1 and fooObj2 must be initialized before m_foo and m_foo2, otherwise you might face static initialization orde... |
7,073,916 | 7,073,936 | printing two adjacent values returned from adjacent_find | I want to print the first 2 values where the next is doubled from the current value.
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
bool doubled (int x, int y) { return x*2 == y; }
int main()
{
deque<int> di;
deque<int>::iterator diiter;
for (int i=0; i<=10; i+=2) di.insert(di.e... | Your program is giving strange results because it does not take in to account the fact, that order of evaluation of arguments to a function(In this case operator <<) is Unspecified.
My Answer here, explains the problem in detail & should be a good read.
You need to cout them on separate statements.
cout << "found " <<... |
7,073,927 | 7,073,970 | Applying texture without coordinates | Is there any way to apply the texture to an object without specifying texture coordinates?
| In fixed-function OpenGL, you can generate texture coordinates by activating texture coordinate generation modes. There are a couple of fixed algorithms (spherical coordinates, reflection coordinates), and there is one that multiplies a vertex component by a 4x4 matrix to generate a texture coordinate.
In shaders, you ... |
7,074,471 | 7,074,519 | Using boost::intrusive_ptr with a nested classes | Specifically, I need to declare (as I understand it) intrusive_ptr_{add_ref,release} as friends of my referenced class:
#include <boost/intrusive_ptr.hpp>
using boost::intrusive_ptr;
class Outer {
public:
//user-exposed interface goes here
protected:
class Inner {
public:
Inner():refct(0){}
... | You don't have to put them in namespace boost, you can put them in the same namespace as your class Outer and they'll be found through argument dependent lookup.
Every new intrusive_ptr instance increments the reference count by using an unqualified call to the function intrusive_ptr_add_ref, passing it the pointer as... |
7,074,797 | 7,074,903 | Get top 5 algorithm from a container? | I have a class(object), User. This user has 2 private attributes, "name" and "popularity". I store the objects into a vector (container).
From the container, I need to find the top 5 most popular user, how do I do that? (I have an ugly code, I will post here, if you have a better approach, please let me know. Feel free... | You can use the std::partial_sort algorithm to sort your vector so that the first five elements are sorted and the rest remains unsorted. Something like this (untested code):
bool compareByPopularity( User a, User b ) {
return a.GetPopularity() > b.GetPopularity();
}
vector<Users> getMostPopularUsers( const vector... |
7,074,934 | 7,077,029 | GetTimeZoneInformation equivalent in ubuntu? | i am using GetTimeZoneInformation in windows...but not able to find any equivalent in linux.
Any idea??
| i figured it out after some more debugging time related structures.
Its better to use struct tm * gmtime ( const time_t * timer ) which wll give the UTC time.
And can use tzset() and tzname[0] to get the timezone info.
|
7,074,941 | 7,075,136 | Qt in Windows: build environment and redistribution problems | I want to ask your opinion about one specific aspect of endless "Qt vs wxWidgets" question. Using wxWidgets in Windows, I may continue to work with my prefered build tools and compilers (in my case, Visual Studio). I only need to add wxWidgets include and lib directories to the compiler/linker path. When necessary, I j... | You can use Visual Studio. There is a Visual Studio integration plugin that makes it a lot lot easier to develop with Qt in Visual Studio.
As for the wxWidgets vs Qt debate... I use both (on different projects). I have to say that I would rather use Qt - it has fewer bugs IMO and in general there is an easier workaro... |
7,075,034 | 7,075,079 | Cocoa: get path to Contents/Resources folder in cocoa bundle | I am aware of how to get a specific file from the Resources folder in cocoa, i.e. :
NSBundle* myBundle = [NSBundle mainBundle];
NSString* myImage = [myBundle pathForResource:@"Seagull" ofType:@"jpg"];
anyways, I'd like to have a simple function that gives me the path to the Resources folder so I can use it in c++ like... | If you ever wonder if an Apple-provided class has a certain method, do look up Apple's own documentation before asking the question here at SO.
In this case, the answer is this method. But let me reiterate:
If you ever wonder if an Apple-provided class has a certain method, do look up Apple's own documentation before ... |
7,075,126 | 7,075,237 | Getting a substream of a stringstream effectively | I need to implement a mechanism where I can initialize a vector of my custom class using a text source, where each line of the source is representing one instance of my class. To achieve this, I implemented the operator >> for my class and stringstream. When I read the source, I go line-by-line and get a substream of m... | One obvious alternative would be to have your operator>> do line-by-line reading itself, so you don't have to do that externally:
class MyClass {
// some sort of data to demonstrate the idea:
int x;
std::string y;
friend std::istream &operator>>(std::istream &is, MyClass &m) {
std::string tem... |
7,075,214 | 7,075,399 | how to makefile with iostream, string and ifstream library | I'm trying to build a makefile for an application that use the lib string iostream and fstream.that's what I did up to now
CPP = gcc
LIB_DIR = ./incl
PROGRAMS = test
PROGS_O = action_rec.o
CPPFLAGS = -I$(LIB_DIR) -pg -g
VPATH = ./src/
OBJFILES = $(V... | Try taking all the -lstring -stdlib -liostream -lfstream out and see if it fixes it.
And compile with g++ so it finds other things it needs to link C++ code.
|
7,075,429 | 7,076,154 | "Expected unqualified-id before 'namespace'" error | I have the following seemingly innocuous piece of code:
#ifndef UI_H
#define UI_H
#include <string>
namespace ui
{
//Displays the main menu, showing loaded vocabulary cards
//
//Returns upon completion of display
void displayMainMenu();
//...More code like the above, just comments followed by fun... | One way to track down such errors is to start from the ground up:
#include "filepath/ui.h"
int main () { return 0; }
Does this compile? (This works fine with the little snippet of ui.h that you supplied.)
Errors like these are often caused by a missing semicolon on some previous class declaration. So let's try to forc... |
7,075,501 | 7,075,669 | How to select a single overload of a function with using namespace::function in C++? | consider the following C++ code.
namespace A {
void f() { // first function
}
void f(int) { // second function
}
}
...
using A::f; // introduces both functions
Is there a way to introduce only one function?
| That behavior is well-defined in the Standard.
C++03 7.3.3 The using declaration:
"...If the name is that of an overloaded member function, then all functions named shall be accessible.".
|
7,075,603 | 7,086,454 | Using an unordered_map where Key is a member of T | Is there any nice way to use an unordered_map so that you can access objects by a member variable in constant time (average case)? The following example has this functionality but requires the name of each Person to be duplicated as the Key:
#include <iostream>
#include <string>
#include <unordered_map>
#include <algor... | If you're not opposed to using Boost, then Boost.MultiIndex makes this extremely simple without adding any needless inefficiency. Here's an example that effectively creates an unordered_set of Person objects that is keyed on the value of Person::getName():
#include <string>
#include <iostream>
#include <boost/multi_ind... |
7,075,916 | 7,076,138 | Having trouble with Connectivity | Q.1.2 List all the different ways to connect two different objects for the input/output in the table below:
Input | Output | Not Output (Connection Already Established)
3-4 3-4
4-9 4-9
8-0 8-0
2-3 2-3
5-6 5-6
2-9 ... | As you describe it I would say
Your table describes a graph:
3<->4
4<->9
etc...
Now given 2 nodes (2 numbers) you need to find all the path from one to another. I guess you can look at this post for an optimise way to find all the paths :
Graph Algorithm To Find All Connections Between Two Arbitrary Vertices
|
7,076,169 | 7,076,312 | "not declared in this scope" error with templates and inheritance | Here is code sample which reproduces my problem:
template <typename myType>
class Base {
public:
Base() {}
virtual ~Base() {}
protected:
int myOption;
virtual void set() = 0;
};
template <typename InterfaceType>
class ChildClass : public Base < std::vector<InterfaceType> >
{
public:
ChildClass() {}... | myOption is not a dependent name, i.e. it doesn't depend on the template arguments explicitly so the compiler tries to look it up early. You must make it a dependent name:
template <typename InterfaceType>
void ChildClass<InterfaceType>::set()
{
this->myOption = 10;
}
Now it depends on the type of this and thus o... |
7,076,282 | 7,076,319 | C++ Overloading : Overloading the [][] operator | The question is whether it is possible to overload [ ][ ] .
Well in normal circumstances like vector< vector < int > > , we are overloading the [ ] opertor .
But in cases where if define a special meaning to [ ][ ] is it possible to have such an operator
| There is no special [][] operator; it's operator[] applied to the result of another operator [].
You can give special meaning to [][] construct by having the first operator returning a special temporary object, which also has [] operator.
|
7,076,340 | 7,076,452 | will registry key take default value upon setting invalid value | I am setting a registry key with invalid value (setting a REG_DWORD key value with a REG_SZ). Will registry hold the value which it was having it before or will it reset it to its default value?
For example. I have set REG_DWORD key and have set it to value '4'. Default value of this key is '2'. Now when i try to set t... |
RegSetValueEx Sets the data and type of a specified value under a registry key.
It will just change the type of the stored value to REG_SZ and set the value you specified, it doesn't check what value or type there were before. So when you read the value you'll get the last value you set there. There's no such thing a... |
7,076,869 | 7,076,986 | Problem with SetCapture and IWebBrowser2 container | I have an OLE object of IWebBrowser2 wrapped in a window.
At some point I expand the window and its OLE object and I'd like it to collapse on external click (i.e. every click that is outside the web browser).
I use SetCapture on the window wrapper but from some reason, during the capture, the Webbrowser doesn't receiv... | Cite from SetCapture:
Sets the mouse capture to the specified window belonging to the
current thread. SetCapture captures mouse input either when the mouse
is over the capturing window, or when the mouse button was pressed
while the mouse was over the capturing window and the button is still
down. Only one window ... |
7,077,297 | 7,077,379 | Array of virtual functions | When reverse engineering and using external classes I often try to redefine those classes in my library:
class GameEngine // Exported with "GetGameEngine"
{
public:
virtual void foo1() = 0;
virtual void foo2() = 0;
virtual void foo3() = 0;
virtual void foo4() = 0;
virtual void foo5() = 0;
virtua... | Look at boost::preprocessor, specifically at its REPEAT macro. Something like this should work:
#include <boost/preprocessor/repetition/repeat.hpp>
#define FUNC(fun_z, fun_n, fun_data) virtual void foo ## fun_n () = 0;
#define FUNCTABLE(count) BOOST_PP_REPEAT(count, FUNC, 0)
|
7,077,528 | 14,027,412 | Qt : Unable to load TTF file | I have a Qt-embedded application that I develop in OpenSuse 11.4 where I need to load a TTF font file. However when I call int QFontDatabase::addApplicationFont() function, it's returning -1.
Upon reading the documentation, I found out that adding application fonts on Unix/X11 platforms without fontconfig is currently... | You can use QPA or Qt Platform Abstraction (formerly known as Lighthouse). You need to create an implementation (could be made as a plugin or just being used directly) of QPlatformIntegration which exposes a custom QPlatformFontDatabase. The trick here is to reuse much of Qt's existing implementation of QFontconfigData... |
7,077,534 | 7,077,655 | How do I go about this program? | I have a program that has a lot of .cpp, .h and .dfm files. I have just recently started learning about Visual C++ with MFC. The program doesn't have any .ncb or solution object files, because of which I am unable to understand as to how to start understanding the program. There are lots and lots of files and its quite... | Some tips:
Use the Find in Files button to find the characters main. If you find a main(), an _tmain(), or a WinMain this will tell you a lot about what you have. If there's an exe, run it - that will show you what to look for also.
Visual Studio 2010 has an option to create a solution from source files, so that may al... |
7,077,624 | 7,078,536 | Generating dynamic call graph of c/c++ programs on the run | If one were to visualize the running of a program, I suppose one would start by getting the call graphs of the program.
But how would you get the call graph of c/c++ programs while on the run?
edit: clarifications, I'm currently running things on linux, using g++, but I suppose I am also curious about solutions if I'm ... | I've used etrace to trace executions of programs.
Egypt does the same thing, but only has a limited support for C++.
Both requires the program to be instrumented with gcc.
|
7,077,756 | 7,077,932 | Failed Reference to IID_ICorProfilerInfo | I am trying to build a custom .NET profiler using the Profiling API and I am having an issue with the references in the project. I am not a C++ engineer, so please bear with me.
I have created a simple COM server in Visual Studio 2010 in an ATL Server project. Everything builds fine, up until I add the code to query ... | You're probably missing the linkage to corguids.lib, which holds the actual definition of IID_ICorProfilerInfo (in corprof.h it's only declared as extern). In the sample you mention, see Building the Source Code.
|
7,077,780 | 7,077,891 | C++ opencv app in C# window | i'd like to add to my C# window with processed image from my webcam (live webcam streaming).
As far I know, opencv library is for C++.
I've found how to run C++ app from C#, but i don't know how to do streaming in C# form window.. any suggestions?
| Maybe you should take a look at this other thread:
.Net (dotNet) wrappers for OpenCV?
It may be easier to use a wrapper of OpenCV for your case.
|
7,077,798 | 7,079,212 | Can I ask an iostream if it is writeable? | In my code I am passed a reference to an iostream, that in this case is ultimately a file.
Is there any way to find out if, when it was opened, it was set to [in|out] not just [in]?
| After looking at all the members of IOS, iostream, ostream, i did not see any way to retrieve the openmode flag used. I guess you'll have to try to write something to your reference and catch any error it throws. Or depending on how it is set, check the result of bad().
|
7,077,821 | 7,079,792 | Troubles with qfacebookconnect | i Have been given this simple task ,
I want to connect to facebook in my code, any how i downloaded QfacebookConnect from here:
http://gitorious.org/qfacebookconnect/qfacebookconnect/trees/master
please check the link above before you reply ....
I just wanted to run the sample so i could make sure that everything is f... | It's actually not that weird:
When you download the qfacebookconnect project, you only have the sources but no library. You need the library to actually use it, unless you include the source files in your own project. You will get it if you build the qfacebookconnect project.
As the error message is saying it cannot f... |
7,077,903 | 7,077,954 | How access class variables in c++ | Is it possible in c++ to access class variables in other classes without creating an object. I have tried to use static, but the other class doesnt recognize my variable.
I have 3 classes. In two of those the sae variables should be used. In the third class I am changing the values. Would be grateful if you could help.... | class Myclass
{
public:
static int i;
};
int Myclass::i = 10;
class YourClass
{
public:
void doSomething()
{
Myclass::i = 10; //This is how you access static member variables
}
};
int main()
{
YourClass obj;
obj.doSomething();
return 0;
}
|
7,077,943 | 7,078,048 | C++ member variable pointers | I am sure this is a basic question, but I keep receiving memory access errors when I think I am doing this correctly.
What I want to do:
class A{
string name;
string date;
}
main{
A *a = new A();
a->name= someFunct();
a->date= someFunct();
B b;
}
class B{
A *a;
printf("%s", a->name); //retrieving data... | In addition to Andreas' answer, you are not initialising *a in B. Just because they are named the same does not mean that they are pointing to the same thing. You need to say something like
b.a = new A();
in your main. Otherwise b.a is an empty pointer.
Ie. You need to create an instance of a on your b instance. Alter... |
7,078,105 | 7,138,170 | Child window for Internet explorer flickering | I am writing a browser helper object and want to show a child window inside the internet explorer window to show the user some messages. I use DS_CONTROL and WS_CHILDWINDOW and want to get a behaviour similar to the message in this image:
I succeeded in inserting and showing a child window, but the window is flickerin... | Finally I could solve it (with the help of the information I got from the many different answers below).
For those of you having the same problem, here the solution:
I have to shrink the window that is displaying the HTML website, so my own window doesn't overlap with it.
For this I get the current tab like in the exam... |
7,078,156 | 11,906,556 | Design: GraphicManager, TexturesPool, Texture | I have system in which present class sigleton GraphicManager, class TexturePool and class Texture.
Texture have some subtles in creation. Then it constructing itself they use DirectX stuff from GraphicManager and some d3d constants. Now i use CreateInstance method and private cons in Texture class, but as for me its no... | I really couldn't understand your question, but I'll try to give you some tips. It's ok if you use Singleton in GraphicManager or in TexturePool, but you have to be careful, because singleton allows you to use the unique instance even when you shouldn't. Singleton can make the code easier to type, but a quite dangerous... |
7,078,255 | 7,079,082 | Incorrect string length after Blowfish encryption | I did a little testing with Blowfish encoding and noticed something. The encoded string is not always as long as the source string. it is shorter sometimes.
If i want to decode a encoded string i need the length to decode in the openssl function:
BF_cfb64_encrypt(encoded_input,decoded_output,length_to_decode,&key,iv,&n... | The length of the output is identical to the length of the input. Do note that the output data may contain NUL characters, so you should not use strlen on the data.
|
7,078,417 | 7,078,482 | Inheritance hierarchy: Constructor & Destructor execution sequence | Here http://www.parashift.com/c++-faq-lite/multiple-inheritance.html section [25.14] says
The very first constructors to be executed are the virtual base classes anywhere in the hierarchy.
I tried to verify it using following program:
A (pure virtual)
|
B
|
C
(v... | Virtual base classes cannot be constructed if the classes they inherit from are not constructed first. So in your case, non-virtual base classes are constructed because the virtual ones depend on them: C can't be constructed until A and Bare. Therefore, A and B are indeed constructed before C, even though C is virtuall... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.