result of memcpy(&x[0], "fsd", 3)
string x; 78 x.reserve(100); 79 x[0] = '1'; 80 x[1] = '2'; 81 x[2] = '\0'; 82 x.resize(3); 83 cout << "sdfs: " << x.c_str() << endl; 84 cout << &x[0] << endl; 85 return 0 test result: print nothing ...
string x; 78 x.reserve(100); 79 x[0] = '1'; 80 x[1] = '2'; 81 x[2] = '\0'; 82 x.resize(3); 83 cout << "sdfs: " << x.c_str() << endl; 84 cout << &x[0] << endl; 85 return 0 test result: print nothing ...
I'm reviewing our Visual C++ code base and see lots of helper functions with really short bodies. Like for example this: inline int max( int a, int b ) { return a > b ? a : b; } the problem is when code is debugged in Visual Studio debugger it's impossible to immediately see what a and b are upon entering the function with F11 ("step ...
I am trying to start a method from my main() as a new thread with pthread: int main(int argc, char** argv) { pthread_t shipGeneratorThread; Port portMelbourne; pthread_create(&shipGeneratorThread, NULL, portMelbourne.generateShips(), NULL); return (EXIT_SUCCESS); } The Port class has a function that generate...
Just ran into this: #include <iostream> using namespace std; int main(int argc, char** argv) { float *a = new float[10]; void **b; b = static_cast<void**>(&a); delete(a); return 0; } macbook:C nils$ g++ -Wall -g -o static_cast static_cast.cpp static_cast.cpp: In function ‘int main(int, char**)’: static_cast.cpp:...
Is it possible to make my member functions final as in Java, so that the derived classes can not override them? ...
Hello, I'm trying to learn Qt, with a fairly simple application: #include <QtGui/QApplication> #include <QPushButton> #include <QDebug> /* -- header begin {{{ */ class BareBase { public: BareBase(); }; class BareBones: public QApplication { private: BareBase* base; public: BareBones(int &argc, cha...
I have created a Win32 Service using C++ and installed to the Services Successfully. Now While I try Starting the service from Services.msc , I am getting the Error: Could not start the Service on Local Computer . Error 2: The system can not find the File specified. Here is the code snippet I am defining in the Service Entry Point: #i...
Possible Duplicates: How does delete[] know the size of the operand array? ( POD )freeing memory : is delete[] equal to delete ? As I understand, the following class A {}; A* a = new A; // delete A; will result first in a call to operator new() (the global one, or a specialized one provided by A) to allocate the right amo...
My application dynamically loads liba.so (with dlopen). liba.so uses libb.so so I want to link liba.so against libb.so. How to do this in Linux? Thanks in advance. ...
I came across the following code - what is the data type of col_8888 and why does it reference the union _colours? I googled unions, but I can't find a reference to this kind of declaration - it looks to me as though col_8888 is a "union of unions"? union _colours { uint8 c[3][4]; uint32 alignment; }; static const union _colou...
Hi! Imagine I create an instance of Foo on the heap in a method/function and pass it to the caller. What kind of smartpointer would I use? smartptr new_foo() { smartptr foo = new Foo(); return foo; } void bar() { smartptr foo = new_foo(); foo->do_something(); // now autodelete foo, don't need it anymore } Ok... n...
Hi friends, I am having multiple monitors(virtual+real) and by default I wanted to put it in clone/dual mode from my program. Can some one suggest how do I achieve this? I am very new to this world:) sorry for this basic question.... even any doc or any link will be highly appreciable. /sarbojit ...
Look at this code snippet: Size::Size(int iSetWidth, int iSetHeight) :iWidth(iSetWidth), iHeight(iSetHeight) { } Supposedly, this means the same thing as: Size::Size(int iSetWidth, int iSetHeight) { iWidth=iSetWidth; iHeight=iSetHeight; } Why would you use the former or the latter? And what is the name of the former? ...
Can a static libary *.a in Linux be dynamically loaded at runtime? I've read here that ...both static and shared libraries can be used as dynamically loaded libraries. How to dynamically load static library? ...
I think I have a problem with my makefile. I'm writing this program: Q2.cpp contains the main. Agent.cpp Agent.h Timing.cpp Timing.h RandomDouble.cpp RandomDouble.cpp And I'm using the header randoma.h in RandomDouble.cpp. I downloaded the randomaelf64.a file and I wrote this makefile: Q2 : Q2.o Agent.o Timing.o RandomDouble.o ...
Hi all, I want to store a sequence of string in a queue. This seems pretty simple if i use the member function push() queue test; string s0("s0"), s1("s1"); test.push(s0); test.push(s1); I am thinking about adding the strings in the queue in implicitly way. That mean, if I type the following sequence of string the e.g. operator >> s...
What does it mean: Object's observable state? I was reading yesterday in "Exceptional C++" Solution to item 43 and there is a fragment: private: void InvalidateArea() { area = -1; } Even though this function modifies the object's internal state, it should be const. Why? Because this function does not modify the object's observabl...
I'm trying to implement a structure which is basically a custom made hash table containing either nothing (NULL) or a pointer to a binary search tree object. Anyway, I'm having trouble figuring out how to do some things, such as setting the hash table, which is an array to NULL, and also memcpy'ing BST objects from one table to another....
Hi, If I were to create a unit test for class implementation using QTestlib ( trying to figure it out) how would I do it. (I know unit testing for the simple class below can be done other simple way I trying to understand QTestlib framework and whether its really what I want) Consider a simple class ( just to make things really clear )...
I'm using bcp to extract Boost.Archive from Boost. Unfortunately I can't build this extract. Boost.Archive is not a header-only library. bjam complains Unable to load Boost.Build: could not find "boost-build.jam" Is there any way to tell bcp to make the extract buildable with bjam (copy boost-build.jam to the right place)? ...