w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » C++ » Page 4
What is the name of this C++ functionality?
The compiler is evaluating each sequence point in turn within the parenthesis and the result is the final expression, WSA_FLAG_OVERLAPPED in the expression. The comma operator , is a sequence point in C++. The expression to the left of the comma is fully evaluated before the expression to the right is. The result is always the value to the right. When you've got an expression of the form (x1, x2,

Categories : C++

copy-and-swap idiom confusion
You've introduced infinite recursion. The assignment operator is one of the constructs that std::swap uses under the hood, so your operator= would call swap which would call operator= which would call swap which would call operator= which would call swap which would call operator= which would call swap which would call operator= which would call swap which would call operator= which would call swa

Categories : C++

What does `auto && e` do in range-based for-loops?
When and if you should use auto&& in for loops has been explained very nicely by Howard Hinnant here. This leaves the question what x in auto &&x = ...expr... actually is. And it is handled as if there there were a function template definition template <class U> void f(const U& u); and the type of x is deduced by the same tules as u [§7.1.6.4.(7)]. This means it

Categories : C++

Sending data in second thread with Mongoose server
Ok... It looks like I've solved it myself. I'd been looking into mongoose.c code and an hour later I found the piece of code below: static void write_terminating_chunk(struct connection *conn) { mg_write(&conn->mg_conn, "0 ", 5); } static int call_request_handler(struct connection *conn) { int result; conn->mg_conn.content = conn->ns_conn->recv_iobuf.buf; if ((re

Categories : C++

C++: Issue with clearing a vector of objects
Note: firtly OPs didn't showed that he is using memset some where in his code that's y i gave this answer, as i thought this weired behavior is because of some problem in clear as mentioned in below links. 1) cppreference.com: says that it Invalidates any references, pointers, or iterators referring to contained elements. May invalidate any past-the-end iterators. Leaves the capacity() of the

Categories : C++

ACE fails at Linker in MAC OS X 10.9 (and higher)
Thanks for the replies, after some investigation on Linux Ubuntu, I succeeded to compile the code with the following command g++ -o m.out myTest.cpp ACE_wrappers/lib/libACE.a -I ACE_wrappers/ -lpthread -ldl. Seems some default libs were missing!

Categories : C++

C++ boost crashes while using locale
I had this same issue when using a static library build of Boost 1.55 in a Visual Studio 2008 application on Windows 7 64-bit where both the main executable and a couple DLLs all linked to Boost. I'm not sure if your issue is the same as mine since you didn't mention using DLLs, but that wasn't something I thought was relevant when I first started investigating this. If you're just interested in

Categories : C++

Printing name of a key in SDL
The keycode for f is SDLK_f A simple if statement should do it: case SDL_KEYDOWN: if( event.key.keysym.sym == SDLK_f ) std::cout << "f was pressed" << std::endl; break ; //this was missing SDL doesn't distinguish cases so you need an extra check for that, if was shift pressed etc.

Categories : C++

How can I handle exception in catch block in c++
If you think this is what you really want, you can do it like this: try { try { //... } catch( ... ) { //... if( .. ) throw std::runtime_exception( "error occured" ); } } catch( std::runtime_exception& e ) { // handle exception of exception handler }

Categories : C++

boost::lexical_cast not recognizing overloaded istream operator
There's 2-phase lookup at play. You need to enable the overload using ADL, so lexical_cast will find it in the second phase. So, you should move the overload into namespace mandala Here's a completely fixed example (you should also use std::skipws): Live On Coliru #include <iostream> #include <boost/lexical_cast.hpp> namespace mandala { struct vec2_t { float x,y;

Categories : C++

Using select() to receive from multiple peers using UDP sockets while taking user input from STDIN
Basically, yes. UDP is connectionless, so you can use a single endpoint to communicate with all your clients/peers. You can store their IP address and the source port of their messages (which recvfrom gives you) which you can use as the destination IP address and port in a call to sendto.

Categories : C++

Qt : How to generate .h and .cpp from a .ui file - Vim and Qt is it practical?
Use uic to compile the .ui file would do. Some instruction here. You can also use qtcreator on linux, which includes the vim editing mode plugin.

Categories : C++

Faster code-completion with clang
Sometimes delays of this magnitude are due to timeouts on network resources (NFS or CIFS shares on a file search path or sockets). Try monitoring the time each system call takes to complete by prefixing the process your run with strace -Tf -o trace.out. Look at the numbers in angle brackets in trace.out for the system call that takes a long time to complete. You can also monitor the time betwee

Categories : C++

Barcode security with own developed software
Please don't do what you are suggesting! Instead, use a surrogate key (barcode) which is held securely in a database (and by that, I mean carefully check all relevant laws in your jurisdiction). Don't try and be clever and 'encrypt' any info into the key. It will come back to bite you.

Categories : C++

Vigenère Cipher code
Use cin to accept input from the user and input it into a string. Parse the string to obtain the -e/-d flags and the keyword. If the input is not what you want, prompt the user to try again.

Categories : C++

Common Code Behaviour
In your code, #ifdef CLI_LOG_TAG_ENABLE #define LOG_TAG "CLIENT" #if SERVER_LOG_TAG_ENABLE //did you mean ifdef ? #define LOG_TAG "SERVER" #endif To be on safer side, you can use #ifdef CLI_LOG_TAG_ENABLE #define LOG_TAG "CLIENT" #else #define LOG_TAG "SERVER" #endif Just define CLI_LOG_TAG_ENABLE in the client module, leave the server module alone. Hope this helps!!

Categories : C++

Get webview document title when HTML is loaded
QWebView::loadFinished is a signal. You can subscribe to it to know when the page is loaded: connect(view, SIGNAL(loadFinished(bool)), this, SLOT(onLoaded())); To access HTML title you can use QWebView::title property. void onLoaded() { window->setWindowTitle(view->title()); } Rather then using loadFinished it may be more appropriate to use signal titleChanged(const QString& ti

Categories : C++

How to serialize a boost::uuid with cereal
The fact that cereal archives operate on either an std::ostream or std::istream object. doesn't (at all) imply that it using the IO streaming operators (>>, <<). That's just the archive implementation. You'll have to implement the free function serialize to let Cereal know about your type. You should be able to reuse the implementation shown in uuid_serialize.hpp. Chances are you sho

Categories : C++

Access to private member functions of derived class using reference to a base class
_"How can I prevent from calling these two private member functions using reference to the Abstract_base class? I just don't want the user have access to the f2() in Derived_1 and f1() in `Derived_2"._ There's no way to hide these functions by using the scope operators through a derived class declaration. "What surprising me is why using Handler class I am able to invoke these private mem

Categories : C++

user select array type from menu c++
To get rid of the redefinition error you have to enclose the type definition inside curly brackets switch (dataChoice) { case 1: { SimpleVector<int> myVect = SimpleVector<int>(dataSize); break; } case 2: { SimpleVector<double> myVect = SimpleVector<double>(dataSize);

Categories : C++

Why does program continue in while loop for any character entered?
Add one condition to if -else section: if(nextRoman == 'Y') { done = false; } else if(nextRoman == 'N') { done = true; cout << "Thanks for roman numeraling with me. " << endl; } else { done=false; cout<<"see you next time"//or anything you want

Categories : C++

Dynamic Allocation of Array Inside of a Function
Your function return must match the type of pointer you wish to return. If you want to allocate an array of float, then your function must be of type float *. The following is a quick example: #include <stdio.h> #include <stdlib.h> float *allocateBuff(float** buffer, int size) { /* allocate array of floats */ *buffer = calloc(size, sizeof(*buffer)); return *buffer; } i

Categories : C++

C++ automatic pre-processor code generation
Could I have a PRE-PROCESSOR function such that I just write This file: #define read_vector(x) std::string z_##x##_file("z_"#x".txt"); z_##x##_file = input_folder + z_##x##_file.cstr(); Eigen::Matrix<PRECISION, Eigen::Dynamic, Eigen::Dynamic> z_##x##_ = readArbitraryMatrix<PRECISION>(z_##x##_file.cstr()); Eigen::VectorXf z_##x = z_##x##_; read_vector(A); read_vector(B); After

Categories : C++

std::vector emplace_back vs std::deque push_back?
Whether it will improve performance or not will depend greatly on your usage pattern: how much you push, how often you pop, how expensive is element copying (or moving) during vector reallocation and so on and so forth. There's no way to say anything definitive without looking at the specifics. Try it, profile it and see which one works better. BTW, you can specify which container type std::stack

Categories : C++

How to loop std::set with custom .begin() and .end()?
auto i = magic.find(3); if (i != magic.end()) { auto finito = i; do { std::cout << *i << ' '; // or whatever you want to do with elements if (++i == magic.end()) i = magic.begin(); } while (i != finito); }

Categories : C++

How do I define an array in C++ that holds GMP variables?
Well, summing up all the comments above, if you are dealing with a lot of array modification in your code(insertion/remove) it is best to use vector<mpz_class> to hold your mpz_class variables. And the reason that it is better for you to use mpz_class instead of mpz_t is first you don't have to worry about keeping track with memory you use for the variables(mpz_init()/mpz_clear()) and second

Categories : C++

Qt Audiorecorder example - Connection of button
The connection can also be created in a *.ui-file. If you inspect the audiorecorder.ui you'll find the following code: <connection> <sender>recordButton</sender> <signal>clicked()</signal> <receiver>AudioRecorder</receiver> <slot>toggleRecord()</slot> <hints> <hint>...</hint> </hints> <

Categories : C++

Socket Server with Multiple clients. Killing child processes
The hanging child processes are probably zombie processes. You could do for example following for avoiding problem: Use waitpid() of wait() in parent process to get rid of zombies. Use 'double fork' trick to put child processes under init process.

Categories : C++

Browser of file
You've got a ; instead of a : before the initialiser list for your constructor: Browser(USBDevice dev, QWidget* parent = 0); // <--- here QTreeWidget(parent) { ... FWIW, I recommend putting the colon at the start of the line like this: Browser(USBDevice dev, QWidget* parent = 0) : QTreeWidget(parent) { ... That way it's much clearer how the second line relates to the fi

Categories : C++

How can I add many json strings in one JsonArray?
I'm not using json-glib, I couldn't test this code, and I omitted the part to release the builders, but I hope this helps you: // build an object as an element of 'tag' array. // {"one": "value", "two": "value"} JsonNode * objectAsElementOfTag; { JsonBuilder *builder = json_builder_new (); json_builder_begin_object (builder); json_builder_set_member_name (builder, "one"); json_builder_ad

Categories : C++

How can I correctly convert this to hex?
Try using the str member instead of the extract operator, to eject the string from the stringstream. Besides being more direct, you don't have to worry about how the extractor further interprets things.

Categories : C++

nFinding Xcrossing point using Data Points
This appears to be a straightforward implementation. For a given point x,y on the curve, find the slope, draw a line through the slope, find where that line would cross the x axis, and then find the new y value at that point. For well-behaved functions, the new y value is a lot closer to 0 than the initial y value. You iterate until the approximation is good enough. If you look at the graph, you

Categories : C++

Qt : How to get QComboBox item text at an arbitrary index (not the currently selected item)
Use itemText() method to do this. Just set needed index. As Marek R pointed, you can get model and get data from this model, but it will be helpful for you when you want to get something more than text( for example get image with Qt::DecorationRole or font with Qt::FontRole) http://qt-project.org/doc/qt-4.8/qcombobox.html#itemText http://qt-project.org/doc/qt-4.8/qcombobox.html#model

Categories : C++

Embedding Window Media Player in mfc
MSDN says: For full-screen mode to work properly when embedding the Windows Media Player control, the video display area must have a height and width of at least one pixel. If the BSTR specified in IWMPPlayer::put_uiMode is set to "mini" or "full", the height of the control itself must be 65 pixels or greater to accommodate the video display area in addition to the user interface. This assum

Categories : C++

Partial template specialization for variadic template where [Args...] is empty
Your attempt with using R Delegate<R()>::operator()() to specialize even more the member function of a partial specialization of a class template fails due to §14.5.5.3 [temp.class.spec.mfunc]: 1 The template parameter list of a member of a class template partial specialization shall match the template parameter list of the class template partial specialization. In other words: templ

Categories : C++

Using Windows Bluetooth API on OS X/Mac?
The QtBluetooth module currently supports Android, BlackBerry 10 and Linux (Bluez 4.x) and indeed, OS X and Windows are not supported yet. You should write the bluetooth functionality you need in XCode and then import it into your Qt project as a linked library. You can also have a library in which you use platform specific macros like #ifdef Q_OS_WIN and #ifdef q_os_osx and put your platform sp

Categories : C++

Heap error in VS2010
you input whole string into 1 or 2 bytes strings. These allocations: _TCHAR* attString = new _TCHAR(); char* ynAnswer = new char(); Allocate only 1 item array. it should be: _TCHAR* attString = new _TCHAR[MAX_SIZE]; char* ynAnswer = new char[MAX_SIZE]; When MAX_SIZE must beeb defuned as macro. even better is to use: wstring attString ; string ynAnswer; wcin>> attString; cin&g

Categories : C++

Error pointer in C++
The code: P->PGet().XSet(8); Probably does not do what you think it does.. It is most likely that `P->PGet() returns a copy of the "Point" and not the internal structure. The proof of that will be in the definition of PGet().. My guess is that the function looks something like this: CPoint3D Prune::PGet() const This means that the function PGet returns a copy of CPoint3D. and so P->PGet(

Categories : C++

Multiple insertion operator << in C++
You probably meant to write some code like follows #include <iostream> using namespace std; class MyClass { public: int i; MyClass & operator<< ( const string & ); } ; MyClass& MyClass::operator<< ( const string & str) { // Note the parameter symbol cout << str << endl ; // Note usage of the parameter symbol "str", "this" i

Categories : C++




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.