w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » C++ » Page 3
Is a static member initialized before the constructor is called?
This is what the standard says :- The storage for objects with static storage duration (basic.stc.static) shall be zero-initialized (dcl.init) before any other initialization takes place. Zero-initialization and initialization with a constant expression are collectively called static initialization; all other initialization is dynamic initialization. Objects of POD types (basic.types) with static

Categories : C++

Can't link ncurses with Qt
http://www.lucidarme.me/?p=3961 Here You can find a solution. Main reason is You incorrectly set project: LIBS += -lncurses Check a link I sent You. Everything is there clear.

Categories : C++

How Read Urdu text file and then write it to other file in c++
Oh I got answer. The answer is you have to put spaces between Urdu characters because Urdu language has Space Omission Problem so at while loop while(file>>word) { myfile<<word; myfile<<" "; // Put spaces between words. }

Categories : C++

How to cast char array to int at non-aligned position?
No you can't do that in a portable way. The behaviour encountered when attempting a cast from char* to int* is undefined in both C and C++ (possibly for the very reasons that you've spotted: ints are possibly aligned on 4 byte boundaries and data is, of course, contiguous.) (The fact that data+3 works but data+p doesn't is possibly due to to compile time vs. runtime evaluation.) Also note that

Categories : C++

Inconsistent parameter pack deduction with variadic templates
The way you are calling your function template, the template parameter pack Args will be deduced from two sources: The type of the pointer to member function - int (Calculator::*)(const int&, const int&) The actual types of the arguments (*a, *b) you passed for the function parameter pack - int &, int & For deduction to succeed, the result deduced must exactly match. They obvio

Categories : C++

Why am I permitted to declare an object with a deleted destructor?
It's that B's destructor is generated by the compiler at the line of your error and it has a call to A's destructor which is deleted, hence the error. In the first example nothing is trying to call A's destructor hence no error.

Categories : C++

Connecting to Serial port in QT
First of all, you should check is open returns true. If no, then tell to user about error and call errorString() if(serial.open(QIODevice::ReadWrite)) serial.write("ok*"); else { //error qDebug() << serial.errorString(); } You try to open one port in different programs. It is forbidden in Windows. So you can't use this. In your video author open com3 in Qt but com4 in teraterm

Categories : C++

delete (free) elements from stringstream
Since std::istringstream uses std::string to store its data, the contents of buffer is copied to a string that is stored inside the stream. So to answer your question, yes you can free the buffer as soon as you created and initialized the string stream. However, a more interesting question back to you is why you're using C file handling instead of C++ streams directly? And why read the whole file

Categories : C++

Can conversion functions be non-member functions
Conversion operators are specific to class i.e they provide a means to convert your-defined type to some other type. So, they must be the member of a class for which they are serving purpose :- for e.g:- class Rational { public: operator double (); }; Here operator double provide a means to convert Rational object to double.

Categories : C++

How can I use std::lower_bound when I'm only interested in comparing part of the value and can't assume a default constructor for the other part
You can pass a heterogeneous comparator (i.e. one which takes arguments who's types are not the same) to lower_bound. The first argument will come from a dereferenced iterator from the range, the second argument will come from the value passed as the third argument to lower_bound. So, you can use something like this: struct Compare { template<typename T1, typename T2> bool operator(

Categories : C++

How do I get the Polynomial Interpolation coefficients using gsl_interp?
After a quick scan over the documentation, it doesn't seem that such a feature is available in the GSL. This could be caused by two reasons: first, getting polynomial coeffcients is special to this interpolation method doesn't fit well into the general design (which can handle arbitrary functions). Second, citing Numerical Recipes: Please be certain, however, that the coefficients are what you

Categories : C++

Kernel Resource Leak BIO_do_connect
BIO_gethostbyname is not (cannot be) threadsafe, since it returns a pointer to a static buffer. Indeed, there is mention of this in openssl's bio.h, reading struct hostent *BIO_gethostbyname(const char *name); /* We might want a thread-safe interface too: * struct hostent *BIO_gethostbyname_r(const char *name, * struct hostent *result, void *buffer, size_t buflen); * or something similar (

Categories : C++

Is there a penalty to using char variables in CUDA kernels?
Arithmetic It's not possible to say in the generic sense whether it'll be faster/slower/unchanged, though usually I'd not expect much difference. You're correct in saying that arithmetic for chars will be in 32-bit, but whether this requires a type conversion will depend on the problem. In the question's example, I'd expect to see the compiler store a and b in 32-bit registers, and in my experime

Categories : C++

Changing the title of the MessageBox for DDX_Text()
Internally AfxMessageBox is called. This function always uses the application title as a title for the message box. The value is stored in CWinApp::m_pszAppname. It is just a LPCTSTR. Just create a class like this. class CChangeAppTitle { public: CChangeAppTitle(LPCTSTR pszNewTitle) : m_strTitle(pszNewTitle) , m_pszOldTitle(AfxGetApp()->m_pszAppTitle) { AfxGetApp()->m_pszAp

Categories : C++

Return the wrong type in C++
This could be a result of non-explicit constructor of Color class accepting unsigned char as its argument. That means you have constructor in Color class with single argument OR multiple arguments rest being default parameters.

Categories : C++

What the point of using std::ios_base::binary?
The differences between binary and text modes are implementation defined, but only concern the lowest level: they do not change the meaning of things like << and >> (which insert and extract textual data). Also, formally, outputting all but a few non-printable characters (like ' ') is undefined behavior if the file is in text mode. For the most common OSs: under Unix, there is no dis

Categories : C++

Setting a callback function which is non static member function of a class
You should think about what a callback really is and how a member function is called. When you give a callback function, you just give the address of a function that will later be called with parameters on which you normally have little control. When a member function is called, its first parameter is the this pointer, that is a reference to the object on which the method is called. That's the

Categories : C++

cmake can't find boost libraries because it looks for the wrong file names
Note: boost_thread-vc120-mt-1_56.lib is an import library allowing dynamic linking with boost_thread-vc120-mt-1_56.dll, while libboost_thread-vc120-mt-s-1_56 is a static library (s letter means it's also statically linked with CRT). The application you try to build expects static Boost libraries having static CRT, so you should provide them. To build such libraries, invoke b2 with the appropriate

Categories : C++

parsing command-line options with sequence containers?
Actually what you have there is more akin to an expression grammar. I'd suggest writing a grammar/parser for that instead of (ab?)using program_options for this. If your program takes options: use program options. If your program takes an expression: use an expression parser. An example: Live On Coliru // #define BOOST_SPIRIT_DEBUG #include <boost/fusion/adapted/struct.hpp> #include &

Categories : C++

Let rectangle blink/flicker at a certain frequency
For me this sounds like a sampling problem: Assuming a screen-refresh rate of 60Hz, and a flicker-rate of 20Hz. This means that we want the object to be visible for 1/40sec and then be invisible for 1/40sec. Now look at the following diagramm: on 1/60 on 1/60 off 1/60 |---------------------|---------------------|---------------------| Screen |--------------------

Categories : C++

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++




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