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,172,567 | 6,183,261 | C++ web framework like spring for Java | Is there any web framework in C++ which is like Spring for Java, i am currently working on an application which is in the web domain. Our existing applications are all developed in c++, and we are looking for some framework which has a small learning curve and provides exciting features. Has anyone come across such a f... | I just found ffead-cpp while browsing similar threads, can anyone evaluate this framework or has any idea whether this would be a suitable choice. I think it already answers a few of my questions. Can you guys comment?
|
6,173,032 | 6,173,237 | How to find out which included files are not part of current VC++ solution | Among other things, I would imagine a Visual C++ solution is meant to encompass all source code files for a given product. However, thanks to the "Additional Include Directories" and the built-in C++ ability to include absolute and relative paths -- it is possible to include files that are not part of the solution (sta... | The include files that are not a part of the project usually automatically placed in the "External Dependencies" folder of the project in Solution Explorer.
|
6,173,150 | 6,173,165 | Get the text from any type of document | Is there any way (Win32API or other) to get the text from any type of window? I can get the HWND of the active window, but calling sending a WM_GETTEXT message doesn't always give me the text (MS Word being a good example).
I am trying to make a universal spellchecker, where from any application, the user presses a hot... | You're not going to be able to do this without referencing application-specific APIs. Different applications handle text differently.
In Notepad, for example, the text is just a string in a multiline text-box which the Windows API can retrieve.
Word, however, handles the text internally and renders the display as ... |
6,173,187 | 6,173,633 | How do I draw a large (500+) number of sprites to build an isometric tiled map in DirectX 10? | So, I've been puttering around with a few books on DirectX (specifically 10) and am trying my hand at building a game that uses it, but I'm stumped by a problem that none of the books seem to mention: I'm building an isometric map with sprites and as the board gets larger, the program slows down dramatically. Each tile... | The whole point of DrawSpritesImmediate is that you want to call it with an array of hundreds or thousands of sprites... not one sprite at a time.
Alternatively, try changing your "Immediate" call to using DrawSpritesBuffered, followed by a ID3DX10Sprite::Flush (outside the loops, just before the End()).
But even wit... |
6,173,226 | 6,173,486 | virtual forward iterator? | I looked at STL's forward iterator. I don't see any virtual functions anywhere. If I have a library that wants a forward iterator of strings how can I allow the function to take any forward iterator that returns strings? Is there anything in the standard library I can use?
| There are no virtual methods as they are not meant to be used polymorphically (in the common sense of runtime polymorphism) but rather through templates (static polymorphism). The common approach is having the function that takes the iterators templatized on the type of the iterator. You can find many examples in the S... |
6,173,690 | 6,256,838 | Simple ray collision library (bonus if it loads 3ds and b3d) | I've spent quite some time searching a simple / fast c++ library (Win / Linux) that can answer the two questions 'does this ray crosses any of the triangles?' or 'where is the first intersection, if there are any?'.
It's for my little game I'm writing and will be used to see if a NPC can see a player and also to check ... | Well, there seems to be no 'simple & small' library / code out there so I guess the answer might be 'roll your own'.
That is what I did anyway:
a tool that uses Irrlicht to load up my (static) geometry and then save off all (triangle/vertex) data to a file, just 9 floats for each triangle.
Then a collision library that... |
6,173,845 | 6,174,816 | How to implement MS specific _BitScanReverse() function? | From MSDN
Search the mask data from most significant bit (MSB) to least significant bit (LSB) for a set bit (1).
unsigned char _BitScanReverse
(
unsigned long * Index,
unsigned long Mask
);
Parameters
[out] Index
Loaded with the bit position of the first set bit (1) found.
[in] Mask
The 32-bit or 64-bit value to ... | GCC has some similar built-ins:
— Built-in Function: int __builtin_clz (unsigned int x)
Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined.
— Built-in Function: int __builtin_ctz (unsigned int x)
Returns the number of trailing 0-bits in x, start... |
6,173,899 | 6,174,373 | how to convert ucs4 to ucs2 using C++ and ucs2 to ucs4? | Is there any C++ method support this conversion?
By now i just fill character '0' to convert ucs2 to ucs4, is it safe?
thanks!
| It's correct for UCS2, but that's most likely not what you have. Nowadays, you're more likely to encounter UTF-16. Unlike UCS-2, UTF-16 encodes Unicode characters as either one or two 16-bit units. This is necessary because Unicode has more than 65536 characters in its current version.
The more complex conversions usua... |
6,173,915 | 6,174,604 | Need help trying to make Cmake find third party libraries | I currently have a project that links to two third party libraries. These libraries have to be built by themselves and then linked to the project. One is taglib and the other is zlib. I noticed that when you use the Cmake-gui program on the taglib directory you're required to specify where zlib has been built and insta... | In the case of ZLib, a FindZLIB.cmake is provided with CMake and you can "simply" put a find_package call in your cmakelists. If necessary you can make some modifications to findzlib.cmake to suit your needs. E.g. adding ZLIB_DIR as an additional hint when searching for the library. This ZLIB_DIR can then be set by the... |
6,174,033 | 6,183,558 | OpenCV 2.2 SURF Feature matching problems |
I have modified the OpenCV demo application "matching_to_many_images.cpp" to query a image (left) to a frames from the webcam (right). What have gone wrong with the top right corner of the first image?
We think this is related to another problem we have. We begin with an empty database and we only add unique (features... | I think this has to do with the border keypoints. The detector detects the keypoints, but for the SURF descriptor to return consistent values it needs pixel data in a block of pixels around it, which is not available in the border pixels. You can use the following snippet to remove border points after keypoints are det... |
6,174,083 | 6,175,029 | Boost.intrusive multiple containers | In the boost.intrusive document, it mentions about using multiple containers to store in one object. However, there's no actual example, so I made my own. Is this the right way to do?
#include <boost/intrusive/list.hpp>
struct tag1;
class A:public list_member_hook<>, public list_member_hook<tag<tag1> >
{
}
typedef lis... | You're close. Here's what it should look like:
#include <boost/intrusive/list.hpp>
struct tag1;
class A:public list_base_hook<>, public list_base_hook<tag<tag1> >
{
}
typedef list_base_hook<tag<tag1> > TagHook;
typedef list<A> DefaultList;
typedef list<A, base_hook<TagHook> > TagList;
int main()
{
DefaultList d... |
6,174,091 | 6,174,132 | If uncheck inline box when adding function to a class, only the function protoype is needed in the classname.h? | Can anybody help me to clear this thing out?
I use Add Member Function Winzard to add a function to class. If I uncheck Inline box, there is only function prototype like below appear on classname.h file:
CBox operator+(const CBox& aBox) ;
and on the classname.cpp file, there is the full function:
CBox CBox::operator+(... | When you select in-line, it means that the code will be dropped in at the location that is being called. For this reason, the entire implementation needs to be in the header file. If you don't select inline, it will be placed in the cpp file, as one (and only one) copy should be compiled and linked.
Inlining code may m... |
6,174,135 | 6,174,152 | What consumes more storage space - boost::dynamic_bitset<> or raw storage? | I have a program storage optimization question.
I have, let say 4096 "knots" stored in a:
boost::dynamic_bitset<>
I am now considering refactoring my program and build a CKnot class which will contain a bool.
The question is what will consume more space:
boost::dynamic_bitset<> ( 4096 , false );
CKnot Knot[4096] //... | The bitset will be considerably smaller, as a bool in C++ must be at least a byte in size, whereas each bit in a bitset is exactly that, a bit.
|
6,174,137 | 6,174,170 | have a nice representation of a string from a double | I have a double 1.4291400000000001
I want to have a string representation of that double.
What is the best/standard way to get 1.42914
| What about:
std::stringstream ss;
ss << std::fixed << std::setprecision( N ) << double_number;
// ss.str() gives you the string
|
6,174,244 | 6,174,407 | Is opening a shared memory multiple times bad in any way? | I have a class which opens a posix shared memory using shm_open. Now I have to create objects of this class multiple times (5-10 objects total), and that means the same shared memory is going to be opened that many times.
The shared memory has variable size, and can be from 1k to 500k.
The questions regarding this are ... | The answer is on the page you linked shm_open to:
shm_open() creates and opens a new, or opens an existing, POSIX shared memory object. A POSIX shared memory object is in effect a handle which can be used by unrelated processes to mmap(2) the same region of shared memory.
To access a shared memory object, you need a ... |
6,174,268 | 6,174,297 | Compile time RAII type of behavior using C++ | I know it sounds a bit wierd but this is what I want to do: Lets say I have a function void f() and I want to add tracing for this method. I want to trace the enrty of this function and the exit of the function by having trace messages such as "Entered function f" and "Exited function f". I don't want to add manual tra... | The point at which the method is left is only known at runtime, since any kind of exception can happen at any point in your code (generally speaking). Hence, no compile-time solution is possible here.
|
6,174,368 | 6,174,579 | Is it possible to find out what is leaking GDI Objects | I have an application in Embarcadera RAD Studio 2010 (C++). Is it possible to peek into it to see what would be leaking GDI Objects? A tree structured menu is leaking GDI Objects when text is set to Bold. My guess is that the "original" text is first created and then an instance where it is in bold and the first one is... | AQTime is my tool of choice. It's a profiler and brings many more features than just GDI leak detection. RAD Studio XE comes with the Standard version of AQTime. For the Pro version you need to pay more.
|
6,174,543 | 6,176,987 | how to set the priority to get the mutex in C/c++ | I have 3 process (equal priority)
P1
P2
P3(timer)
priority to get the mutex is as follows: P1(1 priority), P2(2 priority), P3(timer)(3 priority)
If suppose p3 comes and get the mutex
then p2 comes and wait for mutex
after that p1 comes and it also wait for mutex
if p3 release mutex then p1 should get the mutex not p... | Since the threads have equal priority, which thread gets the lock will be rather arbitrary. It appears you want to wait on a condition variable rather than using a simple mutex. You will still have a mutex; condition variables are a concept on top of mutexes. Another possibility is to use synchronization barriers.
EDIT... |
6,174,614 | 6,176,531 | Qt and SQlite Database, How do i count queries? | I've tried a lot of things.
query.isNull()
tried the query.Record() then int col = query.Record()
if I put query.size() it will return -1 even if the query has result.
How do i count queries in SQLite?
I wanted to do this:-
if(the query returns null or empty)
{
do this;
}
else
{
do that;
}
| query.size() does not work with the SQlite database driver in Qt. You can do:
query.exec();
bool gotResults = false;
while (query.next()) {
gotResults = true;
// do something with the result using query.value(...)
}
if (!gotResults) {
// do something else
}
|
6,174,730 | 6,174,915 | Qt: Are non-rectangular QWidgets allowed to overlap? | If I have multiple non-rectangular custom QWidgets (e.g. circle-shaped buttons), can I overlap them?
It seems there is no way to let Qt know which parts of the widgets are opaque, so mouse event are delivered to the correct QWidget (It looks like Qt assumes each widget occupies its bounding rectangle).
Should I turn th... | You can give QWidgets a mask if you want them to be non-rectangular. This should work, but it's not always straightforward to create the mask region. QGraphicsItem certainly makes handling non-rectangular shapes much easier.
|
6,174,756 | 6,174,837 | How do I check whether a number is divisible by 2*M_PI in c++? | This is what I've done for checking the divisibility of a number by 2*M_PI. "w" is a constant that's 2/3 and t is the variable that varies by t += dt, where dt is 0.1. I'm trying to use the mod operator, %, to see if something is divisible. But its not working.
bool divisible;
real w = 2/3;
real t;
if((w*t) % 2*M_PI ==... | Use std::fmod instead, it operates on doubles rather than the integral % operator.
|
6,174,764 | 6,174,948 | Template code optimization for specific values of non-type parameters. | template <bool flag>
class foo
{
public:
int bar()
{
if(flag)
{
// stuff
}
}
};
When the compiler compiles this class, it replaces the flag parameter by true or false. Then we have if(true) ( or if(false) ). Then, the if clause checks agai... | Optimizations are compiler-specific. Why don't you create release build and step through disassembly?
Still, this is not idiomatic way to do that. You should either use template specialization or method overloading. They both provide compile-time resolving. So, in this case I would prefer the latter:
#include <type_tr... |
6,174,785 | 6,174,864 | Where should the pure virtual destructor be declared? | EDIT: Apparently the question is not clearly formulated enough. The issue I am having is that when the destructor is defined in the header it gets added into multiple .obj files and the linker complains. The actual question is:
When I add the destructor to a CPP file in a DLL project and use the dll with dynamic loadin... | The problem is that the base class destructor always gets called- but in this case, you've made it pure virtual, so it doesn't exist. The only reason to make a destructor pure virtual to is to enforce a class to be abstract when you have no other members. The destructor of a class needs to be defined in all cases.
Edit... |
6,174,955 | 6,175,524 | What kinds of types does qsort not work for in C++? | std::sort swaps elements by using std::swap, which in turn uses the copy constructor and assignment operators, guaranteeing that you get correct semantics when exchanging the values.
qsort swaps elements by simply swapping the elements' underlying bits, ignoring any semantics associated with the types you are swapping.... | This doesn't work either for types that have pointers to "related" objects. Such pointers have many of the issues associated with "inner" pointers, but it's a lot harder to prove precisely what a "related" object is.
A specific kind of "related" objects are objects with backpointers. If object A and B are bit-swapped, ... |
6,175,190 | 6,175,920 | C#, C++ , WinAPI - Get Number of windows from another process | It can be answer in C# or C++ or WinAPI (I know how to pInvoke).
What I want to achieve.
I want to get number of windows that are opened by another applicatoin.
For example I have Chat application. I want to get number of windows because I wan't to detect if someone send me message (New incoming message = one more wind... | If you have the process ID of the other application, here's a possible Windows API way:
Enumerate all top level windows with the EnumWindows function, using GetWindowThreadProcessId in the callback function to test for main windows belonging to your given process. From matching main windows you can then continue to enu... |
6,175,209 | 6,175,264 | Low-latency IPC between C++ and Java | What is the best way to implement C++/Java IPC for the following situation?
(Someone recently asked a similar question, but my requirements are more specific)
I have two programs -- one written in C++, the other in Java -- that need to communicate with each other. Both are running on the same machine.
The programs sen... | I'd suggest you to use TCP sockets.
The actual overhead of TCP sockets, as of my experience, is very very low compared to the other tasks' workload of the applications, at least the ones I use to develop. I mean, sometimes even if sockets' latency is twice as the latency of other IPC mechanisms, in the overall workflow... |
6,175,333 | 6,175,368 | c++ Why is memory allocated when passing a string literal to a function? | I have his code:
int setAttrib(const string& name, int components){
// here I don't even touch 'name'
if(components == 2) return 3;
else return 1;
}
And I call the function this way:
setAttrib("position", 3);
I'm profiling memory with xcode profiler and in the function call std::string is making an al... | You ask for a const string&, but pass in a const char*. The compiler thus needs to create a temporary object of the correct type.
The fact that "position" is not an std::string but a char const* is more of a historical accident (inherited from C, when there was no string class in C++) than a design decision, but someth... |
6,175,355 | 6,175,407 | Handle removable media USB/CD-ROM mount/umount events on Linux and Mac | I need to implement cross platform handler for the removable media mount/umount events. It was not hard to implement it on Windows, now I need to rinse and repeat on Mac on Linux. I suppose that these platforms handle the removable media in different manners. Which APIs should I look into?
On another note, about the AP... | On Linux you would write a udev rule to get notifications on such events. Here is specific info about udev rules and your scenario: http://reactivated.net/writing_udev_rules.html#external-run
The MSDN of Linux (or at least part of it) are the man pages. Here is an online copy: http://linux.die.net/man/
|
6,175,410 | 6,175,522 | How do I display star(*) instead of plain text for password c++ | How can I do so that I can display star(*) instead of plain text for password in C++.
I am asking for password and it is plain pass on the screen.
How can I convert them in to star(*) so that user can not see the password while entering.
This is what I have currently
char pass[10]={"test"};
char pass1[1... | You need to use an unbuffered input function, like getch () provided by curses library, or a console library of your OS. Calling this function will return the pressed key character, but will not echo. You can manually print * after you read each character with getch (). Also you need to write code if backspace is press... |
6,175,502 | 6,176,389 | How to parse ini file with Boost | I have a ini file which contains some sample values like:
[Section1]
Value1 = 10
Value2 = a_text_string
I'm trying to load these values and print them in my application with Boost but I don't understand how to do this in C++.
I searched in this forum in order to find some examples (I always used C and so I'm not very ... | You can also use Boost.PropertyTree to read .ini files:
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
...
boost::property_tree::ptree pt;
boost::property_tree::ini_parser::read_ini("config.ini", pt);
std::cout << pt.get<std::string>("Section1.Value1") << std::endl;
std::cout ... |
6,175,503 | 6,175,643 | Creation of .Ocx File from a .Net Dll | I have a .Net Com Dll is it possible to use this dll and create .OCX file in c++ or MFC. If yes what are all the steps which needs to be followed. If any sample code is availabe that would be a great help
| You could expose the .NET assembly as COM object using the regasm.exe tool. You could use the [ComVisible(true)] to indicate that all classes should be visible by COM clients when registered. This assembly level attribute could also be set in the properties of the project in Visual Studio. You could also apply it only ... |
6,175,507 | 6,182,275 | Using Lua to define NPC behaviour in a C++ game engine | I'm working on a game engine in C++ using Lua for NPC behaviour. I ran into some problems during the design.
For everything that needs more than one frame for execution I wanted to use a linked list of processes (which are C++ classes). So this:
goto(point_a)
say("Oh dear, this lawn looks really scruffy!")
mowLawn()
w... | I think the approach you give loses a lot of the advantages of using a scripting language. It will break with conditionals as well as loops.
With coroutines all you really need to do is:
npc_behaviour = coroutine.create(
function()
goto(point_a)
coroutine.yield()
say("Oh dear, this lawn loo... |
6,175,675 | 6,176,484 | How to notify a widget about changes in another widget in Qt? | I am trying to implement a widget in Qt that has 2 child widgets of its own: one is a render area where I draw some points and connect lines between them and the other one is a ListBox where I would like to insert the list of all the points I drew with their coordinates from the render area. The 2 widgets where added w... | OrcunC gave you a good advice.
If your are new to signal/slots implementation here some hints you can start from.
renderarea.h
signal:
void pointAdded(QPoint*);
renderarea.cpp
void RenderArea::updateList(QPoint p)
{
list.append(p);
emit pointAdded(&list.back());
}
listbox.h
public slots:
void onPointA... |
6,175,705 | 6,175,850 | scope of using declaration within a namespace | Is it safe (and correct) in a C++ header file to use the using declaration within a namespace as follows:
#include <boost/numeric/ublas/vector.hpp>
namespace MyNamespace {
using boost::numeric::ublas::vector;
vector MyFunc(vector in);
}
I.e. is the "using boost::numeric::ublas::vector" properly contained withi... | No, it is not safe - it won't pollute another namespace, but it is dangerous for other reasons:
A using directive will import anything that is currently visible by the name you specify into the namespace where you use it. While your using will only be visible to users of MyNamespace, other things from "outside" will be... |
6,175,869 | 6,176,065 | Casting a negated double to int | is there a difference between the following code snippets?
double doubleMillis = -getSecondsSinceNow()*100; // returns double
int timestamp = (int) doubleMillis;
and
int timestamp = (int) -getSecondsSinceNow()*1000;
I see differences in the values I get in timestamp. The first one seems to give me meaningful results.... | here you cast the return value of getSecondsSinceNow() (double ) to int and multiplies it by 1000:
int timestamp = (int) -getSecondsSinceNow()*1000;
Which is like:
int timestamp = ((int) -getSecondsSinceNow())*(1000);
While in the cases below you cast the full result:
One explicitly:
double doubleMillis = -getSecond... |
6,176,036 | 6,176,058 | Dynamic memory allocation - default-initialization of primitive types in c++ | If I allocate an array of some primitive type e.g.
double *v = new double[10];
I need to know, what the inital value of the array entries will be.
Is it specified in the standard or compiler dependend and where can I find it.
Thanks,
Johannes
| No, the array contents are not initialized. You need to use double *v = new double[10](); to have the default value of 0 for each element (Notice ()).
|
6,176,126 | 6,176,188 | Sum of primes below two million. Sieve of Eratosthenes | Having a little trouble solving Problem: 'Calculate the sum of primes below two million'. I'm using the 'Sieve of Eratosthenes' method. My method works fine for finding primes till hundred but when I try to find the sum of primes till 2,000,000 I get an incorrect answer.
#include <iostream>
using namespace std;
long l... | I'm not sure an int is enough to hold the answer... It could be larger than a 32-bit value.
Try using long long throughout.
|
6,176,566 | 6,176,583 | Get 30th bit of the lParam param in WM_KEYDOWN message | I need to get the 30th bit of the lParam param passed with the WM_KEYDOWN message. This bit as written here allows me to know if the key was pressed before. Is this code right to get it?
(lParam >> 30) & 1
| I would just use lParam & 0x40000000. If that's non-zero, then b30 was set (I consider that the thirty first bit of the thirty two, by the way). And there's more likelihood that it will be a {logical-and, compare} operation rather than {shift, logical-and, compare}.
Mind you, there's a good chance that a decent compile... |
6,176,588 | 7,109,901 | Adopting Bamboo or TeamCity as native Windows C++ build automation/CI server? | At the moment, we are running our automated (not CI as such) builds via FinalBuilder via a very simple homegrown Apache interface that just launches the FB scripts on our server. (I like FinalBuilder, and will keep it, but it's CI server, FinalBuilder Server just doesn't cut it IMHO -- especially it doesn't support any... | For completeness' sake: I ended up using Jenkins + Finalbuilder. :-)
|
6,176,714 | 6,176,781 | multi parameter class templates and my 'vertices' class | I have defined a 'vertex' class which, when combined, form a graph.
these vertices receive input on one end and produce output on the other (both of these sides can have 0, 1, or more 'subscriptions' of other instances of this vertex class)
The types for both the incoming and outgoing data are independent of each other... | You want to use run-time inheritance for this.
template<typename T> struct InputVertex { ... };
template<typename T> struct OutputVertex { ... };
template<typename Incoming, typename Outgoing> struct Vertex
: public InputVertex<Incoming>, public OutputVertex<Outgoing> {
std::set<InputVertex<Outgoing>*> outgoings;
... |
6,176,744 | 6,176,818 | Convert Mat to IplImage* in OpenCV and C/C++ | in my application I have a Mat file which i'd like to show in a window with cvShowImage which is defined as:
void cvShowImage( const char* name, const CvArr* image )
Now, the problem is that if i pass directly the Mat image, it gives me an error conversion:
cannot convert 'cv::Mat' to 'const CvArr*' for argument '2' t... | Why do you try to use the C interface with C++ datatypes? Use the C++ interface.
cv::namedWindow(window_title, 1);
cv::imshow(window_title, file);
|
6,176,829 | 6,176,932 | IPC: Connect for each request or keep socket open? | I am planning to use sockets (local TCP) to communicate between two processes (running locally). One process will act as a server, but both processes send messages to each other asynchronously. Should I keep the socket connection open for the lifetime of the processes, or re-connect for each request?
Are there any prob... | Keep the socket open.
Its the simpler option and you don't incur in the overhead of opening a new socket (from the client point of view) or accepting a new client (from server point of view).
|
6,176,837 | 6,176,875 | Array objects initialization whose class has some ctor / dtor | I would like to realize array objects initialization by using the initialization statement as follows.
TestClass array[5] = {
TestClass("test1"),
TestClass("test2"),
TestClass("test3"),
TestClass("test4"),
TestClass("test5")
};
According to some authoritative book like ARM (annotated reference manu... | Whether of not the copy constructor is used by the compiler, it must be accessible - i.e. it must not be private. In this case, the compiler could avoid using the copy constructor, by using the const char * constructor directly, but it still needs an accessible copy ctor. This is the kind of thing not covered in the AR... |
6,177,100 | 6,604,187 | WxStyledTextCtrl code folding for PHP | I need to display PHP code using WxStyledTextCtrl. All is working fine except code folding.
I followed the examples in the wxWidgets page http://wiki.wxwidgets.org/WxStyledTextCtrl, they use a wxSTC_LEX_CPP lexer and it works. I adapted their code but when I change this:
text->SetLexer(wxSTC_LEX_CPP);
for this:
text->... | The Scintilla code folding for PHP is a little different than the rest since it is handled by the HTML lexer. The code below will enable code folding in PHP. The folding will look like Visual Studio (a box with a plus sign inside of it)
wxStyledTextCtrl *ctrl = // from somewhere ....
wxColour backgroundColor = // the b... |
6,177,373 | 6,177,672 | Autocompletion library in C++ | I need an auto-completion routine or library in C++ for 1 million words. I guess I can find a routine on the net like Rabin–Karp. Do you know a library that does this. I don't see it in Boost.
Also, is it a crazy idea to use MySql LIKE SQL request to do that ?
Thank you
EDIT: It is true that it is more suggestions tha... | You don't have to use any crazy algorithm if you begin by preparing an index.
A simple Trie/Binary Search Tree structure, that keeps the words ordered alphabetically, would allow efficient prefix searches.
In C++, for example, the std::map class has the lower_bound member which would point in O(log N) to the first elem... |
6,177,617 | 6,177,649 | Dynamic multidimensional arrays | Is it appropriate to call dynamic multidimesional array, an array of arrays?
int **mp = 0;
// Create an array of pointers
mp = new int*[6];
// Where each element of type pointer, points to dynamic array.
for (int x = 0; x < 6; x++)
mp[x] = new int[7];
Looking at this, I would say they are array of pointers point... | If I understand correctly, your question is about semantics. As far as the standard is concerned, new [] does create an array, but returns a pointer to the first element. From 5.3.4/5 of the standard:
When the allocated object is an array
... the new-expression yields a
pointer to the initial element (if
any) ... |
6,177,906 | 6,180,450 | Is there a reason why QVariant accepts only QList and not QVector nor QLinkedList | QVariant appears to accept QList<QVariant> and not QVector<QVariant> nor QLinkedList<QVariant>. Is it simply because it sees QList, QVector and QLinkedList as fundamentally similar (in an abstract sense) data structures?
I'm adding and std::vector to a QVariant. If using only the Qt API and not a manual conversion, thi... | Simply because QList is by far the most commonly used container type, and adding overloads for all the others would make the QVariant interface even more complex than it already is. In any case, your problem seems to be not that QVariant doesn't support QVector (it does with a little work) but that QJson doesn't. I d... |
6,178,212 | 6,178,249 | Saving user's data for my application | I was wondering what would be the correct method for saving all user data for an application I am working on. The application is in QT. The user inputs a lot of data into the application and the data will be different for every user. I want the ability for the user to save all the current data to a file that can be use... | In essense, yes you'll be creating your own file format, but the actual content can just be XML in whatever scheme you need. Then you can use Qt's built-in XML processing capabilities to pull the heavy lifting of parsing the text (I personally prefer the DOM model, so I use QDomDocument as my base point), and you'll j... |
6,178,618 | 6,191,176 | Mac OS X: is it possible to imbue a non-main thread to become "The Main Thread" of a process? | I'm having a GUI/threading-related problem under Mac OS X (10.6.7).
I'm using the wxWidgets framework (ver. 2.9.1), and it rests upon Cocoa in my case. The application design is like this:
thread #1 (a.k.a. "The Main Thread"): enters main(), parses switches, and if necessary, launches another thread (using the POSIX p... | OK, so according to your comment: you basically won't escape refactoring of your code. Most GUI systems use main thread and handle event loops for themselves. But if you say that GUI is optional, maybe it'd better to split your application into two -- worker and GUI. GUI could communicate with worker via numerous ways,... |
6,178,693 | 6,180,208 | Unhandled exception at 0x1000bbae in OCTREE.exe: 0xC0000005: Access violation writing location 0x000000a8 | I'm getting the above runtime error on the following code on line:
glutMainLoop();
Why?
#include <stdio.h>
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cassert>
#include <math.h>
#include <gl/glut.h>
#include <stdlib.h>
class Vertex {
public: float X;
... | I have not used GLUT for 7 years, so take my answer with a grain of salt. This said, your init() function makes me a bit concerned. I believe that when you write GLUT programs, you should only issue OpenGL commands in the GLUT callback functions. I'm not sure there is an active OpenGL context when your init() function ... |
6,178,771 | 6,178,801 | Inheritance and Constructors | This is not homework, just some training exercises for my C++ class in order to get used to iheritance and stuff. So the first part of the exercise ask us to create a program which has one class name Rectangle and we should do the constructors getters and setters and find the area and perimeters.This part works fine. T... | You forgot to chain the constructor for Square. You want to change the constructor of Square to read:
Square(int w) : Rectangle(w,w) {}
|
6,178,946 | 6,180,357 | Saving user's data for my application part 2 | My first question was: should I use dom, sax, or sqlite to save the data the user is inputting into my application. The answer I am going with is to use DOM.
My second question is: How should I load the contents of the file into the application when the user decides to open the file? Should it go through the whole fil... | Question 2: This very much depends on how much data you're dealing with. It will be much easier to load everything in one step. If you are expecting complex documents, it might be better to do it incrementally, but I would strongly recommend starting with the simpler approach.
Question 3: Qt does not handle this, exc... |
6,179,063 | 6,179,415 | Reference-counting instances of classes based on their types | Consider the following code:
struct I
{
SomeInternalState m_internalState;
};
struct S
{
I * m_i;
set_I (I * i)
{
m_i = i;
makeSomeChangesToTheInternalStateOfI(m_i);
}
};
struct S_1 : S { ... };
struct S_2 : S { ... };
...
struct S_n : S { ... };
It is given that an arbitrary coun... | You can use typeinfo as a key, but it's a bad idea. You should not count types in your program. Let me explain with a simple example.
Let's say you have a Vehicle type and its descendants Car, Truck and Bike. You call your function once per each of these classes. So far so good. Now you need, for a completely unrelated... |
6,179,085 | 6,179,133 | Help on build using g++ on Windows | There is a small project C++ (it has win32 code) that I need to build. It already has its Makefile. I was told to use MinGW. I have never used it before. I downloaded and installed the latest MinGW installer.
Then, I opened the MinGW shell and did make. The exe file was created. But when I try to run it I get libgcc_s_... | Whether or not the exe should be self-contained depends on how you built it. We need to see the commands that were executed, or post the makefile. But that DLL does not seem to be part of the current version of MinGW. Also, please clarify if you are actually doing this under cygwin, or if you added the tag by mistake.
... |
6,179,197 | 6,179,225 | Search/replace array of characters pointed to by a character pointer in c++ | Here's my function call:
removeTags(*buf, bufSize);
which calls:
void removeTags(char* dataBlock, unsigned long size)
{
char* start = dataBlock;
char* end = dataBlock + size;
while(start < end)
{
//How do I replace the characters "\abc" with just nothing, ''.
}
I want to replace any ins... | Once you find an instance of \abc simply move all the characters after the \abc backwards four places (four because \abc is four chars long) (possibly using memmove).
For instance:
one two \abc three
<----^ copy everything from the 't' down backwards over the \abc
Note that after you do that, your end pointer ... |
6,179,295 | 6,179,580 | Should I unify two similar kernels with an 'if' statement, risking performance loss? | I have 2 very similar kernel functions, in the sense that the code is nearly the same, but with a slight difference. Currently I have 2 options:
Write 2 different methods (but very similar ones)
Write a single kernel and put the code blocks that differ in an if/else statement
How much will an if statement affect ... | You have a third alternative, which is to use C++ templating and make the variable which is used in the if/switch statement a template parameter. Instantiate each version of the kernel you need, and then you have multiple kernels doing different things with no branch divergence or conditional evaluation to worry about,... |
6,179,314 | 6,179,354 | Casting pointers and the ternary ?: operator. Have I reinvented the wheel? | The last line of this code fails to compile with castingAndTernary.cpp:15: error: conditional expression between distinct pointer types ‘D1*’ and ‘D2*’ lacks a cast
A really smart compiler could have no difficulty because both can be safely casted to B* (the base class). I'm reluctant to use static_cast and dynamic_cas... |
A really smart compiler could have no difficulty because both can be safely casted to B*
Irrelevant. The standard mandates this behaviour. A really smart compiler behaves as observed.
The use of your custom cast is actually fine (and your reluctance for using an explicit cast is well-placed). However, I’d use a diffe... |
6,179,812 | 6,179,836 | C++ variadic constructor - pass to parent constructor | I have th following code:
class A{
//Constructor
public: A(int count,...){
va_list vl;
va_start(vl,count);
for(int i=0;i<count;i++)
/*Do Something ... */
va_end(vl);
}
};
class B : public A{
//Constructor should pass on args to parent
public: B(int coun... | You cannot forward on to an ellipsis. The second constructor will have to take a va_list, I think it is.
This would be possible with C++0x's base constructor forwarding, or variadic templates.
|
6,180,101 | 6,180,141 | Prefix increment in C++ preprocessor | Could somebody explain why b = 150 ?
#define CUBE(X) ((X) * (X) * (X))
using namespace std;
int main( void )
{
int a = 3,b = 0;
cout << "before "<< endl;
cout << "a = " << a;
cout << endl;
cout << "b = " << b;
cout << endl;
cout << "after"<< endl;
b = CUBE( ++a );
cout << "a = "... | Because you're using a macro. Macros are not functions.
The line:
b = CUBE( ++a );
gets re-written as:
b = ((++a) * (++a) * (++a))
before your code compiles.
The code then invokes Undefined Behaviour because you increment a several times between sequence points.
It would be better if you used a function instead.
|
6,180,173 | 6,180,641 | how can I store diffrent value types in an array using c++? | I'm having trouble with some features I want to implement in my config class, I have some values with diffrent types and I want to store them in an map. formerly i used ExtendedString class to store all data and convert them using a template function to the wanted type whenever I needed. and then had a map<ExtendedStri... | I'd recommend using boost::any, as it sounds like it does what you are looking for. However, if you really don't want to use it, you might be able to handle it something like this. It may not be the best way to do it (its the first thing that came into my head) - basically its storing the value in the type you had it... |
6,180,219 | 6,180,235 | How does function overloading work in the following case? | The following code compiles and runs but I'm not sure what exactly is going on at a lower level. Doesn't a reference just store the address of the object being referenced? If so, both test functions are receiving an address as a parameter? Or is the C++ implementation able to differentiate between these types in some o... | As int& and int* are distinct types and i can be treated as a int& but not as a int*, overload resolution is absolutely unambiguous here.
It doesn't matter at this point that references are just a somewhat cloaked kind of pointer. From a language point of view they are distinct types.
|
6,180,514 | 6,180,639 | Visual Studio - correcting different behaviour in an optimized build | I have a project I'm working on. I recently switched it to release mode with full optimization just to get an idea how some things will perform out of debug mode. On doing so however, I noticed that there were a few irregularities. In my particular case, I have a sprite who's alpha value is different (more transparent)... | This type of thing can be very difficult to debug. I suggest that you replace the optimization one-by-one, until you find the one that causes the anomly. You can then narrow the issue further by applying that optimization to each translation unit (file) one-by-one.
Another way to deal with this issue is essentially a d... |
6,180,762 | 6,182,502 | Determining browser Proxy setting in NPAPI to download page SSL certificate | Users could have connections through proxies. Some using system-wide proxy settings, others browser-wide proxy.
On Windows for example you could have the system proxy settings as well as proxy settings for Firefox or Chrome alone. Therefore relying on system proxy settings is not reliable.
The only logical solution i... | I'm pretty sure that NPN_GetURLNotify() will use the browser's proxy settings. It would be pretty crazy if it did not.
Update
If you're writing an NPAPI-based plugin, you need to use the NPN_Get/Post functions to do HTTP requests. That will use the host's proxy settings, cookies, etc. These functions exist for this ... |
6,180,801 | 6,180,831 | PHP define() function | Is there any possible way to get this working:
What is the best comment in source code you have ever encountered? (which I think is C++, but I have no idea)
...working in PHP? I'd love to mess with my co-workers as a little prank and see what happens ;)
| No. There's not.
PHP doesn't have a preprocessor (strictly speaking, it is the preprocessor!); within its scope, keywords trump constants.
A C++ "trick" like this:
#define true false
works because the preprocessor manipulates the code on a context-less basis... though it should be noted that the standard makes that "t... |
6,180,851 | 6,214,869 | Widget under a QTabBar with unwanted frame | I have a problem with QTabBar/QTabWidget. This is what my program looks like at the moment, using QTabBar:
As you can see, there is an unsightly line between the QTabBar and the QScrollArea underneath it. This line is part of the frame of the QScrollArea, which I can't simply get rid of, because it is required on th... | You said "the contents of the QScrollArea change according to the selected tab" well if I assume that this is not true, and what you mean is that the content of the widget that is inside the scroll area changes, then you can try this:
Make as many QScrollArea objects as many tabs you need in your QTabWidget, but only o... |
6,180,909 | 6,502,892 | std::string.npos validity | Was std::string.npos ever valid? (As opposed to the correct std::string::npos.)
I am seeing it a lot in an old project I'm working on, and it does not compile with VS2010.
Is it something from the pre-standard days?
| No, std::string.npos was never valid, and no, it's not something from the pre-standard days.
I see other answers mentioning that MSVC has allowed that notation.
However, MSVC is not a very compliant compiler. For example, it lets you freely bind a temporary to a reference to non-const. For another example, for Windows ... |
6,180,947 | 6,182,460 | scalability of pythonqt for millions of objects | I was thinking about adding pythonqt to my application for writing plugins. My application is in C++ and already uses the Qt framework. The pythonqt option seems like a natural fit for adding GUI components, but I'm concerned about how well the program will scale if I expose an class with millions of instances. It w... | I haven't done much with it but it almost sounds like you should at least look at QtQuick/QML layer. It is hard to tell from your description what is going on but QML is a way to write Qt GUIs without doing any C++ coding. It build on the already exisiting and well working Qt/JavaScript Implementation and Bridge.
As f... |
6,181,003 | 6,181,369 | Move objects from unordered associative container | Is there any way in c++0x of moving objects out from unordered associative containers? I need to merge two separate unordered sets and I would like, in case rvalues are involved, to 'recycle' items in the soon-ceased-to-be sets.
Thing is, unordered_set's iterators provide only const references to the stored items. I ha... | Why not merge the two sets by using one of them as the target, rather than merging them into a third, separate set? This would at least let you avoid copying elements from one of the source sets (presumably you'd choose the larger one).
Or, if the elements are large, you should store them indirectly using smart pointe... |
6,181,306 | 6,181,449 | Initializing a AS 3.0 vector with type array - Vector.<Array>? (plus C++ equivelant) | I have a quick question for you all. I'm trying to convert over some ActionScript code to C++ and am having a difficult time with this one line:
private var edges:Vector.<Array>
What is this exactly? Is this essentially a multidimensional vector then? Or is this simply declaring the vector as a container? I understand... | From Mike Chambers (adobe evangelist) :
"Essentially, the Vector class is a typed Array, and in addition to ensuring your collection is type safe, can also provide (sometimes significant) performance improvements over using an Array."
http://www.mikechambers.com/blog/2008/08/19/using-vectors-in-actionscript-3-and-flas... |
6,181,332 | 6,181,362 | open source software to control computer fan speed | So I asked a similar question here but it was considered a duplicate: https://stackoverflow.com/q/6181191/319862
This time I will be a little bit more specific...
Are there any open source projects that can control the pwm frequency of a motherboard fan header. Please share links. The only software I can find is Spe... | lm-sensors provides a fancontrol tool that can change the speed of your fans, along with some nice calibration tools to help you maintain reasonable temperatures with minimum energy and noise. Excellent tools.
|
6,181,426 | 6,181,440 | How is it possible to have an array of strings in C++? | When you access elements of an array using array[i], I thought that C++ would take the starting position of the array in memory and add i*sizeof(one array element) and then dereference that address (or do something equivalent to what I just described). However, it seems to me that if you have an array of strings (std::... | The string size is constant, but it (at some level) has a pointer to some non-constant-sized data.
The pointer size is constant, the pointee size is not.
|
6,181,464 | 6,181,507 | Do c++11 lambdas capture variables they don't use? | When I use [=] to indicate that I would like all local variables to be captured by value in a lambda, will that result in all local variables in the function being copied, or just all local variables that are used by the lambda?
So, for example, if i I have:
vector<int> my_huge_vector(100000);
int my_measly_int;
some_f... | Each variable expressly named in the capture list is captured. The default capture will only capture variables that are both (a) not expressly named in the capture list and (b) used in the body of the lambda expression. If a variable is not expressly named and you don't use the variable in the lambda expression, then... |
6,181,606 | 6,181,646 | C++ Overloading a Function Based on shared_ptr Derived Class | There are a lot of SO questions which are similar to this, but I couldn't find precisely what I was looking for. I'm sorry if this is a duplicate.
I have a Parent class and two derived classes which inherit from it:
class Son : public Parent { ... };
class Daughter : public Parent { ... };
I then declare two shared_pt... | It isn't possible to overload like that, you would need a switch statement to achieve something similar with dispatch within one method on Director.
Maybe you should move the process() method to the Parent class (and override it in Son and Daughter), that way you can use normal virtual function resolution to call the r... |
6,181,683 | 6,181,729 | C++ Strange File Output | I'm trying to read from a simple text file. Whenever I run the program it prints out the file,
but not before printing out a bunch of garble. Any suggestions?
Garble:
Φ#· ├ï Uï∞ Φ╖ ≈╪←└≈╪YH]├ 5tδ╝
abc
Buffer.cc
//-----------------------------------------------------
// TextInputBuffer - Constructor for Text... | I don't think it's reading the first line after opening the file, so it's fetching junk characters from the uninitialised line storage until one happens to be the newline character, at which point it actually reads the first line.
|
6,181,715 | 51,989,521 | Convenient C++ struct initialisation | I'm trying to find a convenient way to initialise 'pod' C++ structs. Now, consider the following struct:
struct FooBar {
int foo;
float bar;
};
// just to make all examples work in C and C++:
typedef struct FooBar FooBar;
If I want to conveniently initialise this in C (!), I could simply write:
/* A */ FooBar fb =... | Designated initializes will be supported in c++2a, but you don't have to wait, because they are officialy supported by GCC, Clang and MSVC.
#include <iostream>
#include <filesystem>
struct hello_world {
const char* hello;
const char* world;
};
int main ()
{
hello_world hw = {
.hello = "hello, ",
... |
6,181,744 | 6,181,898 | Limitations of the conditional operator ?: | I am using GCC 4.5 and have observed very peculiar behavior. I am wondering if there is something with this operator that I do not completely understand. I thought I was proficient in C++.
I have a thin C++ wrapper class Wnd for Windows HWND objects with an implemented cast operator operator HWND ....
If I use the cond... | I suspect that your Wnd has non-explicit conversion constructor too that takes HWND or even int?
If so then make it explicit.
Your Wnd probably does not have copy constructor and operator= declared? declare these private and don't define them.
Also remove operator HWND and add member function HWND hwnd() const; to your... |
6,181,855 | 6,181,871 | how to detect invalid commands being passed into create process | I am currently working on a program that starts a program that is specified by the user.
passed in is as a wstring entered in by the user. My question is how do i make it throw an exception or check if "passedIn" is vaild. Currently, if the user enters in "notepad.exe" it launches it properly but if they enter somthin... | Quoting the function's documentation (which should have been the first thing you checked):
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
So, check the function's return value.
|
6,181,914 | 6,181,932 | Open source video encoders for an embedded system | I recently designed an H.323/SIP compliant video server (in code at least) fully equipped with a sockets based API which a .NET SDK would use, and a web server, you know ... all of that stuff. Anyway, I chose to use OPAL for my call stack and based my architecture loosely upon the design of EKIGA. I even hijacked the s... | This is the time for microptimisation: Time to look carefully at your inner loops.
You need to figure out which inner loops matter, and then look carefully at how you can get the most throughput. You can also do a sanity check: Can the machine really do what you want to do? Eg. if you need to do n multiple/accumulate o... |
6,182,147 | 6,182,432 | How to getline() from specific line in a file? C++ | I've looked around a bit and have found no definitive answer on how to read a specific line of text from a file in C++. I have a text file with over 100,000 English words, each on its own line. I can't use arrays because they obviously won't hold that much data, and vectors take too long to store every word. How can I ... | If your words have no white-space (I assume they don't), you can use a more tricky non-getline solution using a deque!
using namespace std;
int main() {
deque<string> dictionary;
cout << "Loading file..." << endl;
ifstream myfile ("dict.txt");
if ( myfile.is_open() ) {
copy(istream_iterator<s... |
6,182,155 | 6,182,191 | What is the relationship between C and C++ (more technical approach) | I was reading through Relationship between C and C++ and was interested in a more technical look at the question.
For example, if you want to use threads in C++, would you (assuming a Linux platform) just use pthreads? I know C++ has the STL and the Boost libraries fill in a lot of gaps... but do C++ programmers genera... | Up through C++03, yes, you'd probably use pthreads. The current draft of C++11 has threading built into the standard library, so you'd probably use that instead (though it's based closely on pthreads, so there's little practical difference between them).
In general, however, yes, it's easy to use C libraries directly f... |
6,182,885 | 6,182,903 | Function overloading and function pointers | The name of a function is a pointer to the function...
But in case of function overloading the names of two functions are the same...
So which function does the name point to?
| It depends on the context; otherwise it's ambiguous. See this example (modified except below):
void foo(int a) { }
void foo(int a, char b) { }
int main()
{
void (*functionPointer1)(int);
void (*functionPointer2)(int, char);
functionPointer1 = foo; // gets address of foo(int)
functionPointer2 = foo; // ... |
6,183,062 | 6,191,636 | Getting content carried by reference | I have a reference to a string object how can i get the data from it. Here is my sample:
string key = "key1";
gpointer somepointer;
GHashTable* myTable;
g_hash_table_insert(myTable,&key1,somepointer);
GList *keysList = g_hash_table_get_keys(myTable);// here i got keys previously set
keysList = g_list_first(k... | If keysList->data is gpointer(void*), I guess some cast like the
following is needed:
string recentKey = *(string*)keysList->data;
Hope this helps
|
6,183,141 | 6,183,522 | Port / Recode really big and old C++Builder code to Qt or CLI/Mono | Hello I need to remake some old C++Builder (6) project and make it for Linux/Windows.
The main and big project parts is
OPC Client (and some other clients)
Working with database (currently MS SQL) but maybe porting to another one like postgres is another task.
GUI Components for Tables / Reports / Graphics / Diagram... | I'd go Qt for a few reasons:
cross-platform UI
using QSQL and correct plugin, you could have code working for both MsSql and PostGre (smoother transition, easier for testing)
Qt is well documented and easy to deal with, moreover it compiles with Visual, thus preventing cygwin / mingwin mayhem on windows
|
6,183,507 | 6,183,787 | Am I getting a race condition with my boost asio async_read? | bool Connection::Receive(){
std::vector<uint8_t> buf(1000);
boost::asio::async_read(socket_,boost::asio::buffer(buf,1000),
boost::bind(&Connection::handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
int rcvlen=buf.size();
ByteBuffer b((std::shar... | You are trying to read from the receive buffer immediately after starting the asynchronous operation, without waiting for it to complete, that is why it works when you set a breakpoint.
The code after your async_read belongs into Connection::handler, since that is the callback you told async_read to invoke after receiv... |
6,183,533 | 6,184,053 | qmake with INCLUDEPATH ignores dependencies | I use qmake to build a project. The project contains several static libs and a executable. The executable links to the static libraries and therefore has the path of the library added to the INCLUDEPATH variable.
When I change something in the header files of the executable everything is rebuild as expected. When chan... | You should add the paths you added to INCLUDEPATH to DEPENDPATH as well.
|
6,183,658 | 6,183,901 | A Portable typeof() in C++ using SFINAE? |
Possible Duplicate:
Absence of typeof operator in C++03?
Is it possible to use templates to get the compile-time type of an expression portably in pre-C++0x C++?
Something like:
int foo() { return 0; } //Let's say we have this
typeof(foo()) x; //x would now be of type 'int'
but since we're working with templ... | It's impossible in the general case. And yes, quite a lot of effort has been put into this problem over the years.
There are a lot of tricks for determining the type of an expression in specific cases (for example, functors are commonly annotated with a typedef indicating their return type), but in general, you need de... |
6,184,034 | 6,184,065 | which data structure for a list of object with fast lookup feature | I have a data structure and have to perform lookup on it, I would like to optimize things...
struct Data
{
std::string id_;
double data_;
};
I use currently a std::vector<Data> and std::find algorithm but I'm wondering if another data structure would be more convenient :
hash table ?
map ?
boost multi index contai... | It really depends on your requirements, but two possibilities are to sort your vector and do a binary search, or to use a map. Both can be implemented within about 15 minutes, so I suggest you try both of them.
Edit: Given your requirement that you want to add and remove things often, and the size of your data, I'd us... |
6,184,221 | 6,184,253 | Importance of a design pattern? | I am learning C++
I don't know much about this stuff except the fact that programming design pattern is neccesary when actually working in large projects.I hope its correct to some extent.
Is this common to all object oriented languages or do I need to look specifically into
C++ design patterns.
Also How does it helps... | Design patterns are often misunderstood. They are really a way for experienced users to have shorthand for describing common situations. You don't need to worry about them too much while you are learning C++.
|
6,184,420 | 6,184,500 | C++ XML to C++ Object Mapping library? | Is there any good automatic xml to C++ object library ?
With good benchmark and Multi - Platform support (if not at-least linux )
Edit :
More Description
I want to library like
http://www.codesynthesis.com/products/xsd/
where I can use any xml as c++ object.
XMLOBJECT x=new XMLOBJECT("my.xml");
x->root
x->root->ch... | I think that you refer to what is called XML Data Binding.
gsoap is a free tool that does it. There are of course many commercial tools - XML Spy and others. Here is a nice list of resources.
|
6,184,607 | 6,184,803 | Run windows GUI application in synchronized mode? | I am debugging GUI app on windows and I want to find out who is the sender of some message. On linux, I can run app in synchronized mode and find the sender in call stack. Is there any equivalent mode in windows?
| AFAIK there's no built-in ability to do this.
But let's first investigate the problem. You want to know who's the sender of the message. You should know however that windows message processing can be classified by the following criterias:
Posted vs Sent messages (PostMessage vs SendMessage).
Messages sent to the windo... |
6,184,627 | 6,184,783 | pthread - How to start running a new thread without calling join? | I want to start a new thread from the main thread. I can't use join since I don't want to wait for the thread to exit and than resume execution.
Basically what I need is something like pthread_start(...), can't find it though.
Edit:
As all of the answers suggested create_thread should start thread the problem is that i... | The function to start the thread is pthread_create, not
pthread_join. You only use pthread_join when you are ready to wait,
and resynchronize, and if you detach the thread, there's no need to use
it at all. You can also join from a different thread.
Before exiting (either by calling exit or by returning from main),
y... |
6,184,658 | 6,184,757 | Where's the balance between thread amount and thread block times? | Elongated question:
When having more blocking threads then CPU cores, where's the balance between thread amount and thread block times to maximize CPU efficiency by reducing context switch overhead?
I have a wide variety of IO devices that I need to control on Windows 7, with a x64 multi-core processor: PCI devices, ne... | First, it sounds like these tasks should be performed using asynchronous I/O (IO Completion Ports, preferably), rather than with separate threads. Blocking threads are generally the wrong way to do I/O.
Second, blocked threads shouldn't affect context switching. The scheduler has to juggle all the active threads, and s... |
6,184,700 | 6,184,827 | C++ implementation for DataGrid | I've noticed that the built in C# DataGrid doesn't have great performance (not good enough for what I'm doing anyway).
Is there a C++ implementation for a DataGrid ?
I need one that hopefully has about the same functinality and a COM interface or something that can be access with managed .NET code.
(If there's nothing ... | Does this or this help in anyways?
|
6,184,817 | 6,687,994 | HDF5: inserting a set of strings in a dataset | I'm currently learning the HDF5 API and I'm trying to insert a set of C++ std::string into a HDF5 dataset (1 column).
In the following snippet, how should I loop over a vector<string> and insert each string at the right index ?
How should I tell HDF5 whether I want to use a fixed-length string or a can-have-any-length... | First, make a C-style array of char* with pointers to your strings:
const size_t n = samples.size();
char* data[n];
for (size_t i = 0; i < n; i++)
{
data[i] = samples[i].c_str();
}
Then write everything in one go:
H5Dwrite(dataset, datatype, dataspace, H5S_ALL, H5P_DEFAULT, data);
|
6,184,853 | 6,185,938 | Adding MySql.Data.dll to Qt C++? | How do I add a MySql.Data.dll file to a Qt C++ project?
| For QT, check out QSQL instead to connect to a database.
Or use the C++/C connectors:
For C++: MySQL++
For C: MySQL C API
|
6,184,943 | 6,185,096 | XCode importing C++ project problems: "referenced from" | I have some problems importing an existing C++ project into my XCode. I already resolved some issues on includes (the use of string.h from another library was a pain), and now I stumbled upon another problem.
When I build the project, I have 35 errors, all of the same origin.
For example:
"_EVP_DigestInit_ex", referenc... | These are linker errors; you can tell that from the fact that .o files are being processed. That means compilation must have succeeded to produce these.
Did you specify all the right libraries? By the looks of it, you need to link with at least OpenSSL (-lssl -lcrypto -lz) and wxWidgets.
|
6,185,020 | 6,185,043 | Initializing member variables using the same name for constructor arguments as for the member variables allowed by the C++ standard? | I figured out that it's possible to initialize the member variables with a constructor argument of the same name as show in the example below.
#include <cstdio>
#include <vector>
class Blah {
std::vector<int> vec;
public:
Blah(std::vector<int> vec): vec(vec)
{}
void printVec() {
for(unsigned... |
I wonder what the C++ standard says about it? Is it legal and guaranteed to always work?
Yes. That is perfectly legal. Fully Standard conformant.
Blah(std::vector<int> vec): vec(vec){}
^ ^
| |
| th... |
6,185,129 | 6,185,197 | how to include 2 files with same name? | I am working in ubuntu, I have a folder that contains a subfolder. in the first folder i have a name.h file. in subfolder i have again a name.h file. the thing is that i need both the headers. the problem is the fact that both headers have the same name. i receive errors saying that a specific function was not declared... | So, something like this :
<some dir>
-> <sub1>
header.hpp
-> <sub2>
header.hpp
This is resolved by telling the compiler to search in the common folder for the headers (in the above case ) and including like this :
#include "sub1/header.hpp"
#include "sub2/header.hpp"
|
6,185,137 | 6,185,308 | Recursive binary tree function | I am trying to insert items from my array into my tree. My function works fine and creates nodes all the way down to the leaf node on the left hand side of my tree. The problem is when it is supposed to return recursively when detecting a leaf node to the higher level, it just stops building the tree completely. Here i... | if ( tree_root->left > 0) {
// implementation
}
else if (tree_root->right > 0) {
// implementation
}
Shouldn't this be two separate if statements, rather than if/else? Otherwise it only does one or the other sides, but not both.
|
6,185,279 | 6,185,464 | How can I assign hex string to a char[] variable? | Assume my hex string. hexStr = "aecf"
How can I assign the hex string value to unsigned char myChar[] as below. Thanks.
myChar[0] = 0xae;
myChar[1] = 0xcf;
| You may convert data as follows:
char* hexstr="aecf";
int hexsize=strlen(hexstr);
unsigned char* myChar = new unsigned char[hexsize/2+1];
myChar[hexsize/2]='\0'
for (int i=0,intj=0;i<hexsize;i+=2,j++)
{
int tmp;
sscanf(hexstr+i, "%2x",&tmp));
myChar[j]=tmp; // warning, ig... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.