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,297,711 | 7,297,885 | CreateDialog Failed, but why GetLastError returns 0? | I am writing an editor for my project by using scintilla editor component. The editor is for an internal scripting language, having all the basic functionalities like cut,copy, paste etc. As one of the feature I am also providing searching functionality. When a user presses the Ctrl+F ideally it should show this dialog... | The SysLink control requires v6 of comctl32 as explained by the documentation. You are linking to v5 comctl32 and I suspect this is the cause of your error. You need to include the v6 comctl32 application manifest.
|
7,297,879 | 7,297,897 | Read and write in c++ | I am trying to use the system calls read() and write(). The following program creates a file and writes some data into it. Here is the code..
int main()
{
int fd;
open("student",O_CREAT,(mode_t)0600);
fd=open("student",O_WRONLY);
char data[128]="Hi nikhil, How are u?";
write(fd,data,128);
}
... | You're not checking whether read() returns an error. You should do so, because that's probably the case with the code in your question.
Since you're opening the file write-only in the first place, calling read() on it will result in an error. You should open the file for reading instead:
char data[128];
int fd = open("... |
7,298,100 | 7,298,577 | XML parsers for C++ which convert xml nodes to C++ objects | Ive a requirement to parse a XML file, and create a tree of nodes inside my application, which then will be used for other purposes like searching and stuff.
The node structure is homogeneous in nature, i.e it will have only a few fields/attricutes like 1.Id 2.Data 3.Children.Even the xml node will be similar, i.e id, ... | A very very easy one to use is mini xml (abbreviated to mxml)
http://www.minixml.org/
|
7,298,103 | 7,303,758 | Mapping between sets of integers | I need to map a set of integers into sets of integers.
First off, I want to point out that not all possible sets of integers are taken into account.
Rather, I create the relevant sets that the application will (ever) use - programmatically, only once, and serialize it in a binary file.
Next, I'd construct a QMap<QSet<i... | If the sets are static, load them into a table (QVector<QSet<int> >), and use the indexes of the sets in that table as keys and values in the map (QMap<int,int>) instead of the sets themselves.
|
7,298,374 | 7,298,394 | Function to return total data within a linkedlist C++ | Trying to implement a function in my linkedlist class that will return total amount of data stored within the list. i.e. linkedlist of 5, 10, 20 total would return 35.
My node class contains the getNextPtr and getData methods.
I implement a new Node and call it currentPtr and make it point to headPtr.
On compile i get:... | If you want to dereference a pointer you need to use ->, not .
e.g. your code becomes:
while(currentPtr != NULL)
{
total += currentPtr->getData();
currentPtr = currentPtr->getNextPtr();
}
I also find it more natural to write while(currentPtr) (i.e. 'while I have a valid pointer') instead of explicitly testing fo... |
7,298,390 | 7,298,599 | How to draw bitmap as OpenGL texture in C++? | I have a bitmap, and its handle (Win32 HBITMAP). Any suggestion of how to draw this bitmap on an OpenGL quad (with scaling and pulling the 4 corners of the bitmap to fit the 4 vertexes of the quad)?
| You need to retrieve the data contained in the HBITMAP, see http://msdn.microsoft.com/en-us/library/dd144879(v=vs.85).aspx Then you can upload the DIB data to OpenGL using glTexImage2D or glTexSubImage2D
With a texture being created you can apply this like usual (enable texturing, give each corner of the quad a texture... |
7,298,781 | 7,298,837 | Constructor for LinkedList to receive an array C++ | Attempting to write a constructor for LinkedList to be initialised with an array of integers.
The program would call linked(array); which will add all the values within the array in to a linkedlist.
LinkedList::LinkedList(int array[])
{
headPtr->setData(array[0]); //setData method stores the integer at position 0 i... | Like others have said, it is not only important but vital that you get a good introductory C++ book and read it from front to back, simultaneously trying to forget what you know about Java while in C++ mode. They are not remotely similar.
Now to your problem, it can be solved by using std::vector and using its size met... |
7,298,872 | 7,298,926 | Is void* necessary apart from memory allocation related stuff | Is void* necessary apart from memory allocation related stuff in C++?
Can you give me an example?
| Logging memory addresses
If you want to output a pointer using iostreams (e.g. for logging) then going via void* is the only way of ensuring operator<< hasn't been overloaded in some crazy way.
#include <iostream>
struct foo {
};
std::ostream& operator<<(std::ostream& out, foo*) {
return out<<"it's a trap!";
}
int... |
7,298,912 | 7,298,993 | Convert NSDictionary to std::vector | I want to convert an NSDictionary mapping integers to floating point values into a C++ std::vector where the key from the original NSDictionary is the index into the vector.
I have code that I thought would work, but it seems to create a vector larger than the number of key-value pairs in the dictionary. I'm guessing i... | Initialising a vector with a number creates that many entries to begin with. In this case, your vector will start with 16 elements, and each insert will add elements, so you'll end up with 16 + N elements.
If you want to change an element to a new value simply assign to it. Don't use insert:
result[index] = fValue;
Ho... |
7,299,171 | 7,299,212 | Union member has a non-trivial copy constructor | I have a union that looks like this:
union {
int intValue;
double doubleValue;
std::string stringValue;
void *pointerValue;
} values;
When I compile it, I get this error message (yes, I did #include <string>):
./Value.hh:19:19: error: union member 'stringValue' has a non-trivial copy constructor ... | You cannot.
A union combines two pieces of functionality: the ability to store an object which may be of a select number of types, and the ability to effectively (and implementation-defined) convert between those types. You could put an integer in and look at its representation as a double. And so forth.
Because a unio... |
7,299,196 | 7,299,746 | Drawing Text with GDI+ | I have searched for some days now to find a possibility to display text on my GDI+ application.
I tried using the DrawString() function of GDI+ but the reference on MSDN does not work as it does not match with the parameter list. I am using Visual C++ 2010 Express.
I changed the MSDN example to make it compile, like th... | You are making the fairly classic mistake of not checking the return value of Graphics::DrawString(), it will tell you what you did wrong. InvalidParameter is pretty likely here. It is also quite unclear in which context this code runs, that better be inside the WM_PAINT message handler or you'll never see the output... |
7,299,282 | 7,299,551 | relinking hex code and running on another machine | if i could get the hex code of a function in one machine
how would i relink it and execute on another machine
i.e,
if i get the functions hex code from a disassembler
and the function called a windows API
void newfunc()
{
call some_API;
}
for running on another machine i would have to relink it to call that machin... | To do what you have described under Windows would require duplicating the PE Loader functionality.
Under Windows, what usually happens is:
call [some_API_addr] ; uses in-program data
in the RDATA section of the PE:
some_API_addr: dd 0 ; filled in by the Loader with the address in the DLL
You can't just ... |
7,299,476 | 7,299,509 | Boost::Multiindex vs string indexed boost::unordered_map | I need a container of unique elements to be accessed with a triplet of int, and each int can be over 1.000.000.000.
(Only few of these elements will be actually filled, and actually these elements are boost::unordered_map themselves).
Is it faster to have a multiindex array like boost::multiindex (or maybe something el... | Multi-index isn't what you want, you seem to want a single index whose type is a triple. (Unless you actually do want three independent indexes; if I misunderstood, leave a comment.)
Don't use strings, heavens no. Just use the triple as a key:
typedef std::tuple<int, int, int> key_type;
If you use an std::map<key_type... |
7,299,539 | 7,299,582 | What is the guid string that represents the file path? | I see the file in my trash bin has the path as:
C:\Recycle bin\{3x-for-example-guid-4x}\file.txt
I would like to know how to get the real path, the one before it is transfered to the trashbin.
| See the answer in this post for how to read out the path. Also see How to restore files from recycle bin
The original link refers to a C++ article: How to programmatically use the Recycle Bin
|
7,299,666 | 7,299,742 | Can I use C++ with Windows Phone 7? | I'm going to write an application for iOS, Mac OS X and Windows Phone 7.
To minimize the amount of work, I'd like to write the model only once, in C++ (otherwise I'd have to do it twice; in Objective-C and in C#).
Can I use C++ in a Windows Phone 7 application, together with C#?
| Taken from here: Windows Mobile 7 and C++
All Windows Mobile 7 (now called Windows Phone 7 ) development, at
least initially, will be in managed code. Development using native
languages like C/C++ is not supported for third parties. You can
develop apps and games for Windows Phone 7 using the Silverlight or
XN... |
7,299,679 | 7,299,712 | C++, please explain Classes to a Python user? | I'm trying to learn C++, Thanks to this article I find many similarity between C++ and Python and Javascript: http://www.cse.msu.edu/~cse231/python2Cpp.html
But I can't understand C++ Classes at all, they looks like Javascript prototypes, but not that easy.
For example:
//CLxLogMessage defined in header
class myLOG: p... | myLOG is the name of the class. It inherits (look it up2) from CLxLogMessage and has the functions GetFormat (which is virtual and can be overridden by subclasses and called through base class pointers, look it up2), Error, and Info. It has the data member authoringTool which is a string.
The public and private stuff i... |
7,300,027 | 7,301,352 | Add QTextEdit objects to a QMainWindow | I seem to be having an issue. Objective: I want to dynamically add QTextEdit to a QMainWindow, I have a lot of data I wish to split amongst various QTextEdit objects. I've been looking at centralWidget and did some digging into ui->setupUi(this); generated by the Qt Creator and spotted that the parent for objects of... |
I wanted to add multiple QTextEdit so I can use a residing QListWidget
(the index property) to switch amongst the many QTextEdit widgets
You could put a QStackedWidget in place of your QTextEdit, and add all the QTextEdits to it.
Only one of the textedits would be visible at all time, but you can switch between the... |
7,300,245 | 7,300,301 | Container of pointers Issue | I have classes A, B, C, D and the following hierarchy:
class A {
B* b;
};
class B {
C<D>* c;
};
template <class T>
class C<T> {
list<T*> ds;
};
class D {
};
I allocate A first as an A* member inside a base class, using new A(). Within A I allocate b using new B(). Within B I allocate c using new C<D>().... | Your code, to my knowledge, should not care one way or another what the contents of list ds are. When you insert elements into containers and things like that you need to ensure that your element type supports all the necessary functionality (i.e. its assignable, copyable, and has the correct functions within it depen... |
7,300,306 | 7,300,338 | C++ overwriting data in a file at a particular position | i m having problem in overwriting some data in a file in c++. the code i m using is
int main(){
fstream fout;
fout.open("hello.txt",fstream::binary | fstream::out | fstream::app);
pos=fout.tellp();
fout.seekp(pos+5);
fout.write("####",4);
fout.close();
return 0;
}
the problem is even after using... | The problem is with the fstream::app - it opens the file for appending, meaning all writes go to the end of the file. To avoid having the content erased, try opening with fstream::in as well, meaning open with fstream::binary | fstream::out | fstream::in.
|
7,300,375 | 7,300,447 | #including a class header does not specify type | I am encountering a very strange problem in my wxWidgets application. What I am trying to do is use a custom wxPanel resource to allow for some redundancy control and providing methods that allow me to work easier. This problem was not occurring before I tried to pass access to a resource in the main frame to each pane... | You are can't include CPAMountMain.h in CopyRow.h and CopyRow.h in CPAMountMain.h! You have to decide the order in wich you want to include the files.
Since CPAMountMain.h only use pointers to CopyRow class, you can use a forward declaration instead of including CopyRow.h:
// CPAMountMain.h
class CopyRow;
and remove ... |
7,300,543 | 7,300,598 | Convert C++ map to c arrays - Performance | Is there a better way in terms of performance to convert a map imap to char* array[] and integer array in C?
map<string, int> imap; // Code below will build the imap
....
....
....
char** carr;
int* iarr;
*carr = (char**)malloc(sizeof(char*)*imap.size());
*iarr = (int*)malloc(sizeof(int)*imap.size());
index = -1;
... | No, there isn't. Just beautify your code a little. I guess a good compiler will optimise all the anomalies.
I would avoid calling c_str(), I would just create the array of STL string if possible, because that is the thing that uses up most time in your script.
Also side note: I myself place beautiful, understandable c... |
7,300,550 | 7,301,035 | Faster WinSock sendto() | I'm using Windows Server 2008, and my program is in C++.
I'm using WinSock2 and sendto() in a while(true) loop to send my packets.
Code like so:
while(true)
{
if(c == snd->max)
c = snd->min;
dest.sin_addr.S_un.S_addr = hosts[c];
iphead->destaddr = hosts[c];
sendto(s, castpacket, pktsz, 0, cast... | I would recommend moving to asynchronous I/O to speed things up a bit here. The main problem with sending them one at a time is that you are unable to queue up the next packet while the TCP stack is processing the current one.
Alterntively, you can go for a thread pool approach: you fire a certain number of worker thre... |
7,300,584 | 7,305,392 | Using Facebook Connect (which is in Objective C) in C++ code | I have already created a button widget in my game. When I press it, I want a dialog pop up, asking the user to login in with their Facebook account.
I've already downloaded Facebook iOS Connect, but it is written purely in Objective C. My game project is written in C++.
| I'm assuming you're targeting iOS, in which case you can compile your code as Objective-C++, which basically allows you to use both languages together. Try changing your .cpp files to .mm files.
|
7,300,636 | 7,300,671 | function ptr to a function with template arguments | how would i define a function ptr which points to a function which gives back a boolean but takes two unknown (but equal) types as arguments?
Should be something like this, but my IDE marks this as wrong:
template<class arg>
bool (ptr*)(arg,arg);
I also want to combine this with a function which takes such a function-p... | You can't have template typedefs, which seems to be what you're asking about initially. For the function which takes a function pointer you can do:
template<class arg>
void function(arg one,arg two,bool (*comparefunction)(arg,arg))
instead.
Your initial syntax is also wrong:
bool (*ptr)(arg,arg); // * goes before the ... |
7,300,650 | 7,300,864 | How to find TMax without using shifts | Using ONLY
! ~ & ^ | +
How can I find out if a 32 bit number is TMax?
TMax is the maximum, two's complement number.
My thoughts so far have been:
int isTMax(int x)
{
int y = 0;
x = ~x;
y = x + x;
return !y;
}
That is just one of the many things I have unsuccessfully have tried but I just cant think of a prop... | Something like this perhaps?
0x7FFFFFFF is the maximum positive signed 32 bit two's complement number.
int isTMax(int x){
return !(x ^ 0x7FFFFFFF);
}
I am not sure, you may need to cast it to unsigned for it to work.
|
7,300,969 | 7,339,824 | Do I need to make a type a POD to persist it with a memory-mapped file? | Pointers cannot be persisted directly to file, because they point to absolute addresses. To address this issue I wrote a relative_ptr template that holds an offset instead of an absolute address.
Based on the fact that only trivially copyable types can be safely copied bit-by-bit, I made the assumption that this type n... | To avoid confusion let me restate the problem.
You want to create an object in mapped memory in such a way that after the application is closed and reopened the file can be mapped once again and object used without further deserialization.
POD is kind of a red herring for what you are trying to do. You don't need to b... |
7,301,120 | 7,301,214 | Checking if all bits in k between 1 to n are set | I was reading one question on the blog and the solution of the question was to check whether 1 to n bits in 'k' are set or not.
For ex.
k = 3 and n = 2; then "True" since 1st and 2nd bit are set in k
k = 3 and n = 3; then "False" since 3rd bit in k is not set
The solution as provided by the author is:
if (((... | If you draw out the binary representations on pen and paper, you'll see that (1 << (n-1)) always sets a single bit to 1 (the n-th bit), whereas (1 << n) - 1 sets the first n bits.
These are bitmasks; they're being used to manipulate certain sections of the input (k) via bitwise operations (&, | and ^).
Note
I think the... |
7,301,543 | 7,301,560 | Can a lambda have extern "C" linkage? | This seems to work on the platforms I have tried:
#include <iostream>
// extern "C" linkage
extern "C" void foo(void (*fn_ptr)(int));
namespace {
struct bar {
static void f(int);
};
}
int main() {
// Usually works on most platforms, not guaranteed though:
foo(bar::f);
// Probably equally bad or worse?... | No. Lambdas are ultimately objects that have a function call operator. A captureless lambda can be converted into a function pointer of its appropriate type, but that function pointer will be a C++ function with C++ linkage.
|
7,301,577 | 7,313,271 | Replacing memcpy in a safe way | I want to replace memcpy with my own optimized version to do some benchmarks.
I wouldn't like to modify each place in code which calls memcpy(it's a large code base and I want to avoid lots of changes). So what I did is the following:
// in a "common" header file which is included everywhere
#ifdef SHOULD_OPTIMIZE
... | I just found another way to replace the memcpy function call. It only works with GCC(I still need to find another way for VC++) but I think it's definitely better than the crude #define way. It uses the __REDIRECT macro(in sys/cdefs.h included via features.h), which from what I've seen it's used extensively in the glib... |
7,301,649 | 7,302,035 | How do I loop through results from std::regex_search? | After calling std::regex_search, I'm only able to get the first string result from the std::smatch for some reason:
Expression.assign("rel=\"nofollow\">(.*?)</a>");
if (std::regex_search(Tables, Match, Expression))
{
for (std::size_t i = 1; i < Match.size(); ++i)
std::cout << Match[i].str() << std::endl;
}
... | regex_token_iterator takes an optional fourth argument specifying which submatch is returned for each iteration. The default value of this argument is 0, which in case of the C++ (and many other) regexes means "the whole match". If you want to get the first captured submatch, simply pass 1 to the constructor:
const std... |
7,301,872 | 7,301,887 | How to open multiple files using fopen and file pointer? | I have a predetermined amount of one-dimensional double arrays and want to write each one of them to a file. For example, if I have 96 arrays, I'd like to have 96 different files containing these arrays.
I'm initializing a file as follows:
FILE * f=fopen("domain001.txt","w");
...
...
...
fclose(f)
I'd like to do this ... | I'm not sure i got what you want..maybe this?
FILE* files[FILE_N];
for(int i = 0; i < FILE_N; i++) {
char filename[50];
sprintf(filename, "domain%03d", i);
files[i] = fopen(filename, "w");
}
|
7,302,053 | 7,302,211 | How to "dereference a type" in C++03? | How do I get the "dereferenced type" of another type in C++03? Note that it can be other dereferenceable type like std::vector<int>::iterator.
e.g. if I have
template<typename T>
struct MyPointer
{
T p;
??? operator *() { return *p; }
};
How can I figure out what to replace the ??? with?
(No Boost! I want ... | In the general case, you can't. For raw pointers, you can partially specialize as shown in other answers- custom smart pointers may have a common typedef for the result type. However, you cannot write a single function that will cope with any pointer in C++03.
|
7,302,099 | 7,302,144 | Question about 3D model loading | When processing a 3D model file with libraries like cstdio, wouldn't it be faster to load whole file to a new buffer with a file's length size, and then process it instead of frequent using file data accessing functions ?
My question applies both to binary and text model formats, but especially to the second ones wher... | One negative aspect would be that if this is single threaded the CPU isn't doing anything while the entire file is being read into memory which could even extend loading times.
However the speed gains or losses are probably negligible in any case.
Again, not directly addressing the problem but: If processing time is a ... |
7,302,111 | 7,302,134 | Finding the max random number | I am instructed to find the max number generated from a 2D array: arr[10][10]. Is this code correct? To me its seems to work.
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int maxArray(int arr[][10], int rcap, int ccap) {
int max = arr[10][10]; srand(time(0));
for (int r=0; r < r... | I think you were asked to create a random 2D array and then find the max:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int maxArray(int arr[][10], int rcap, int ccap ){
int max = 0;
for (int r=0; r < rcap; r++)
for(int c=0; c < ccap; c++)
if(arr[r][c] > max) ... |
7,302,122 | 7,302,131 | in C++, what do the underscore signs in the multi-inheritance classes mean? | here is the code:
PiGenerator::PiGenerator(PP_Instance instance)
: pp::Instance(instance),
graphics_2d_context_(NULL),
pixel_buffer_(NULL),
flush_pending_(false),
quit_(false),
compute_pi_thread_(0),
pi_(0.0) {
pthread_mutex_init(&pixel_buffer_mutex_, NULL);
}
Or is this even multi-inheritance? Can someo... | It's (probably) just a convention: often, private variables are declared with a tailing underscore, so that one can easily recognize them.
|
7,302,269 | 7,311,448 | Disabling warnings about Boost headers in XCode 4.1 | I am writing a C++ program that uses Boost, using XCode 4.1 as IDE and compiler front-end. I get quite a lot of warnings in various Boost headers, and I would like to disable all warnings for those headers (but still enable them for my own project). Is there an easy way to do so?
| I have found a decent workaround, based on what @Georg Fritzsche suggested:
I have added the various incriminated boost headers to the .pch file (the pre-compiled header), and wrapped them around a #pragma push - #pragma pop block, like this:
// We do not want to have warnings about Boost headers!
#pragma GCC diagnosti... |
7,302,460 | 7,302,481 | Equation to find the degrees of rotation of a once horizontal line | hey so I have a center of an object and i'm making a line with this center as the start of it, and the mouse position the end of it.
How do I find how rotated the second point (?,?) is around the stationary first point (0,0) ?
Note: if the second point were (1, 0) it would be roated 0 degrees.
| Remember SOHCAHTOA? ;) You can use the arctangent (via the standard atan2() function) to determine the angle of the line between the origin and an arbitrary point:
#include <cmath>
double mouseX = ...;
double mouseY = ...;
double angleInRadians = std::atan2(mouseY, mouseX);
|
7,302,602 | 7,302,650 | Why is ~size_t(0) (== 0xFFFFFFFF in most 32-bit systems) not a valid array index? | Quoting from this blogpost:
http://www.codesynthesis.com/~boris/blog/2008/10/13/writing-64-bit-safe-code/
This works because a valid memory index can only be in the [0, ~size_t(0)-1] range. The same approach, for example, is used in std::string.
So why is ~size_t(0) (this should usually equal 0xFFFFFFFF in 32-bit sys... |
IMPORTANT NOTE: The term "memory index" is ambiguous and confusing. The linked article refers strictly to array indexes, not addresses in memory. It is entirely valid for size_t to be incapable of representing all memory addresses, which is why we have the intptr_t type in C99. Of course, this doesn't apply to your... |
7,302,630 | 7,302,654 | Is there any chance to use C++ for Web applications in the future? | Coming from Python and Javascript background, I'd like to know if there is any chance to use C++ for Web applications in the future.
I mean...if C++ is only for Desktop applications and mostly Game Engines or Operation Systems, then how you can guarantee future of this language?, I know C++ is unbeatable for many tasks... | There's a C++ web application toolkit that you can use right now. There's at least one site which was implemented in C++. Facebook has a tool that converts PHP code into C++, which is compiled with GCC, and their servers run the executable.
So it's definitely possible to use C++ in some form for web applications. It's ... |
7,302,692 | 7,303,056 | How to compile a C++0x code on Eclipse CDT on mac? | Can someone point to flags and setup changes required for one to compile C++0x code on a Eclipse CDT on mac please ?
| The latest Apple gcc compiler is gcc 4.2 which does not support C+11 code. You need to install a gcc 4.6 - this can be done from source or there are some binaries at hpc this put the gcc in /usr/local/bin Then use that in the preferences fot the C++ compiler in eclipse.
Alternative for Lion and above Xcode 4.* includes... |
7,302,693 | 7,302,719 | Reading image byte array with OpenGL | I have a bitmap image that is currently represented as a byte array (could be YCrCb or RGB). Is there a function build in to OpenGL that will allow me to looks at individual pixels from this byte array?
I know that there is the function glReadPixels but I don't need to be reading from the frame buffer if I've already ... | OpenGL is a drawing API, not some kind of all purpose graphics library – The 'L' in OpenGL means should be read as Layer, not library.
That being said: If you know the dimensions of the byte array, and the data layout, then it is trivial to fetch individual pixels.
pixel_at(x,y) = data_byte_array[row_stride * y + pixel... |
7,302,813 | 7,302,833 | initiate array inside function call | My Question is related to the release of the c++11 standard and this old question, as I wondered if it is now possible to create an array/vector inside a function call, instead of building the array/vector before and then just giving it as an parameter to the method/function.
| (Presuming you're talking about C++11.)
void f(int x[]) {} // remember, same as void f(int* x) {}
int main() { f({0,1,2}); }
// error: cannot convert '<brace-enclosed initializer list>'
// to 'int*' for argument '1' to 'void f(int*)'
But:
void f(const int (&x)[3]) {}
int main() { f({0,1,2}); }
/... |
7,302,888 | 7,302,909 | c++ custom matrix template using pointers | Here is a matrix template I recently started implementing. It doesn't have many functions since, like I said, I just started it.
Header file:
#ifndef MATRIXX_H
#define MATRIXX_H
#include <iostream>
using namespace std;
template <typename theType> class Matrix
{
public:
Matrix()
{
rows = columns = 0;
matrixRo... | Matrix<int> a(r, c); // Invokes constructor with arguments.
You are not initializing the member variables rows and columns present in the two argument constructor. And so getting some garbage values from their getters.
Matrix(int rows, int columns) : rows(rows), columns(columns)
// ^^^^... |
7,303,336 | 7,303,357 | Returning a dynamic C style string from a function? | Basically I have a function that roughly looks like this and I need to return out.
const char* UTF16ToUTF8(const wchar_t *in) {
int tmp = wcslen(in);
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &in[0], (size_t)tmp, NULL, 0, NULL, NULL);
std::vector<char> out;
out.resize(size_needed);
WideCharT... | Don't trouble yourself with any such worries and return an std::string:
std::string UTF16ToUTF8(const wchar_t *in) {
std::vector<char> out;
//...
return std::string(out.begin(), out.end()); // or std::string(out.data())
}
Then, in your C interface, use:
printf("%s", UTF16ToUTF8(ws).c_str());
I would even make ... |
7,303,561 | 7,304,628 | Is there a vector that can handle integers of nonstandard bit-lengths? | I'm looking for something resembling an STL vector but can handle integers that are, for example, 12, 16, 20, 24, 32, and 40 bits long. The 16-bit and 32-bit cases are handled wonderfully by vector<uint16_t> and vector<uint32_t>, but I haven't been able to find any way to handle the other ones. Note that the whole purp... | There is none in the STL.
I understand you performance concern, and notably the memory issue. However unaligned reads (requiring bit-shifting) can be slower than regular ones (on bytes boundaries), so I would suggest keeping to whole bytes. This means:
12 bits, 16 bits: uint16_t
20 bits, 24 bits: either 3 uint8_t or 1... |
7,303,723 | 7,304,478 | C++: efficient swap() when using a custom allocator | It seems to be the month of C++ templates for me...
I have a SecureString. SecureString looks just like a std::string, except it uses a custom allocator which zeroizes on destruction:
class SecureString
{
public:
typedef std::basic_string< char, std::char_traits<char>, zallocator<char> > SecureStringBase;
typedef z... | Unfortunately... no.
This is not what rebind is for. rebind is used because an allocator is meant to allocate objects of one type, and one type only (std::allocator<T>) in the STL.
However, there is a trick. When you instantiate std::list<T, std::allocator<T>> for example, then the allocator does not have to allocate T... |
7,303,808 | 7,309,974 | C++ Armadillo code in C# | I would like to use Armadillo in a C# application, Anyone had any experience using armadillo in C#, I am not familiar with C#.
I know armadillo has a .dll, is there anyway to import this dll in c#...
| If you have to use LAPACK, BLAS or Eispack with C# you can use DotNumerics
DotNumerics is a Numerical Library for .NET. The library is written in pure C# and has more than 100,000 lines of code with the most advanced algorithms for Linear Algebra, Differential Equations and Optimization problems. The Linear Algebra li... |
7,303,957 | 7,305,844 | PInvoke: Error in returing text from C++ to C# | I am using Pinvoke for Interoperability between Native(C++) code and Managed(C#) code. What i want to achieve is get some text from native code into my managed code as a retrun value i.e My C# Code calls my C++ function which returns some text back to C#. Following is my code for this.
C++ Code:
static std::wstring WST... | I guess the problem is that you are allocating memory with your C++ runtime's allocator but then the C# marshaller attempts to deallocate it. That cannot work. You need to allocate and deallocate with the same allocator.
The best way I know to solve your problem is to marshal with a BSTR. That uses the COM allocator wh... |
7,304,026 | 7,304,445 | Extracting submatches using boost regex in c++ | I'm trying to extract submatches from a text file using boost regex. Currently I'm only returning the first valid line and the full line instead of the valid email address. I tried using the iterator and using submatches but I wasn't having success with it. Here is the current code:
if(Myfile.is_open()) {
boost:... | Use boost::smatch.
boost::regex pattern("what(ever) ...");
boost::smatch result;
if (boost::regex_search(s, result, pattern)) {
string submatch(result[1].first, result[1].second);
// Do whatever ...
}
|
7,304,302 | 7,304,309 | undeclared first use this function - compile error C++ LinkedList | I have a function that inserts a new node at the tail end of a linkedlist:
void LinkedList::insert(Node* previousPtr, Node::value_type& newData)
{
Node *insertPtr;
insertPtr->setData(newData);
insertPtr->setNext(previousPtr->getNextPtr());
previousPtr->setNext(insertPtr);
}
In another function I am ... | You are missing something like
some_linked_list->insert(some_node_ptr, ...)
or you could make copydata a member of the LinkedList class:
void LinkedList::copyData(Node* sourcePtr, Node*& headPtr, Node*& tailPtr)
|
7,304,502 | 7,304,806 | C++ struct memory layout and OpenGL glVertexPointer? | I have following struct to store my vertex data.
struct Rz3DContourNode {
float x; //pos x
float y; //pos y
float z; //pos z
float nx; //normal x
float ny; //normal y
float nz; //normal z
};
I store list of vertices in STL vector as follows :
std::vector < Rz3DContourNode > nodes;
When I try to use... | sizeof(Rz3DContourNode) == 6*4 = 24 bytes ... not 12!
The stride is the # of bytes between the start of each vertex, not the padding. Although 0 is a special value that indicates tightly packed data.
So, if you're using 3 floats as vertex data, there's no difference between a stride of 0 and 12 (because 3 floats are 1... |
7,304,696 | 7,307,090 | Meaning of 'instantiation' with respect to templates |
Note that code is instantiated only for member functions that are called. For class templates, member functions are instantiated only when they are used.
The above quote is from the book: C++ Templates by Addison Wesley.
I want to understand the meaning of the jargon "code is instantiated". Does it mean that only a p... | This is a quite interesting question that should be done in the wider context of how templates are processed by the compiler. Basically templates are code patterns from which the compiler generates classes of functions. A template can be used to generate anything from no code at all (if never used) to an indefinite num... |
7,304,699 | 7,304,730 | What are all the syntax problems introduced by the usage of angle brackets in C++ templates? | In C++ templates are instantiated with angle brackets vector<int> and the Java and C# languages have adopted the same syntax for their generics.
The creators of D, however, have been quite vocal about the problems that angle brackets bring and they made a new syntax foo!(int) — but I've never seen too many details abou... |
but haven't compilers become able to parse that syntax, nowadays?
Of course. But it’s far from trivial. In particular, it prevents you from implementing a clean separation between context-unaware lexer and parser. This is particularly irksome for syntax highlighters and other support tools that need to parse C++, but... |
7,304,745 | 7,305,000 | Initializing class object-array | Is there a way to initialize an array like so:
static const vec3d<long> XI[Q] = {
vec3d<long>( 0, 0, 0 ),
vec3d<long>(-1, 0, 0 ), vec3d<long>( 0,-1, 0 ), vec3d<long>( 0, 0,-1 ),
vec3d<long>(-1,-1, 0 ), vec3d<long>(-1, 1, 0 ), vec3d<long>(-1, 0,-1 ), [etc]
};
where
00039 template<typename TYPE>
00040 class... | Your copy-constructor is not correctly declared -
the toCopyFrom parameter needs to be const:
vec3d<TYPE>( const vec3d<TYPE>& toCopyFrom)
Edit:
Now, on your second problem regarding the subscript operator:
The subscript operator operator[]() in your base class does not have const (i.e. read-only) semantics. In your ... |
7,304,749 | 7,304,955 | How much memory should be allocated for the DIB data received from HBITMAP using GetDIBits function? | How much memory should be allocated for the DIB data received from HBITMAP using GetDIBits function?
The GetDIBits function is described in MSDN as follow:
int GetDIBits(
__in HDC hdc,
__in HBITMAP hbmp,
__in UINT uStartScan,
__in UINT cScanLines,
__out LPVOID lpvBits,
__inout LPBITMAPIN... | I think the simplest way is calling GetObject() function (And BTW to get the image bits):
BITMAP bmpObject;
GetObject(hBitmap, sizeof(BITMAP), &bmpObject);
Then you simply use the Bitmap Fields:
LONG size = bmpObject.bmWidthBytes * bmpObject.bmHeight;
Be aware of alignment whem processing image bytes!
Hope this will ... |
7,304,786 | 7,304,878 | One pointer, two different classes in c++ | Suppose I have two structures a and b, each hold several variable in them (most of the variable are c++ core types but not all).
Is there a way to create a a pointer named c that can point to either one of them? Alternatively, is there a way to create a set that can hold either one of them?
Thanks
| The usual way to create a pointer that can point to either of the two is to make them inherit from a common base-class. Any pointer of the base-class can point to any sub-class. Note that this way you can only access elements that are part of the base-class through that pointer:
class Base {
public:
int a;
};
clas... |
7,304,950 | 7,304,978 | Programming C++ on OSX in Macbook pro | I'm thinking of getting a new laptop. Is OSX C++ programmer friendly? I mainly use gedit, gdb, g++, meld, ddd (gdb front end), valgrind and RabbitVCS (svn) in Ubuntu. Does OSX have equivalent softwares.
| Yes, Mac OS X works well for many programmers. As for the specific software you mentioned:
You can get gedit for Mac OS X.
gdb is included with Xcode.
g++ is also included with Xcode.
It looks like Meld has a Fink package.
I was able to compile and run ddd successfully.
When I tried it quite a while ago, Valgrind did ... |
7,304,956 | 7,518,745 | Unicode and Android NDK | Is there any way to use UTF-8/16 strings in the NDK without including a multi-megabyte library such as ICU? Is ICU built in to Android?
| ICU is only multimegabyte if you go with a default build including all this, hundreds of codepages and several hundred locales worth of data.
Have a look at "Making ICU Smaller". I just added a note about using static builds.
HTH
|
7,305,059 | 7,305,611 | I want to call method in *delegate.m from C++ | I have a button written purely in c++;
but I need to call facebook connect ,since it is written in objective c.
so I wonnder if I could call the method written in *delegatel.m from c++.? if it`s ok,how?
thanks for your help.
| Simply change the extension of your source file from *.cpp or *.m to *.mm, so it will compile as Objective-C++. This means that it will be able to mix C++ and Objective C code in the same file.
|
7,305,249 | 7,305,780 | how to work with an .so file without running it at the command line g++ | I've created a .so file called car.so. I would like to test and work with this library in a test.cc code . In the command line i would like to compile: g++ test.cc -o test. I don't want to also link (include) the library car.so.
How to do that?
My test.cc code looks like this:
void* handle = dlopen("/home/v3/car.so", ... | in General you should include .h file of your .so library in your (application)/ test.cc then compile that test.cc file by linking that .so file & use generated binaray.
i think this link will realy help you..
http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html
|
7,305,614 | 7,307,256 | #include <gdiplus.h> causes error | When I include gdiplus.h in a program that compiles well the first(there are many) error I get is:
c:\program files (x86)\microsoft sdks\windows\v7.0a\include\GdiplusImaging.h(77): error C2504: 'IUnknown' : base class undefined
Part of GdiplusImaging.h:
IImageBytes : public IUnknown <<< error!
{
public:
...
Why... | These are the standard includes for using GDI+:
#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
|
7,305,629 | 7,305,732 | C++ - manipulating objects in a STL vector? | I have structure like this:
struct Rz3DContourNode {
float x;
float y;
float z;
float nx;
float ny;
float nz;
};
And I store elements in a STL vector as follows :
std::vector < Rz3DContourNode > nodes;
Now I want to change the nx,ny compoent of the nodes in the vector.I tried as follows:
*(&nodes[i].nx)... | It works on my compiler....
Taking the address of the instance and then dereferencing it is the same as not doing it all.
So you don't need it. So replace this
*(&nodes[i].nx)=newNXValue;
with
nodes[i].nx = newNXValue;
Here is the code sample I tried:
#include "stdafx.h"
#include <stdio.h>
#include <vector>
struct ... |
7,305,921 | 7,305,966 | Strict aliasing rules and std::copy | I have a character array that contains "serialized" data that I need to interpret as 'int's. Previosuly I just cast a pointer to the location to an 'int*' and dereferenced that to get at the int data, but although it's worked well for me it's breaking the strict alias rules and therefore undefined behavour.
So now I us... | This is equivalent to std::memcpy(&i, data, sizeof(int)) and suffers the same problems of relying on endianness and the assumption that sizeof(int) <= sizeof(data), which are platform-dependent. char * is exempt from the strict aliasing rule.
|
7,305,925 | 7,306,046 | Is MinGW stable enough | Is MinGW (gcc port on Windows) stable enough for compiling a DLL consisting of various data algorithms (no DirectX, no graphics, ...) for 24/7 production?
We need to make a decision and from many reasons we do not want to use Visual C++.
So question is: "Is current MinGW stable enough for production?"
| It is several years old (13 years it seems), and actively maintained. It has a branching strategy that has a stable branch and a development branch. I'd call that stable enough for production :)
Licensing might be an issue for you, though. If you don't pay anyone, you have no contractual support, and can't sue if th... |
7,306,013 | 7,306,049 | C++ boost::thread operator()() question | This is my first attempt to use boost::threads and I have a silly question.
I call a boost:thread to use one of my template class functions. However after reading this tutorial it says to construct an operator()() which I did.
Will the code below work properly ?
template <class S>
class SarsaL : public Task<S,Policy>, ... | You don't have to use the operator()() if you provide a method on the object to be executed (in this case updateEpsilons). Obviously this operator()() is not correct because it does not call the appropriate updateEpsilons method with a parameter.
Note that in the tutorial, the new thread is created giving just an insta... |
7,306,491 | 7,306,618 | may i know which C++compilers(online/free) supporting "inheriting constructors" feature in c++0x | May i know which C++compilers(online/free) supporting "inheriting constructors" feature in c++0x
N3290 draft :section 12.9 : Inheriting constructors
I tried with VS10,GCC 4.6.0 ..But i think it is not supporting ..(please confirm it.)
Please tell me which online compilers or Free compilers supporting .. This feature
... | So let's see:
google didn't find any compiler claiming to implement it;
overview pages don't list any compiler claiming to implement it;
clang, Comeau, GCC, and MSVC overview pages don't claim they implement it.
Seems consistent to me!
Maybe you do not like the answer you found, but it appears to be correct!
EDIT: Ad... |
7,306,999 | 7,307,053 | Debugging An ATL Exe COM Server | In Visual Studio 6, I have written an ATL COM server EXE. I want to debug this and put a breakpoint at the start of the method I am calling. I start debug and then call the method from the other EXE but the breakpoint is never hit. This was working fine a couple of weeks ago. I could break into it no problem. I can't w... | Your exe or pdb probably don't match the source. Try rebuilding the project, and make sure the executables you've just built are used by the server.
FWIW, you can also place a call to DebugBreak in your code. If the source and executables indeed don't match, the debugger will let you know when it breaks.
|
7,307,200 | 7,307,358 | Can I access a base classes protected members from a static function in a derived class? | I have a program where I need to make a base class which is shared between a dll and some application code. Then I have two different derived classes, one in the dll one in the main application. Each of these have some static member functions which operate on the data in the nase class. (They need to be static as are u... | In general (regardless of whether the function is static or not), a
member function of the derived class can only access protected base
class members of objects of its type. It cannot access protected
members of the base if the static type is not that of the derived class
(or a class derived from it). So:
class Base ... |
7,307,368 | 7,307,392 | what does ' t ' denote in copy constructor? | #include <iostream>
using namespace std;
class tester {
public:
int a;
tester( int x ) {
a = x;
}
tester( tester &t ) {
cout << t.a;
}
};
int main() {
tester t(10);
tester t_1(t);
}
output : 10
In definition of copy constructor what does t refer to ? From main when i passed t in the argument of t_1,it's... | In copy constructor t is an reference to the object of the type tester.
Copy constructor is a copying function.
It creates a copy of an object of an class, So it takes the object of that class an parameter. This copy constructor is called to create temporary copies of object during call by value in function calls etc. ... |
7,307,521 | 7,307,591 | Pointer to base class and private inheritance | The following simple example will produce a compiler error, since I accidently use private inheritance:
main.cpp:21: error: ‘A’ is an inaccessible base of ‘B’
class A
{
};
class B : /*ups forgot that -> public*/ A
{
};
int main(int , char *[])
{
A* test = new B;
return 0;
}
Could you help me and explain... | Private inheritance means that for everyone except B (and B's friends), B is not derived from A.
|
7,307,540 | 7,381,187 | Distributing state across many machines | I'm trying to write up a tool that requires knowledge of the state of other machines in a cluster (local LAN). This is for a network failover/high availability system similar to VRRP and corosync/openais, but I wish to contain more information (such as near real-time speed/performance characteristics) so devices can ma... | I'm not sure if there is any application for your purpose or not.
But I know that you can write a simple program with MPI library and broadcast any information that you want.
all client's can send their state to root node, and the root node then broadcast the message.
functions that you need for this are:
MPI_Bcast
MPI... |
7,307,695 | 7,308,019 | SpinBoxDelegate and QItemDelegate | I work on project It's like SpinBoxDelegate in Qt sample project but I must customize It, I mean having different widget(textbox) in second and third column of table view instead of spainBox.What do you suggest?
| Try instead tableView.setItemDelegate(&delegate); from the example something like QTableView::setItemDelegateForColumn().
Plus have a look at this one tutor.
|
7,307,830 | 7,307,882 | error: void value not ignored as it ought to be | template <typename Z> Z myTemplate <Z> :: popFromVector ()
{
if (myVector.empty () == false)
return myVector.pop_back ();
return 0;
}
int main ()
{
myTemplate <int> obj;
std :: cout << obj.popFromVector();
return 0;
}
Error:
error: void value not ignored as it ought to be
AFAI can see,... | std::vector<T>::pop_back() returns void. You attempt to return it as an int. This is not allowed.
|
7,307,857 | 7,317,160 | LIBSSL Static lib Compiling issue with fpic | I compiled libssl using
CC="gcc34 -fPIC" CXX="g++34 -fPIC" CFLAGS="-m64 -fPIC" ./config --prefix=/workspace/libs/gcc34/64/ssl shared && make clean && make && make install
but when I try to link this static generated library with my dynamic library
I am getting
relocation R_X86_64_PC32 against `OPENSSL_cpuid_set... | There're recommendations to use -Wl,-Bsymbolic to fix this error.
https://openssl-dev.openssl.narkive.com/uAKes0jM/openssl-org-1521-bug-report
http://www.opensubscriber.com/message/openssl-users@openssl.org/1901249.html
|
7,308,226 | 7,308,335 | recursive divison of number | I have following code to divide one number recursively by another number:
#include <iostream>
using namespace std;
int divide(int number,int dividend){
int answer=0;
if (number>dividend || number==dividend ){
answer+=1;
return divide(number-dividend,dividend);
}
return answer;
}
... | Answer is a local variable. When you run this code, the first call to divide creates an instance of the answer variable, sets it to 0, and then increments it to 1. Then, when you recursively call divide again, it creates a brand new instance of the answer variable, sets that instance to 0, and then increments that inst... |
7,308,384 | 7,308,425 | Argument passing by reference to pointer problem | Every time I try to compile my code I get error:
cannot convert parameter 1 from 'int *' to 'int *&'
The test code looks like this:
void set (int *&val){
*val = 10;
}
int main(){
int myVal;
int *pMyVal = new int;
set(&myVal); // <- this causes trouble
set(pMyVal); // <- however, this doesn't
}
I'd lik... | A reference to non-const cannot bind to an rvalue. The result of the & operator is an rvalue. Take a look at the difference between lvalues and rvalues or read a good C++ book.
Also, in your context, you don't need to pass by reference. The following is OK as well:
void set (int *val){
*val = 10;
}
The reference wo... |
7,308,620 | 7,308,768 | Do you have to implement multiple iterators in a STL-like class? | I'm quite familiar with the STL and how to use it. My question is...
If I were to implement my own STL container type, how are the internal iterators defined? STL classes tend to have sequential or random-access iterators, const_ versions of these, and stream iterators.
Are these iterators all fully-defined in every S... | Generally, you only have to implement iterator and const_iterator.
If reverse iterators are desired, they can be obtained using
instantiations of std::reverse_iterator. The stream iterators will use
operator>> and operator<<; typically, they aren't appropriate for a
container (and none of the standard containers provi... |
7,308,638 | 7,314,446 | C++: undefined reference to function | I have the problem, that I want to compile some software using the lib hqp. This lib uses adolc, but a deprecated function from an old version. As I only have the new version, one class (adoublev) is missing and I get compile errors. Now I try to write a wrapper but here I get errors.
Before: I was till now not aware o... | Since your class Prg_T2Topt is based on Omu_Program, it inherits Omu_Program's methods including consistic(), and since your class does not override consistic(), compiler is trying to use Omu_Program::consistic().
What libraries are you linking with? It looks like you missing something during linking phase.
|
7,308,833 | 7,308,945 | Creating a QList from a plain array | I have this
Struct values[] = {
{ a, b },
{ c, d }
};
And I just want to create a QList out of it
QList<Struct> ql(values + 0, values + 2);
But for some reason, QList has no suitable constructor and seemingly no suitable insert function. How does this work? I'm on Qt4.6.
| One solution would be to first create an std::list and then convert that into a QList:
QList<Struct> ql =
QList<Struct>::fromStdList(std::list<Struct>(values + 0, values + 2));
However, that would incurs two copies of the array content instead of just one.
The other solution is to use std::copy along with a back_... |
7,308,887 | 7,308,937 | Is it possible for 2 windows managed by Windows to have the same window handle value? | Is it possible for 2 windows managed by Windows to have the same window handle value?
Consider both cases when these 2 windows are opened by the same process and when these 2 windows are opened by 2 different processes.
| Quick answer: no, it's not possible if they are inside the same desktop, every window handle issued by the window manager is unique (inside its desktop) throughout all the existence of the window, otherwise it couldn't uniquely identify such window on the system current window station desktop (which is defined by MSDN ... |
7,309,040 | 7,310,572 | EDG ,get C++ friend data | I use edg software (Edison Design Group)to parse C++ code.
I need to get information about all friends classes.
For example for
class A;
class B;
class C{
private:
int x;
double y;
public:
friend class A;
friend class B;
}
I need to get that A,B classes are friends for C,when parsing ... |
Can anyone tell me, where can I find the info for freinds classes ? And may be give some code for example for friends data retreiving?
Yes, there is someone, who can. As i know, edg is commercial product (closed-source) and if you can use it, you or your company have a commercial support plan. So, you can ask the EDG... |
7,309,141 | 7,309,392 | System.AccessViolationException in Visual Studio 2008 | // diskbin.cpp : main project file.
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <fstream>
#include <conio.h>
#include <stdio.h>
#include <sys/stat.h>
using namespace std;
int main( int argc, char *argv[] )
{
//code
if(stat("key.pc.db", &filek) ==0 )
sizek=filek.st_size;
if(stat... | It's crashing because you're using uninitialized variables:
int sizes, sizek;
struct stat files, filek;
ofstream ofs;
if(stat("key.pc.db", &filek) ==0 )
sizek=filek.st_size;
if(stat("seek.pc.db", &files) ==0 )
sizes=files.st_size;
sizek=sizek/sizeof(int);
sizes=sizes/sizeof(int);
if s... |
7,309,206 | 7,309,231 | Question about const pointer in C++? | I cannot explain myself the following code:
double d = 100;
double const d1 = 30;
double* const p = &d; // Line 1
double* const p1 = &d1; // Line 2
In the above code, Line 1 is ok, but Line 2 produces the error:
"error C2440: 'initializing' : cannot convert from 'const double *__w64 ' to 'double *cons... | The type double* const is a const pointer to a non-const double. If you want a pointer to a const double, you have to use double const* (or double const* const if you want a const pointer to a const double).
In C++, with a simple pointer to a double, you the const-ness of both the pointer itself (ie, can you make it po... |
7,309,277 | 7,311,103 | Heap Violations when releasing a CStringArray& parameter from a DLL exported function | I have developed a MFC dll containing a function having this prototype:
//DLL code
long __declspec(dllexport) GetData(CString csIdentifier, CStringArray& arrOfData)
{
//based on the identifier I must add some strings inside the string array
arrOfData.Add("...");
arrOfData.Add("...");
/*.................... | In order to share MFC objects like CStringArray across an exe/dll boundary, you'll need to make the DLL be an MFC Extension DLL. See: https://msdn.microsoft.com/en-us/library/h5f7ck28(v=vs.140).aspx
From the section on Memory Management:
MFCx0.dll and all extension DLLs loaded into a client application's address spac... |
7,309,302 | 7,309,346 | why is this C++ program using constructor and destructor showing error? | The following program is showing error:
#include<conio.h>
#include<iostream.h>
int count = 0;
class alpha
{
public:
alpha()
{
count++;
cout<<"\n Number of objects created "<<count;
}
~alpha()
{
cout<<"\n Number of object destroyed"<<count;
coun... | There is no header <iostream.h> in standard C++. Use the header <iostream> which has names in std namespace, thus not polluting the global namespace with names as count.
Don't forget to use std::cin, std::cout etc. from now on.
If your compiler doesn't recognize <iostream>, throw it away and get a new one. Visual Stud... |
7,309,514 | 7,310,519 | Execute External function belonging to other process | I would need help with a problem. I have 2 processes running, one the Watchdog and the other a simple test process. I need process 2 to call code from the Watchdog, the reason I do this is to reduce the size of process 2. For example process 2 must call a function called "IsSafe" from the watchdog. The IsSafe function ... | Although putting the code in the process which needs to call it is good advice in general, in the particular case of a watchdog (also debugger and any other form of error handler) using separate processes is correct. You don't want the watchdog to fail due to an error in the main code, so it needs to be a separate pro... |
7,309,762 | 7,310,127 | c++ win32 SendInput() | How can I simulate key press with SendInput()?
I want to make it to simulate for example in a notepad to press shift+q. So a Q would appear in the notepad if I run my program.
| You need 4 inputs: shift down, q down, q up, shift up. Therefore, use a INPUT[4].
|
7,309,838 | 7,310,021 | Improper marshaling: C# array to a C++ unmanaged array | I have the following C# code with a structure definition (CInput), obj definition and init, and a call to a C++ (native) DLL function (that has also been written by me).
//C# code
public struct CInput
{
[MarshalAsAttribute(UnmanagedType.R8)]
public double Time;
[MarshalAs(UnmanagedType.SafeArray, SafeArrayS... | As I understand your question, you can't use ByValArray with SizeConst because your real struct has a large number of such arrays which results in the stack overflowing.
You opine that maybe you need to use pointers in your structs and I agree with you. Here is how to do it.
On the C++ side you should declare each arra... |
7,309,962 | 7,310,022 | Holding scrollbar freezes win32 console application | I wrote this little program to illustrate my problem :
int main(int argc, char* argv[])
{
int i = 0;
while(1)
{
std::cout << i++ << std::endl;
Sleep(1000);
}
return 0;
}
So this simple program will stop counting if you hold the vertical scroll bar ( to watch back logs or whatever ...).
Is... | Not really. What happens is that holding the scrollbar prevents the application to write any new output to the console, so it eventually blocks on flushing std::cout. This is due to how Windows implements the console and can not be avoided.
|
7,310,297 | 7,310,353 | OpenGL texture color issue | I'm loading raw texture (with alpha channel) and displaying it in openGL everything is fine and texture displayed, but color is little bit darker than original. I already tried to turn of lighting, blending and dithering, but this doesn't helps.
I'm using mac osx.
Sample image
http://postimage.org/image/2wi1x5jic/
Her... | Maybe you have GL_MODULATE set as texturing environment and the vertex colours are not white. Try setting the texture environment to GL_REPLACE.
glBindTexture(GL_TEXTURE_2D, your_texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
EDIT
Another problem may be a color profile embedded into the image. A... |
7,310,421 | 7,310,438 | removing elements by value in C++ - does the preferred idiom really consist of a double negative? | I came across this answer to the question of removing elements by value in C++:
C++ Erase vector element by value rather than by position?
Basically:
vec.erase(std::remove(vec.begin(), vec.end(), valueToRemove), vec.end());
The answer makes sense, but isn't this bad style? The logic is consists of a double negative..... | Deleting an element from a collection consists of two steps:
Moving down all subsequent elements to fill in the holes created by matches
Marking the new end
With the C++ standard library, these are two separate functions, remove and erase, respectively.
One could certainly imagine an erase_if type of function which w... |
7,310,624 | 7,310,662 | Expected content of a dynamic vector | I have to store integer values which are mapped to other integers. One way to do it is use a std::map m. But then to retrieve the value using m[int] or m.find(int), will be an order of logN (N is number of elements) time. In my case N is pretty large (upto 2^30). I thought using a std::vector will be faster for access ... | std::vector<int> v;
v.assign(6, -1);
v[3] = 10;
v[10] = 100; // Unlucky with this statement
The size of the vector is just 6. And the accessing index is from 0 to 5. Your first snippet has undefined behavior that you got unlucky that it didn't break when accessing an index 10. If there is a notion a key association... |
7,310,714 | 7,310,748 | C++ CopyFile() does not works on c:\ | hello guys i have one simple program which copying itself. Its work great when i copying in D disk. But when im trying to copy it on c disk nothing happens.
This is code :
int main()
{
string appDir = "";
appDir = std::string( result, GetModuleFileName( NULL, result, MAX_PATH ) );
CopyFile(appDir.c_... | By default, the system drive has locked down permissions which prevent anyone from copying things there who are not administrators. Generally, one should not be messing with the root of the drive. If you need to do something like an installer, then you should
Ask for Admin rights
Install yourself in the correct locati... |
7,310,941 | 7,311,013 | Import, use and compile a single c++ header file in an ios objective-c project | I'm sure the answer is simple but I am facing the following problem ...
I want to use this c++ header file CAAudioUnitOutputCapturer.h (there is only a .h file) inside an ios objective-c xcode project.
Could someone tell me how to eliminate compilation errors and give me an example of how to use in Objective-C context?... | At the moment, the compiler is trying to build your file as pure Objective C, which is causing these errors. Rename the file you are compiling it into as myFile.mm (note the mm extension). This will force the compiler to consider it as Objective C++ code, which by virtue of the header you're including, it is.
|
7,310,955 | 7,504,315 | cuda kernel not changing input arrays | My CUDA Kernel doesn't seem to be changing the values of the arrays I pass in, here's the relevant host code:
dim3 grid(numNets, N);
dim3 threads(1, 1, 1);
// allocate the arrays and jagged arrays on the device
alloc_dev_memory( state0, state1, d_state0, d_state1,
adjlist, d_adjlist, transfer,... | I found that the values of N and numNets were garbage values. The offset by N was wrong, so the values were being set outside of the array. @pQB, your suggestion was just what I needed.
|
7,311,041 | 7,311,303 | const to Non-const Conversion in C++ | I'm really annoyed by const keyword these days, as I'm not quite familiar with it. I had a vector that stores all const pointers like vector<const BoxT<T> *> *Q_exclude, and in the constructor of another class, I need an element in this queue to be passed in as a parameter and assign it to a non-const member. My questi... | You can assign a const object to a non-const object just fine. Because you're copying and thus creating a new object, constness is not violated.
Like so:
int main() {
const int a = 3;
int b = a;
}
It's different if you want to obtain a pointer or reference to the original, const object:
int main() {
const int... |
7,311,323 | 7,605,804 | Strange Exceptions using RapidXml under Windows CE 6.0/Windows Mobile/Windows Embedded Compact | I'm having a very strange problem when trying to run RapidXml 1.13 under Windows CE 6.0 compiled with Visual Studio 2005. I have an extremely small program that fails to run:
#include <rapidxml.hpp>
using namespace rapidxml;
int _tmain(int argc, _TCHAR* argv[])
{
xml_document<char> doc;
return 0;
}
It compil... | I found the solution. RapidXML allocates its own pool of memory once its loaded. Problem is, I think it allocates it on the stack and I was getting a stack overflow! (How serendipitous that the problem with my first question here actually WAS a stack overflow). Anyways, reducing the size of the pool solved my problem.
|
7,311,435 | 7,311,475 | How do I embed WebKit in a window? |
Possible Duplicate:
How to embed WebKit into my C/C++/Win32 application?
I am trying to embed the WebKit project into my solution. At first I'd like to just render the Webkit inside a typical window and make it load some pseudorandom URI.
I tried checkouting the sources from http://svn.webkit.org/repository/webkit/t... | There is an accepted answer for "How to embed WebKit into my C/C++/Win32 application?". I think it might be the best place to start. IIRC WebKit provides various interfaces for different features and you need to make sure that you have implementations for all the ones that you require in your application.
ChromiumEmbed... |
7,311,477 | 7,311,560 | Overload cast operator between two enums | Is there a way to overload a cast operator to convert between two enums?
In my code I have
enum devStatus
{
NOT_OPERATING,
INITIALISING,
DEGRADED,
NORMAL
};
enum dataStatus
{
UNAVAILABLE = 1,
DEGRADED,
NORMAL
}
where NOT_OPERATING and INITIALISING map to UNAVAILABLE; DEGRADED and NORMAL ma... | In C++, conversion operators can only be declared within class, struct, and union declarations. They cannot be declared outside the type (like operator+, for example). Enum type declarations do not support instance members, so you will need to go with the conversion function. Doing so will also make the calling code cl... |
7,311,480 | 7,311,505 | Can I determine whether a pointer is of integral type via type traits? | By using type traits, I can find out whether a type is integral or a pointer (and more). Is it also possible to find out whether the pointer being passed is that of an integral data type (int, float, char) and not an object?
EDIT: In addition to Armen's answer, if anybody is using the LOKI library instead of Boost, the... | boost::is_pointer<T>::value &&
boost::is_integral<boost::remove_pointer<T>::type>::value
Btw float is not integral. You probably need is_arithmetic
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.