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 |
|---|---|---|---|---|
6,508,365 | 6,609,080 | List of combinations of N balls in M boxes in C++ | I would like to write a function that generate an array of tuples containing all possible permutations of N balls in M boxes in C++.
The order (Edit : in the resulting list) is not important, just that the first must be (N,0,...,0) and the last (0,0,...,N).
I didn't find such an implementation on the net in C++, only p... | There's a neat trick to solving this. Imagine that we took the n balls and m − 1 boxes and put them in a row of length n + m − 1 (with the boxes mixed up among the balls). Then put each ball in the box to its right, and add an mth box at the right that gets any balls that are left over.
This yields an arangement of n ... |
6,508,594 | 6,508,638 | Generic linked list in c++ | I have been struggling for too long a time now with a rather simple question about how to create a generic linked list in c++. The list should be able contain several types of structs, but each list will only contain one type of struct. The problem arises when I want to implement the getNode() function [see below], bec... | There is already a generic link list available in C++, std::list. It will definitely be more efficient & should suffice for your usage.
If you still want to create your own generic link list
You should consider using templates and create a template implmentation of link list.
In c, where templates are not available th... |
6,508,700 | 6,508,984 | How to debug "This application has requested the Runtime to terminate it in an unusual way." when I can't even step in the code? | I have a C++ program that is giving this error as soon as the process starts - apparently before any user code executes. It only happens when inlining is enabled. Even with debug symbols built in, I can't step in the code. As soon as I press F10 in Visual Studio I get the error and the program stops. I checked all exce... | You could try setting up Process Dumper and configure it for your EXE to create a dump on any process exit. Then start the process from the command line to rule out any artifacts of the IDE.
This ought to give you a dump for post-mortem debugging, and maybe a callstack fromm the exiting thread that could be useful.
|
6,508,866 | 6,516,625 | Create multiple static objects in C++ | Long story short, I need to create lots of objects within a function. Is it possible to do so without copying and pasting?
Basically, the effect I'm after is this
class foo() { .... }
void bar()
{
static foo obj1;
static foo obj2;
static foo obj3;
...
...
static foo obj501;
}
Any help is much ... | I'd do it with recursive template functions:
template <int N> void makeStatic() {
static foo s_foo;
makeStatic<N-1>();
};
template <> void makeStatic<0>() {
static foo s_foo; // comment this out to get 512, otherwise you get 513 objects. :)
};
void bar() { makeStatic<512>(); }
|
6,508,868 | 6,510,242 | Create smooth line to join N points in 3 dimensions | I have N points in 3-dimensional space. I need to join them using a line. However, if I do that using a simple line, it is not smooth and looks ugly.
My current approach is to use a Bezier curve, using the DeCasteljau algorithm for 4 points, and running that for each group of 4 points in my data set. However, the probl... | A couple of solutions:
Use a B-spline. This is a generalization of Bezier curves (a Bezier curve is a B-spline with no internal knot points.)
Use a cubic spline. Cubic splines are particularly easy to calculate. A cubic spline is continuous in the zero, first, and second derivatives across the control points. The thir... |
6,508,989 | 6,509,251 | How to use a preprocessed .i file in another C++ program? | Suppose I have one program that I compile and generate a preprocessed output file, as described at this page:
http://msdn.microsoft.com/en-us/library/8z9z0bx6%28v=vs.80%29.aspx
It generates a .i file as an output. Anyone know where I can find an example of properly using this output file in another program?
| Preprocessed files are files which contain all pre-processor substitutions in place. You should just compile them as other source files.
|
6,509,032 | 6,509,443 | How to define implementation of a COM coclass? | I am new to COM, and I looked around on the internet to find how to create a COM class in C++ (to be used by C#). I've seen that in the .idl file, I must put something like this:
[
object,
uuid(a93164ee-e6d4-44be-aa27-f00ce6972719),
helpstring("interface ITopologyQuery")
]
interface ITopologyQuery : IUnknown
{
HRESU... | The IDL (Interface Definition Language) part defines the binary interface in a language-independent way that just looks a lot like C++.
It's generally used to build a binary type library, which is a DLL with info about your COM class. You can use Microsoft's COM/OLE Viewer to browse existing type libraries.
For C++ con... |
6,509,154 | 6,511,177 | Using Kerberos authentication for Server/Client application | In c++ I am trying to build a portable server running on Linux and Windows and client running in Windows that will use MS Active Directory for authentication. After some research I decided that best way to go is use Kerberos. I decided to use MIT Kerberos v5 library due to BSD style licence.
But my problem is that I am... | The best place to start is the sample simple client and simple server in the MIT code distribution found here: https://github.com/krb5/krb5/tree/master/src/appl/sample
This shows you how to use GSSAPI to do mutual auth
|
6,509,405 | 6,509,699 | Random algorithm with priority to one end | I am writing a little program with a GUI in C++ and Qt.
It is supposed to be similar to a vocabulary trainer. I will use it for my own studying.
I have a QList of objects (name and description as string for example).
Then I have a second QList with ints in it. For every object in my other list, an int is in this list.... | First a remark: You should use qsrand only once at the beginning of the program.
Now to your algorithm: First get the sum of all your values, let us call it sumValues, then compute your random number between 0 and sumValues-1. Go through your list and sum the values into the variable currentSum until it is greater or e... |
6,509,449 | 6,509,479 | Is strncpy() a specialization of memcpy()? | Just curious to know (as we use these functions often). I don't see any practical difference between strncpy() and memcpy(). Isn't it worth to say that effectively,
char* strncpy (char *dst, const char *src, size_t size)
{
return (char*)memcpy(dst, src, size);
}
Or am I missing any side effect? There is one similar ... | There is a difference, see this part of the strncpy page you linked to (emphasis mine):
Copies the first num characters of source to destination. If the end of the source C string (which is signaled by a null-character) is found before num characters have been copied, destination is padded with zeros until a total of ... |
6,509,551 | 6,510,027 | How to render with isometric perspective? |
Possible Duplicate:
true isometric projection with opengl
I want to render using the same isometric rendering which Blender3d uses, how can i do this ? Is it possible with just a call to glMultMatrix() ? I tried googling but couldnt find any working matrixes that would result in that kind of rendering mode. i tried ... | It is easier to use glOrtho then rotate the axes:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10.0f, 10.0f, -10.0f, 10.0f, -10.0f, 10.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(35.264f, 1.0f, 0.0f, 0.0f);
glRotatef(-45.0f, 0.0f, 1.0f, 0.0f);
|
6,509,605 | 6,509,988 | What is HID_REPORT_DESCRIPTOR? | What is HID_REPORT_DESCRIPTOR and what is the use of this. I had found some definitions in web, but I don't understand. How we can use use this and how we can edit a Report Descriptor.
Please guide me, it would be appreciated.
| This tutorial pretty much explains everything in detail about HID_REPORT_DESCRIPTOR.
Please do a google search before you ask a question.
|
6,509,617 | 6,509,659 | Method for abstracting filesystems in a C program | I'm starting out a program in SDL which obviously needs to load resources for the filesystem.
I'd like file calls within the program to be platform-independent. My initial idea is to define a macro (lets call it PTH for path) that is defined in the preprocessor based on system type and and then make file calls in the p... | The Boost Filesystem module is probably your best bet. It has override for the "/" operator on paths so you can do stuff like...
ifstream file2( arg_path / "foo" / "bar" );
|
6,509,961 | 6,512,309 | Is C++/Tk compatible with Tk 8.5? | Since Tk 8.5, Tk started using Native Based UI components - buttons, scrollbars etc. I wonder if C++/Tk supports such Native GUIs approach?
| As far as I can see, C++/Tk is based on Tk 8.4 (if it's before that then it really needs updating). It wouldn't in principle be that hard to adapt to 8.5, where the Ttk widgets are supported; just a matter of adding more widget definitions (and a few other commands too, so you can do things like change the theme). If i... |
6,510,041 | 6,510,163 | Template parameter as a friend | In C++03 the following is illegal, although some compilers support it.
template <class T>
class X
{
friend T;
};
Has this been legalized in C++11? (Sorry, didn't have time to read the draft myself, just hoping someone knows this)
| From section §11.3, 3 in N3291:
template <typename T> class R {
friend T;
};
R<C> rc; // class C is a friend of R<C>
R<int> Ri; // OK: "friend int;" is ignored
So it is legal in C++11.
|
6,510,218 | 6,511,359 | Get program name from executable path (or from hWnd, or from pid) in C++ |
I've got the HWND of a window,
with GetWindowThreadProcessId i get
the pid of it's process,
and with GetModuleFileNameEx i get the
executable path (I use PathFindFileName to get the
executable name).
However, I can't seem to find any way (if there is any) to get the program's name. For example, for the executable c... | Here, as an answer :)
How to get information about a Windows executable (.exe) using C++
|
6,510,323 | 6,510,512 | Can a templated Pointer class have a virtual destructor? | I ran into a surprising revelation when implementing the pimpl idiom with a home made pointer class (I know: why roll your own? But bear with me). The following three files contain a minimal example:
Pointer.h:
#pragma once
template <typename T>
class Pointer
{
public:
Pointer(T*p=0)
: _p(p)
{
}
... | Without virtual, there is only one place the destructor is going to be called; within ~Foo, at which point you have presumably fully defined FooPrivate. If another instance of Pointer<FooPrivate> is created elsewhere, you might get the warning back, but since you don't the compiler can tell you're behaving safely.
Wit... |
6,510,393 | 6,510,497 | Is it possible to access a STL deque element by its address? | Good afternoon , We are trying to make a simple emulation of the Windows memory mapped caching subsystem. We are using several STL data structures.
A STL deque , std::deque<Range> accesses, which holds and records information about the last recently used to the most recently used memory mapped regions.
A STL set, std... | Rather than using a set to hold the addresses, how about a map that contains the address and an iterator into the deque?
Note that moving an element from the middle of a deque to the beginning or end is going to be no faster than doing it for a vector. You might want to think about using a list.
|
6,510,411 | 6,510,434 | Adding a library to an MFC project | So this might be super basic, but that's what happens when you get a job you aren't wholly qualified for, right?
I've got an MFC project, everything is working great, but I'm trying to add the string and stringstream directive into the project.
No matter where I put #include <string> and #include <sstream> I get the "... | Try std::string instead of string, since string is in the std namespace
|
6,510,654 | 6,510,759 | templated code not working while non-templated code works! | I spent several hours, completely stuck when I realized that only the templated version of my code has a bug.
In the following code, when pushing_back elements in the myMap, the original vectors myVec1 and myVec2 are modified and contain garbage at the end of the execution. If I un-template everything, just replacing ... | A templated constructor is never a copy constructor.
So your class is using the automatically generated copy constructor.
Cheers & hth.,
|
6,510,746 | 6,512,520 | Using Dlls in Qt C++ | I'm trying to build a project with a library (dll) I made. I've never attempted to either load or make a library before and I'm getting the following error.
error: undefined reference to `imp__ZN6NeuronC1Ev'
In Qt, the error is shown in the following line.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(paren... | What are you trying to do?
LIBS += -L quote(C:\Programming\Jane\Jane\Source\Neuron.dll)
It variable contains a lib-files, which project will be linked with, not a library itself!
You should find a lib for the dll or use WINAPI LoadLibrary/GetProcAddres functions to load dll dynamically.
|
6,510,921 | 6,511,660 | Huge performance slowdown - vectors the problem? | This part of my code is meant to take an irregularly-shaped outline of Tile objects and loop through creating a ring and decreasing the height value of the tiles in the ring while expanding the ring each time to include those tiles just outside the previous ring (does that make sense?). What I find, however, is that I... | Your algorithm, as best I can tell, is O(n^2 * m) in the number of edges and adjacent tiles. Most likely just a small increase causes the asymptotic performance to blow up and you see the slowdown. If the edge containers were sorted you could use a binary search instead, or if you were able to hash them instead that wo... |
6,510,923 | 6,511,159 | How to use istream with strings | I would like to read an file into a string. I am looking for different ways for how to do it efficiently.
Using a fixed size *char buffer
I have received an answer from Tony what creates a 16 kb buffer and reads into that buffer and appends the buffer till there is nothing more to read. I understand how it works and I ... |
it only happens in the memory, not from the disk, so it is almost unnoticable
That is indeed correct. Still, a solution that doesn’t do that may be faster.
Why are those iterators so slow?
The code is slow not because of the iterators but because the string doesn’t know how much memory to allocate: the istreambuf_i... |
6,511,044 | 6,532,664 | How to debug/fix an access violation (Heap Corruption) | My app crashes (repeatably) after I have moved from VS2005 to VS2008 (win32).
If I step in the debugger, I get:
Access violation reading location 0x00000014
Firstly, I see that the class object at the crash line, has a NULL _vptr. But some other objects of the same class have non-NULL _vprt :)
Secondly, if I change th... | This turned out to be an issue related to preprocessor defines being different between my app and some of its dependencies (libs).
|
6,511,096 | 6,635,067 | __cdecl or __stdcall on Windows? | I'm currently developing a C++ library for Windows which will be distributed as a DLL. My goal is to maximize binary interoperability; more precisely, the functions in my DLL must be usable from code compiled with multiple versions of MSVC++ and MinGW without having to recompile the DLL. However, I'm confused about whi... | I just did some real-world testing (compiling DLLs and applications with MSVC++ and MinGW, then mixing them). As it appears, I had better results with the cdecl calling convention.
More specifically: the problem with stdcall is that MSVC++ mangles names in the DLL export table, even when using extern "C". For example f... |
6,511,560 | 6,511,611 | Can I have gdb break on read/write from an address? |
Possible Duplicate:
Can I set a breakpoint on 'memory access' in GDB?
I have a specific location in memory that is getting corrupted, and I'd like to be able to see exactly when things write to that location. Is there any way that I can make gdb break on memory access to that particular address?
| Yes.
Using Watchpoints:
watch - only breaks on write (and only if the value changes)
rwatch - breaks on read, and
awatch - breaks on read/write.
A more detailed brief from some internet sources:
watch
watch is gdb’s way of setting data breakpoints which will halt the execution of a program if memory changes at the spe... |
6,511,942 | 6,512,499 | Can I have blocking I/O within an asynchronous io_machine? | I have a server that's currently using asynchronous IO to (1) accept data from cin and send that input across a UNIX socket and (2) accept data on a UNIX socket, parse that data, and send back a response.
When I'm parsing the data, how can I block the I/O that occurs in the parser (ParseJSON(data_.data()) in the exampl... | If ParseJSON() does a blocking read from cin then it will block which means that handle_read() won't execute the async_write() until ParseJSON() returns.
I think the problem is that parsed is a stack variable. handle_read() will most likely return before the data is actually written and parsed will be destroyed. Th... |
6,512,019 | 6,512,387 | Can we get the type of a lambda argument? | Using std::function, we can get the type of an argument using the argument_type, second_argument_type etc. typedefs, but I can't see a way to do the same thing with lambdas. Is it possible? (I'm using VS2010)
Say I want something like the following in my deserialization system used to read an object and pass it to a se... | It's not desirable in the general case. (Note that it's quite easy for std::function<T(A)> to specify what e.g. argument_type is: it's just A! It's available in the type definition.)
It would be possible to require each and every function object type to specify its argument types, and in turn mandate that the closure t... |
6,512,054 | 7,596,527 | Creating gui binding for c++ and YUI | I am planning to use yui or jquery ui as front end for native c++ applications. I found no bindings present for this purpose. Will it be feasible/possible to do this ? If it is so, then how shall i proceed? please suggest advice.thanks
| @rwik - I can see your point and desire to do what you intend and I would presume it to be a wise move to be making at this point in time considering the vast facilities browsers bring to the table as well as other aspects... I know we are in September now and I have come across this pretty late, but this is also for o... |
6,512,173 | 6,512,278 | ifstream not reading EOF character | I am creating a program (In C++) that takes an ASCII file and reads a few values from each line until it reaches the end of the file. I am using ifstream to read the file, and I have never had problems with it stopping when I use the ifstream.eof() method. This time, however, even though it found the eof character in... | First thing is first, you shouldn't check like that. eof() doesn't return true until after a failed read. But you can do better (and easier)!
check the stream state with the implicit conversion to void* which can be used in a bool context. Since most of the read operations on streams return a reference to the stream, y... |
6,512,271 | 6,513,163 | boost::asio reading troubles | I'm new to network programming in general, so please bear with me. I couldn't find anything about this in the boost documentation. When using asio::async_read, an end of file error is raised when there is no data to be read from the socket (at least, I think it does). Is there any way to implement some kind of check to... |
When using asio::async_read, an end of
file error is raised when there is no
data to be read from the socket
eof is returned when the other side of the socket is closed, not when there is no data to read.
What I'm trying to get at is: is there
any way to wait for data to be
present, and then read said data a... |
6,512,692 | 6,524,938 | Visual Studio 2010: Building and development cycle with Google Test? | Using Visual Studio 2010 C++ with googletest. I'm new to unit testing and I've created a test solution to experiment with it. I have three projects in the solution:
HelloService (static lib)
HelloService.Tests (exe, a console app I think, linked with gmock_main.lib)
HelloApp (MFC exe, my main app)
I've got googletes... | The solution for me was to set the HelloApp as the StartUp project and then right click on the HelloApp project and choose "Project Dependencies..." and then check the HelloService.Tests project (the HelloService project was already checked). Now when I hit F5 the test project gets run (because HelloService.Tests alre... |
6,512,710 | 6,512,737 | Union of same type in C++ | Whenever I see examples of union, they are always different types. For example, from MSDN:
// declaring_a_union.cpp
union DATATYPE // Declare union type
{
char ch;
int i;
long l;
float f;
double d;
} var1; // Optional declaration of union variable
int main()
{
}
What happens if... | No, this won't cause any issues. The reason you don't see it more often is that it's pointless - both names refer to the same value of the same type.
|
6,512,980 | 6,513,005 | How to view assembly language produced by VS2010? | How can I see the assembly language my C++ project has been compiled into within VS2010?
| Supply /FAcs to the command line, or select "Assembler Output" under the project properties → C/C++ → Output Files.
The compiler emits an .asm file next to the .o file corresponding to the .cpp. You can learn more about the operation of /FAcs here.
|
6,512,991 | 6,525,097 | Boost::Program_Options unhandled exception due to access violation | I have a program that runs fine in DEBUG mode but in RELEASE mode I get an unhandled exception due to an access violation. I'm pretty sure it's not due to null pointers. Here is the call stack:
msvcr90d.dll!memchr(unsigned char * buf=0x0000002c, unsigned char chr='', unsigned long cnt=1243588) Line 80 Asm
msvc... | I think the problem I may be facing is that my program loads the symbols from the DEBUG CRT DLL's. By the time the access violation occurs, the symbols from the RELEASE CRT DLL's are not loaded. I have checked all the projects involved in my program and they all use a Multi-threaded DLL (/MD) and yet it's still using t... |
6,513,042 | 6,513,047 | std::string::length() vs. std::string::size() |
Possible Duplicate:
std::string length() and size() member functions
I always retrieved the length of an std::string via thesize() member function. To be honest I never knew there was a length() member function too. Well, I've just learnt there is. So I am wondering if there's any difference between the two, and in ... | Nope! No difference. The more natural name for this function is length() and size() is provided alongside for uniformity with containers.
|
6,513,202 | 6,513,625 | boost::asio::async_read bind compilation error | I can't figure out why I get this error :
/usr/local/include/boost/asio/impl/read.hpp: In member function ‘void boost::asio::detail::read_op<AsyncReadStream, boost::asio::mutable_buffers_1, CompletionCondition, ReadHandler>::operator()(const boost::system::error_code&, size_t, int) [with AsyncReadStream = boost::asio::... | Your completion handler signature is not correct, consider this example
#include <boost/asio.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
void
foo()
{
}
int
main()
{
boost::asio::io_service io_service;
boost::asio::ip::tcp::socket socket( io_service );
char buf[2];
// this compiles... |
6,513,660 | 6,513,887 | Can deriving a class from 'enable_shared_from_this' increase performance? | make_shared is more performant than separately calling new and creating a shared_ptr because make_shared allocates space for the reference count and weak count in the same memory block as the client object instance (effectively giving the shared_ptr most of the performance benefits of an intrusive_ptr).
enable_shared_f... | I have never dug into the details of implementation, but for shared_from_this to work, the object must already be managed by an external shared_ptr, so it is to some extent unrelated. I.e. the first shared_ptr might have been created with make_shared in which case the count and object are together (as you say intrusive... |
6,513,736 | 6,513,771 | Qt support for C++0x enum class | Using Q_ENUMS I can now "register" with Qt an enum declared inside a class that inherists from QObject. This gives me a few cool reflection features for the enum.
I'm also really enjoying the type-safe enum class introduced in C++0x. I'm wondering if you know of any announcement made by Qt developers of plans for suppo... | It appears that Qt 4.8 will have support for many major C++0x features (including enum class) according to this blog post.
|
6,514,368 | 6,514,725 | How to make the visual studio 2008 IDE look at the right place for header files. Compiling Qt/C++ program | I am building an app on Qt 4.6.2 using visual studio 2008. I need to include the header <QtGui\QDir>.
Problem : The QDir header includes several headers. Once of them is qfile.h. Now the ide/compiler is unable to include this file and the error I get is this
c:\devprojects\myprojects\nttoolkit\trunk\external\qt\includ... | The various places the preprocessor searches for include files is described in the Remarks section here.
Typically for an "SDK" like Qt people will change their VC++ Directories, Projects, Options under Tools | Options | "Projects and Solutions" | "VC++ Directories" so that the Include Files and Library Files lists i... |
6,514,378 | 6,553,466 | how do you get how long a process has been running? | Is there a way to get this information from the /proc directory? I want to be able to get how long each process has been running on seconds.
EDIT: I needed to do this from C++. Sorry for the confusion.
| Okay guys, so after reading the top command's source code, I figured out a non-hacky way of getting the start time of a process. The formula that they use is:
Process_Time = (current_time - boot_time) - (process_start_time)/HZ.
(You have to divide by HZ because process_start_time is in jiffies)
Obtaining these values:... |
6,514,438 | 6,514,831 | hidden copy in STL vector? | I am experiencing unexpected performance degradation when using vectors with classes.
I have a csv_File class that reads in a csv file and stores the contents in a 2D vector. There's a member function that allows access, e.g.
csv_File file("file.csv");
file.access(2,2);
To access the 2,2 element.
Then, I have ... | You probably want to make grab return a reference rather than a copy:
csv_File& grab(int index);
|
6,514,449 | 6,514,459 | referencing something from global namespace? | This is really trivial but I'm getting an error I didn't expect.
I have some code which is inside of a namespace
the following is some pseudocode that represents the structure of my code:
namespace A {
void init() {
initialize_kitchen_sink();
}
#include "operations.h" // declares shake_and_bake()
... | Turns out moving the #include outside the namespace will fix it.
As it was, the include would be in effect declaring all of the functions in operations.h inside the A namespace. Then it would search in vain for the implementations.
I figure instead of deleting my entire post i may as well leave it for that minute pos... |
6,514,547 | 6,514,806 | CreateWindow() style parameter being ignored? | In my Windows application, I'm creating a new window using the CreateWindow() function. The registration and window creation are as follows:
// Set up the capture window
WNDCLASS wc = {0};
// Set which method handles messages passed to the window
wc.lpfnWndProc = WindowMessageRedirect<CStillCamera>;
// Make the instan... | Drawing of the title bar and other such things requires that you pass unhandled window messages to DefWindowProc. For example, the title bar is painted during the WM_NCPAINT message. If you don't pass the message to DefWindowProc that just doesn't get done.
|
6,514,587 | 6,514,603 | Best way to read 12-15GB ASCII file in C++ | I am trying to count the number of lines in a huge file. This ASCII file is anywhere from 12-15GB. Right now, I am using something along the lines of readline() to count each line of the file. But ofcourse, this is extremely slow. I've also tried to implement a lower level reading using seekg() and tellg() but due to t... | Don't try to read the whole file at once. If you're counting lines, just read in chunks of a given size. A couple of MB should be a reasonable buffer size.
|
6,514,663 | 6,514,767 | Do C89 or C++03 define strict aliasing rules? | I've seen several assertions that C89 and C++03 define strict aliasing rules. I, however, cannot find that particular bit in the standard. My understanding was that strict aliasing rules were added in C99.
| The C++03 standard has the following under §3.10 [basic.lval] p15:
If a program attempts to access the stored value of an object through an lvalue of other than one of the following types the behavior is undefined48):
— the dynamic type of the object,
— a cv-qualified version of the dynamic type of the object,
—... |
6,514,774 | 6,514,797 | C++ reading random lines of txt? | I am running C++ code where I need to import data from txt file.
The text file contains 10,000 lines. Each line contains n columns of binary data.
The code has to loop 100,000 times, each time it has to randomly select a line out of the txt file and assign the binary values in the columns to some variables.
What is t... | To randomly access a line in a text file, all lines need to have the same byte-length. If you don't have that, you need to loop until you get at the correct line. Since this will be pretty slow for so much access, better just load it into a std::vector of std::strings, each entry being one line (this is easily done wit... |
6,514,800 | 6,515,828 | Vim auto-completion for C++'s #include clause | I just installed omnicomplete plugin, does it support header auto completion?
When I typed #include <, is it possible to provide a list of header files to complete?
Many thanks!
| You can just use the vim autocomplete feature, which was introduced in vim7.
Just type in first few characters and press Ctrl->P(for backward search) or Ctrl->N(for forward search), vim lists down all options available or completes it.
And Yes it works even for header files.
To make this work you should install ctags... |
6,515,042 | 6,515,176 | Class component order of initialisation | class D: A
{
B obj;
C obj2;
}
What order of construction here is guaranteed?
I know that D will be constructed after A, B and C, but what I really want to know is whether A is guaranteed to be constructed before B or C, or even whether B is guaranteed to be constructed before C.
I know you can have an explicit... | From the C++03 standard ISO/IEC 14882:2003(E) §12.6.2/5 [class.base.init]:
Initialization shall proceed in the following order:
— First, and only for the constructor of the most derived class as described below, virtual base classes shall be initialized in the order they appear on a depth-first left-to-right travers... |
6,515,143 | 6,515,232 | User-Created Header Causing C2061: Syntax Error : Identifier 'classname' | So, I sort of expect this to end up being a simple answer, but I've been hacking at it for a while now, and can't seem to fix this issue. So I have a particular class, Intersection, that when included in any other header gives me:
error C2061: syntax error : identifier 'Intersection'
This is my Intersection header:
#if... | It looks like the error is that you have two header files that are circularly including one another - intersection.h and road.h. Doing this tends to lead to weird surprises in C++ because of how include guards work. For example, suppose that I have two header files that look like this:
// File: A.h
#ifndef A_Included... |
6,515,271 | 6,515,553 | fatal error LNK1120: 1 unresolved externals | This is the program :
#include <windows.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
MessageBox (NULL, TEXT ("Hello, Windows!"), TEXT ("HelloMsg"), 0) ;
return 0 ;
}
I can't understand the error.Please help in correcting it.
**ERROR** `fatal e... | I think you might be working on a console project and trying to make a windows application !
If it is so,select a new win32 project from file->new and then re-write that code.
You will have this as output:
|
6,515,291 | 6,523,676 | Making a game in Qt regarding GUI windows | I've been wanting to program a simple game with a simple GUI using Qt (Its will be a VERY simple game, nothing fancy). What I've been wondering is, how can I create multiple windows and display them when needed? For an example, a battle screen and an inventory screen. The user should only see one of them, but should be... | A StackWidget certainly would accomplish what you want to do. The reason why it is not always used for this kind of thing, is that it all the screens are pre-created at the beginning and always exist. This means it takes a little longer to initialize, and you are using more resources than you need at any one time
But a... |
6,515,418 | 6,515,423 | Why non-const version is selected over the const version for class? | Following is the test code:
struct A
{
operator int ();
operator int () const;
};
void foo (const int);
Now, upon invoking:
foo(A()); // calls A::operator int()
Why does it always chooses the non-const version ? Even making operator const int () const; doesn't have any effect on invoking foo(). Apart from stand... | A() gives you a temporary A object that is not const-qualified. The A() expression is an rvalue expression, yes, but that does not make the A object const-qualified.
Since the A object is not const-qualified, the non-const operator int() is an exact match and the const operator int() requires a qualification conversio... |
6,515,510 | 6,515,763 | Multiplication of two deques of integers weird errors | this should be the final part of my integer class, and it seems to be very easy, and yet, something is wrong. is this code correct for multiplication using 2 deques?
// 0x12345 = {0x01, 0x23, 0x45}
integer operator*(integer rhs){
// long multiplication
unsigned int zeros = 0;
std::deque... | I think you are missing the last carry. Do you not need:
row.push_front(carry);
just before you add the row to out?
|
6,515,529 | 6,517,791 | GJK collision detection implementation from 2D to 3D | I apologize for the length of this question and give a pre-emptive thanks for anyone who reads through this!
So i've spent the last few days going over the GJK algorithm. I understand the general concepts behind it, and understand the most of the nitty gritties of its implementation in 2D thanks to the wonderful artic... | Depending on what result you expect from the GJK algorithm you might want to look at this nice tutorial from Molly Rocket: https://mollyrocket.com/849
Be aware though that his implementation only outputs intersection? yes/no. But it might be a nice start.
|
6,515,656 | 6,515,893 | Postfix Operator Overloading Order |
Possible Duplicate:
Undefined Behavior and Sequence Points
I'm having trouble understanding the order of actions when overloading the postfix operator. Let's examine the two small examples below:
int i = 0;
std::cout << std::endl << "i: " << i;
i = ++i;
std::cout << std::endl << "i: " << i;
i = i++;
std::cout << st... | As others have said, with int the behaviour is undefined. But I thought I'd try to explain why for your MyClass it is not ever getting to 2.
The trick is that you are taking the following three steps in the postfix version:
Making a copy of this called myTemp (with myValue == 1).
Incrementing this->myValue (so myTemp.... |
6,515,842 | 6,515,980 | Can one install Whole Tomato's Visual Assist X in Microsoft's Visual C++ 2010 Express Edition? | Do you know software support assist for Visual C++ 2010 Express ?, as Visual Assist X for Visual Studio
| Installing any plugin requires running the IDE in Integrated Mode (rather than Isolated Mode), which means you'll need a full version of Visual Studio. The express editions simply don't have the feature.
Couple of options to get a version capable of Integrated Mode:
If you are a university student, you can download a... |
6,515,963 | 6,517,787 | making buttons and handling them | How can i make buttons in c++ and handle them.
I am targeting win32.
Till now i have no idea of how to make graphical programs in c++ . I have come from JAVA and therefore have no idea of handling c++ events and building GUI
It will be of great help if you give the links to tutorials or could name the books to do so.
| C++ is merely a language and the framework and operating system services whcih enables you to make use of the services using C++.
Java contains a GUI framework which has implemented across the platform. When you come to a native windows application, you have to rely on mainly two things, Win32 and MFC(a C++ wrapper of... |
6,516,019 | 6,516,067 | What are _Unwind_SjLj_Unregister and _Unwind_SjLj_Register? | What are _Unwind_SjLj_Unregister and _Unwind_SjLj_Register? I get them as my top processor time users in my gprof report. google only returns links to people complaining about errors with these two.
heres the only part of my report that has times != 0:
Flat profile:
Each sample counts as 0.01 seconds.
% cumulativ... | I believe it is exception handling. The problems mostly come up when people try to link to a C++ library built in a different compiler.
|
6,516,130 | 6,516,309 | Developing a GUI specific to games | For a while now, I have been wanting to create my own GUI "library" in C++ and DirectX 9. I have seen a ton of questions regarding GUIs, but what I want is a GUI specific to games. Most libraries are really complex and are very generic, and they offer support for command line parsing and window creation etc. These libr... | Writing your own gui would be a good educational task, as you will soon have to learn the design patterns that are used to make it scalable. If you are interested, the GoF book
uses GUI as an example to many of the patterns.
However, it is a large (HUGE - I mean years of your life) task to do it properly.
One project t... |
6,516,402 | 6,870,814 | Build driver plugin QIBASE Qt 4.7.3 | I try to build QIBASE driver in Qt 4.7.3
ibase.pro
TARGET = qsqlibase
SOURCES = main.cpp
INCLUDEPATH += "C:/Program Files/Firebird/Firebird_2_0/include" "C:/QtSDK/Desktop/Qt/4.7.3/mingw/lib"
LIBS += -L"C:/Program Files/Firebird/Firebird_2_0/lib/fbclient_ms.lib" -L"C:/Program Files/Firebird/Firebird_2_0/lib/fbclient_... | the problem is solved by the advice of colleagues
Need to change the file ibase.pro only and specify the path to header files in the source directory not in directory of the SDK
ibase.pro
TARGET = qsqlibase
SOURCES = main.cpp
INCLUDEPATH += "C:/Program Files/Firebird/Firebird_2_0/include" C:/tmp/src/include
LIBS += "C... |
6,516,877 | 6,516,927 | Interoperation and CRL Activity | I hope that question would not mess with StackOverFlow FAQ rules
So ,when using Libraries which are written in C++ for example ,and that means we have some Code in these DLL's which is going to be executed ,when Software execution cames in that case ,will this Portion of code be executed by CLR ?
I need that because we... | You can use DLLs created in C++ inside your C# project, and as you already know you have to make an interop call. This switches context to unsafe, so the code is probably executed outside the CLR. This means that you lose the portability options the CLR gives you. For example a C# based app would run on Windows and Win... |
6,516,958 | 6,522,448 | How to find all occurrences of an item in a ublas::matrix | I am currently working on a algorithm that needs to find all equal occurrences a an item in a matrix. I decided to use uBLAS matrices from boost. So my problem is:
I have a ublas::matrix looking like:
1 2 3 4 5
2 4 6 8 1
1 5 4 6 8
9 4 6 7 0
and I want to find all positions (x,y) of i.e. the value 6.
Is there a functio... | There is no ublas-specific function (as far as I can tell), you will have to scan the matrix the usual way -- through iterators or through indexed access:
typedef std::vector<std::pair<size_t, size_t> > posvec_t;
template <typename T>
posvec_t find_all(const ublas::matrix<T>& m, T val)
{
posvec_t ret;
for(size_... |
6,517,231 | 6,517,325 | Are C++ recursive type definitions possible, in particular can I put a vector<T> within the definition of T? | For one of my projects, what I really wanted to do was this (simplifying it to the bare minimum);
struct Move
{
int src;
int dst;
};
struct MoveTree
{
Move move;
std::vector<MoveTree> variation;
};
I must admit that I assumed that it wouldn't be possible to do this directly, I thought a vector of Move... | The C++ Standard (2003) clearly says that instantiating a standard container with an incomplete type invokes undefined-behavior.
The spec says in §17.4.3.6/2,
In particular, the effects are undefined in the following cases:
__ [..]
— if an incomplete type (3.9) is used as a template argument when instantiating a templ... |
6,517,435 | 6,517,447 | Dividing unsigned long long | Currently attempting to divide an unsigned long long by a static value.
The unsigned long long contains the number of microseconds it took for an operation to complete. I want to take this value and convert it into seconds.
Here is the code snippit:
double udDiffTime = ullHighResDiffTime / (unsigned long long)1000000;
... | You're doing an integer division, thus if the result is 0.000639 it will get truncated to 0.
If you want a floating-point result, you'll have to use at least one floating-point operand. Try for instance to change (unsigned long long) 1000000 to 1000000.0.
An unsigned long long can range up to 18,446,744,073,709,551,615... |
6,517,599 | 6,517,810 | Warning on field init order, signed comparison, and unused vars in VC++ & Sun Studio | I am hoping to enable warnings for the following C++ compilation issues and corresponding compilers:
Unused variables -- Sun Studio CC
Example: void m() { int i = 10; }
Signed to unsigned comparison - VC++ and Sun Studio CC
Example: if ((unsigned) 10 < -1);
Wrong field initialization order - VC++ and Sun Studio CC
Exa... | In Visual Studio, Project Properties, C++, set warning level to 4 (maximum) - VC++ compiler gives all possible warnings. AFAIK, warnings 1 and 2 are reported, and field initialization order is not reported by VC++ compiler.
|
6,517,717 | 6,517,776 | Effect of entring multiple characters for char type variable | I am new to C++ coding.
I have noticed that if I enter multiple characters for a character variable then the test program given below goes into an infinite loop. I am not able to debug this issue properly. Can someone help me see how the flow of the program goes when such input is entered. I doubt about some unsafe co... | When the user enters mutiple characters on the first query, only the first one is extracted and stored in name.
After that, the loop is entered. The first character is read, and it is not a number, thus the stream goes into a bad state. All subsequent reads fail, so the value of number never changes, and you have an in... |
6,518,157 | 6,518,176 | Is it a good idea to template based on enums? | I am writing a unique ID generator which has different strategies for generating Id's which are unique through a day, or a week or a month.
I do not want to create a hierarchy of classes with virtual function mechanism
Is doing something like the below code snippet, a good idea?
Any suggestions?
enum Duration { Day, We... | Yes it acceptable and will work just file if compile-time polymorphism is enough for you - you will save on virtual calls and that will allow for better compiler coptimizations.
|
6,518,319 | 6,518,388 | Why the following c++ code don't compile? | #include <iostream>
int test( const double *t1,const double **t2 )
{
return 0;
}
int main(int argc, char*argv[])
{
double *t1 = new double;
const double ** t2 = new double *;
test(t1, t2);
}
The error is :
cannot convert double ** to const double **
It compiles if I remove the 2 occurence of const though..
| Make it
const double ** t2 = new const double *;
|
6,518,337 | 6,518,432 | Why is there no gcc/g++ warning for unused temporaries? | Consider the following code :
void ListenerImpl::attach(boost::shared_ptr<ISubscriber> subscriber)
{
boost::unique_lock<boost::mutex>(mtx);
subscribers.push_back(subscriber);
}
void ListenerImpl::notify(MsgPtr msg)
{
boost::unique_lock<boost::mutex>(mtx);
//notify all subscribers
BOOST_FOREACH(boo... | Compiler doesn't issue a warning, because it's quite possible that you might be updating some static-member / global variable inside the constructor (which is valid and meaningful). e.g.:
struct A
{
static int count;
A () { count ++; }
};
Now when you simply invoke a temporary:
A();
In case if such update is not ... |
6,518,347 | 6,518,426 | using double for loop | Does anyone see any syntax error on the following line?
int a6[3][2]={{0,0},{0,0},{0,0}};
for (int c=0 ; c<3 ; for(int c2=0 ; c2<2 ; cout<<a6[c++][c2++])) ;
It gives the following syntax error:
error C2143: syntax error: missing ')' before 'for'
error C2059: syntax error: ')'
| The for command is not an expression that you can use for the post-increment part of another for. Put it outside the control statements of the loop.
The code gets more readable if you keep with the common convention on how to write a loop, i.e. the code controlling the loop inside the for statement and the work to be d... |
6,518,545 | 6,518,826 | How to initialize a struct[int] correctly with extern keyword | Here's my code:
main.cpp
#include "color.h"
int main ( int argc , char **argv )
{
Highlight h;
return 0;
}
color.h
#ifndef HIGH_H
#define HIGH_H
#include <iostream>
using namespace std;
struct colorPattern_t
{
int c1 , c2;
colorPattern_t ( int a , int b )
{
c1 = a; c2 = b;
cou... | In your example, I don't see anything outside of color.cpp accessing colors, so there is no reason to have the extern on its definition.
If other files are going to have access to this global data, then declare in colors.h that there exists a colors data structure:
extern colorPatterns_t colors[];
Then in your color.c... |
6,518,689 | 6,519,486 | i want to read .bin file in my objective -c project and want to parse data accordingly | i want read data from the binary file named "xyz.bin" and want to parse data according to algorithm can any buddy suggest how to get dat from binary file and perform read and write operation on that binary file
| You want
NSData's
+ dataWithContentsOfURL: or + dataWithContentsOfFile: for input
and
– writeToFile:options:error: or – writeToURL:atomically: for output
What you do with the data in between is up to you.
|
6,518,896 | 8,211,447 | Boost: iterating over an image region | I have images that I don't own, with adjacent monochrome pixels, which I currently iterate with dumb pointer-increment.
I now have the need to iterate over 2D regions, so I'm thinking about the best way to provide iterators that are efficient and easy to write.
I need only forward_iterator. If I have a 10x10 image and ... | You have two concepts: (i) subimage, and (ii) 1-d iterator over image.
I would start by taking a look at vil_image_view in the VXL library.
This separates the concept of image data, from the representation (view) of the data. The view provides istep, jstep amd planestep increments, and pixel indexing. Different v... |
6,519,369 | 6,520,685 | G.711 c++ implementation | Can you advise a G.711 audio codec implementation in C/C++ ?
I am going to use it in a proprietary software.
| I use the implementation here, its simple and fast.
|
6,519,389 | 6,538,489 | Why this argument order in the prototypes of regex_match? | Here is a simplification of the 6 prototypes of std::tr1::regex_match
regex_match(iterator1, iterator2, match_results&, regex&, flags = some_default);
regex_match(iterator1, iterator2, regex&, flags = some_default);
regex_match(Elem*, match_results&, regex&, flags = some_default);
regex_... | The only thing I can think of is some sort of stylistic consistency with the algorithms library. If you think of match_results as some sort of output iterator then it sort of looks like copy, etc with an iterator range at the front, an output iterator after that and predicates after that. The option to not store the ... |
6,519,483 | 6,519,726 | Is there any guaranteed dependency of C++ system headers? | For example, in <algorithm>, the function equal_range returns a pair, so can I assume that if I #include <algorithm>, <utility> is #included?
| You should always include what you need, you cannot rely on all implementations including the same set of headers in another header.
In your example, if a function returns a pair you can be reasonably sure that the pair class is declared, but nothing requires the implementation to include the rest of <utility>.
In fact... |
6,519,857 | 6,519,897 | Problem debugging C++ code from .NET application | I have .NET service (C#) that uses a couple of c++ libraries. I have a desperate need to get into C++ methods but when I set the breakpoints they get disabled in the run time.
Where to look at?
I set "Attach Debugger" in C++ project settings but this does not seem to change a bit.
Please advice. Where to look at?
The l... | You need to enable unmanaged code debugging for your project. To do this:
Right-click on your project in the Solution Explorer, and click "Properties".
In the "Debug" tab, check the box labeled "Enable unmanaged code debugging".
By default, a project targeting the .NET Framework will only debug managed code. You ... |
6,520,067 | 6,520,121 | How to encrypt folder in Windows? | I have a program in C++ that stores certain files such as movies, mp3 & Flash in the AppData folder. The issue is that whilst generally hidden, the user can easily visit this folder and take any of these files.
Is there a way that the program can encrypt this folder so that it's not possible for the user to access the ... | You can use your own program to encrypt a file or a folder.However you can use open source software like truecrypt.The software along with the code is available.Code is written in C,C++ and assembly
|
6,520,089 | 6,520,135 | how to print a list<class*> ls? | What am I doing wrong at the last two lines in my code below? I receive an error:
request for member ‘name’ in ‘t.std::_List_iterator<_Tp>::operator* [with _Tp = a*]()’, which is of non-class type ‘a*’
#include <dlfcn.h>
#include <iostream>
#include "/home/developer/Desktop/MsgSphSDK1/test1_sdk/libsdk_MS.hpp"
#inclu... | You should write
cout<<(*t)->name<<endl
t is an iterator, (*t) gives you a* (the pointer to the object of class a). So to get access to the member of the object you should use ->, not ..
|
6,520,093 | 6,520,277 | C++ events/messages system | I need to IMPLEMENT(not to use some library/open source) an event/message system.
I have the following restrictions:
It must be fast. It will be use for games and speed is the main restriction. I think I can't create/delete message/event classes every time a new message/event is sent even if I use custom allocators fo... | Let me address your points one by one:
It must be fast. It will be use for games and speed is the main
restriction. I think I can't
create/delete message/event classes
every time a new message/event is sent
even if I use custom allocators for
that.
It would suffice and perhaps be even more efficient (it was... |
6,520,236 | 6,520,304 | error: ‘class std::vector<route, std::allocator<route> >’ has no member named ‘exitPoint’ | Please tell me if some more info is needed here:
Global declarations:
typedef struct route
{
int exitPoint;
bool allBranchesTraversed;
} route;
****vector <route> routeVector;****
The culprit func is getting called from:
int main ()
{
....
do
{
****curre... | If you use vector <route> *objRouteVector as parameter, you need (*objRouteVector)[h].exitPoint. Better is using reference: vector <route> &objRouteVector.
|
6,520,261 | 6,520,302 | Cannot understand the first argument of write() | I came across the statement:
outbal.write( (char*) &acc , sizeof( struct status ) );
outbal is an object of ofstream and status is a type.
Therefore:
struct status {
// code
};
status acc;
Talking about the second line I don't understand the first argument, which is (char*) &acc. What are we doing and how?
| (char*)&acc if the address of the variable acc, cast to a char pointer so as to be compatible with ostream::write(). It is that variable that is being written, to the outbal stream, for a length of sizeof(struct status).
ostream::write takes a memory address and a length and will output that memory to the specified str... |
6,520,428 | 6,520,963 | How to query a running process for its parameters list? (Windows, C++) | For a given Windows process I want to know with what command line parameters it was started. The Windows Task Manager is able to show that.
| Assuming you know the process ID, use OpenProcess to get a handle to it (this requires elevated privilege as noted in the docs). Then use NtQueryInformationProcess to get detailed process info. Use the ProcessBasicInformation option to get the PEB of the process - this contains another structure pointer, through which... |
6,520,487 | 6,520,516 | What happens to exported global variables when a DLL is linked in multiple times? | Suppose I have a X.DLL with the following in a header file:
extern __declspec(dllexport) int foobar;
This foobar global variable is then defined inside X.DLL in an implementation file:
int foobar = 1;
Now suppose that I have two DLLs, A.DLL and B.DLL, which are linked to X.DLL, and an application E.EXE which uses A.D... | There is only one copy. However, in general, doing this is an incredibly bad idea and you will run into a lot of problems.
|
6,520,544 | 6,586,876 | Building zlib libz.a for 32 bit | I am trying to compile a 32-bit version (MinGW) of a program I wrote using zlib. Until now, I've never has to compile for 32-bit so the version of zlib I compiled from source (libz.a) is 64-bit. I tried to rerun the makefile in the zlib-1.2.5 directory but it only compiles a 64bit version of libz.a.
I can't seem to fi... | It turns out I had to get the 32bit version of MinGW and compile it with that. I was using MinGW64.
|
6,520,605 | 6,520,730 | How to declare operator<< for internal class | //cannot declare operator<<(...) here:
//forward declarations:
class External;
template<class T, class Y>
class External::Internal;
template<class T, class Y>
std::ostream& operator<<(std::ostream& out, const External::Internal<T,Y>&);
class External
{
template<class T, class Y>
class Internal
{};
I... | If you're asking how to define Internal<>::operator<< as a friend, then:
class External
{
template<class T, class Y>
class Internal
{
friend std::ostream& operator <<(std::ostream& out, const Internal&)
{
// impl
return out;
}
};
Internal<Foo, Bar> data_;
public:
void print() const... |
6,521,020 | 6,523,545 | Can I add the CAArchive class to my iPhone project to serialize data? If so, how? | I have to use the CAArchiver class for the serialization of the data coming from the .bin file in my iPhone project (I need to use it in a C++ code snippet). How do I do this?
I have also researched the following link: http://msdn.microsoft.com/en-us/library/caz3zy5s(v=vs.80).aspx. This appears to be used in .NET techn... | CArchive (as per your link) is part of the Microsoft Foundation Class Library. It's very unlikely that you will find an implementation for them on the iOS platform.
If you need only to provide a kind of serialization, Jigneshs answer is the way to go. If you need to be compatible to other output from CArchive then chan... |
6,521,127 | 6,521,179 | Porting C++ __fastcall Hook from x86 to x64 | I have this hook function that works fine on x86. Thanks to Bo Persson.
void __fastcall Hook(Class* ThisInECX, int UnknownEDX, OtherClass* P1, void* P2, void* P3)
{
static void* OriginalFunctionPointer = GetProcAddress(GetModuleHandleA("Some.dll"), "[...]");
static auto OriginalFunction = ((void(__fastcall*)(Cl... | There is only one calling convention on x64, so you can ditch that from the signature. What's likely going wrong is that you're trying to load the x86 version of a procedure from an x64 function.
Edit: Oh wait, you posted that question about x86/x64 hooking before, right? I'm pretty confident that's not the problem he... |
6,521,404 | 6,524,337 | Parsing XML Elements using TinyXML | UPDATE: Still not working :( I have updated the code portion to reflect what I currently have.
This should be a pretty easy question for people who have used TinyXML. I'm attempting to use TinyXML to parse through an XML document and pull out some values. I figured out how to add in the library yesterday, and I have su... | After a lot of playing around with the code, here is the solution! (With help from HERE)
TiXmlDocument doc("EGC_Cards.xml");
combo = (CComboBox*)GetDlgItem(IDC_EGC_CARD_TYPE);
if(doc.LoadFile())
{
TiXmlHandle hDoc(&doc);
TiXmlElement *pRoot, *pParm;
pRoot = doc.FirstChildElement("EGCs");
if(pRoot)
... |
6,521,675 | 6,525,114 | How to convert Qt program from Win to Mac? | I have a Windows program that writen in QT using C++. May I know whether those code wrote for Windows platform are convertible to Mac? Is it 100% of the code are convertible or none of it are convertible?
| There are a couple of things that are different on the Mac
the Installer of your application needs to be written from scratch (if you have on)
Windows API calls need to be ported (if there are any)
file associations (e.g. .doc means call WinWord.exe) are done differently on Mac OS
double clicking an associated file is... |
6,521,889 | 6,522,063 | Fastest way to skip to position in file (C/C++) | I have some 6k pictures in binary format (uint8), where I process the picture in blocks of 30 or so lines at time. The implication is that I end up having to skip through most of the file until I to get to the position I need to. So far the fastest thing seems to be to read the unnecessary part into a temporary variabl... | Use the seekg method. It was made for exactly what you're trying to do.
http://www.cplusplus.com/reference/iostream/istream/seekg/
Hope it helps
|
6,522,090 | 6,522,131 | CComSafeArray change no of elements | I have created CComSafeArray object having 32 elements using the following statements. But after some operations I came to know that I need only 3 elements in the safe array. Is it possible to change the number of elements in the safe array after creating it?
CComSafeArray<VARIANT> x(32);
| Are you by any chance looking for the CComSafeArray::Resize() member function?
http://msdn.microsoft.com/en-us/library/9758bsfw(v=vs.71).aspx
|
6,522,159 | 6,522,313 | How compilers are handling null pointers | When I have a code like this :
int* nPtr = 0;
MyClass* myClass = 0;
What compiler really does under the hood. I mean anyway there must be some place in memory to refer.
Does compiler have a special memory block for null pointer to where all they refer ?
|
I mean anyway there must be some place in memory to refer.
Nope. You can't dereference a NULL pointer and get an object. There's no object at memory location 0x0 *.
It's just a convention that we have this one [invalid] pointer value that we can use to identify a pointer as deliberately not pointing anywhere valid.
... |
6,522,200 | 6,523,150 | Is there a way to disable message boxes in MFC? | I have an MFC application (using a legacy library that I can't change). When the application starts, it loads a couple of drivers and shows message boxes if some drivers couldn't be loaded. The loading of the drivers and the showing of the message boxes is done by a method inside the library that can't be changed (let'... | I am not sure whether this could work. I use it for subclassing some messageboxes not to preven them to popup and they are not from a dll.
I set a hook to capture message boxes before poping up:
HHOK hMessageBoxHook_ = SetWindowsHookEx(WH_CBT,
&CbtHookProc,
... |
6,522,785 | 8,319,520 | c++ template functions with variable arguments | Is it possible to write a c++ template function which takes a variable number of input variables of different types (number of input can be limited to say 10)?
For example take a function sql_exec() which executes an sql query string and saves the resulting rows in std vectors of the type supplied, i.e.
std::vector<do... | As said above, Boost.Preprocessor is the way to go if C++0x is not available, although it takes a while to get used to the syntax. The example below demonstrate the way Boost.Preprocessor can be used to define functions with variable (but limited) number of arguments.
#include <boost/preprocessor/repetition.hpp>
#inclu... |
6,523,039 | 6,523,225 | Qt Application and window Icon under windows | I have created a simple application icon by embedding a standard windows resource file containing an icon. However I would also like to use this icon on my main application window. Is there an easy way to do this? So far it seems the only way would be to seperately load an icon that contains the window icon rather t... | Actually ... turns out its very very simple ...
HICON hIcon = (HICON)LoadImage( GetModuleHandle( nullptr ), MAKEINTRESOURCE( IDI_ICON1 ), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT );
setWindowIcon( QIcon( QtWin::fromWinHICON( hIcon ) ) );
::DestroyIcon( hIcon );
|
6,523,275 | 6,523,426 | Some Question regarding Exception handling | Please have a look at demo code :
class myError
{
const char* str;
public:
myError():str(NULL) {}
myError(const char* temp)
{
str = temp;
}
const char* what()
{
return str;
}
};
class ab
{
int x;
public:
ab() try :x(0)
{
throw myError("error occu... | The usual rule is that a catch block doesn't rethrow unless you ask it
to. How would you stop the exception from propagating otherwise. In
the case of a constructor, however, if something in the initialization
list throws, then you haven't got a fully constructed object; there is
nothing you could do with the object,... |
6,523,292 | 6,523,351 | Forwarding a shared_ptr without class declaration | NOTE: I've found the source of the error is not actually related to the shared_ptr, just cleverly disguised as such in the error message. Thus the below is basically nonsense (not the answers, they're fine)
--
I'm having some trouble using a shared_ptr (boost's at the moment) where I need to simply forward a pointer t... | You need at least a forward declaration for T for every mention of shared_ptr<T>.
Only if you use unary shared_ptr::operator* and shared_ptr::operator->, the full thing is needed. Under the hood, shared_ptr uses a mix of compiletime- and runtime-polymorphism, making this possible. See also this question to learn about... |
6,523,624 | 6,523,784 | C++ class type copy-initialization | If I write
T t = T();
T is a class.
I think this is calling T's default constructor and then the copy assignment operator.
But the compiler is allowed to get rid of the assignment.
I'm trying to find the description of this behavior written in the C++ standard, but I can't find it.
Could you point me to the right spo... | Since you asked for the C++ standard citation, here it is:
12.8 copying class objects
15
*When certain criteria are met, an implementation is allowed to omit the copy construction of a class object, even if the copy constructor and/or destructor for the object have side effects. In such cases, the implemen-tation tre... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.