spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » C++ » Page 5
What's the difference between first locking and creating a lock_guard(adopt_lock) and creating a unique_lock(defer_lock) and locking?
There's actually a paragraph (3.2.6) in the book explaining that the code is virtually equivalent and you could replace one with the other. The only difference being is that std::unique_lock tends to take more space and is a fraction slower than std::lock_guard. Bottom line is whenever you don't need the additional flexibility that std::unique_lock provides, go with std::lock_guard.

Categories : C++

Taking the elements that are > 0 from 1 array to another
In: for (i = 0; i < n; i++){ if (p[i] > 0){ w[j] = p[i]; j++; } for (j = 0; j < n; j++){ cout << w[j]; } } the inner loop is printing every element of the array w. That loop is executed for every element of p (being it inside the outer for loop). This mean that, for example, the first time it visits p to check if the first element is 0,

Categories : C++

Code compiled with profiling flag does not generate gmon.out
You are not passing -pg when generating executable. i.e. gcc -o xrttimetag xrttimetag.o .... You should pass -pg option here too. I can re-produce the problem (i.e. symbols are undefined for gmon* calls) if I use -pg when compiling but not when linking. From the gcc documentation: -pg Generate extra code to write profile information suitable for the analysis program gprof. You must

Categories : C++

Global protobuf message
Try calling MyType::default_instance() at least once before you try to use MyType. This triggers a bunch of initialization that may cover your needs. If that doesn't work, then you're going to need to find some way to cause the .pb.o's dynamic initializers to run before your own code's. It may be that this is dependent on the order in which the objects are listed on the linker command line, and y

Categories : C++

Making a circle orbit in a circular path around another circle in C++
The classical error is to use the modified x in the second assignment, so that you are actually computing yr + (x' - xr) sinθ – (y - yr) cosθ (Not showing the actual code that you are using is not a good idea.)

Categories : C++

Visual Studio C++ : Getting Unresolved tokens and unresolved link. What should I do?
Assuming that you're using the standard sqlite source distribution, there should be a .c or .cpp file inside your sqlite3 directory. That file needs to be included in the project and compiled along with your source. The other possibility is that you may have received the sqlite3 headers with a .lib file -- if that's the case, then you'll need to link the library along with your project. The r

Categories : C++

Finding a word using std::regex_token_iterator (not necessarilly) to find the char position in string
okay so i figured out a way to cleanly do it. int basepoint=0; while(whatever) { int c1=zodis.end()-zodis.begin();//the length of the word int c2=eil.find(zodis,basepoint);//the starting position of the word basepoint+=c1+c2;//start point for the find function for the next loop } this will find all the word start points(even if the whole line is the same word)

Categories : C++

Correctly sending and receiving a struct through Indy UDP
TBytes is a dynamic array of bytes, it is implemented by the RTL as a pointer, which is why sizeof(AData) is returning 4. Do not use sizeof(AData), use the AData.Length property instead: void __fastcall TForm1::UDPServer1UDPRead(TObject *Sender, TBytes AData, TIdSocketHandle *ABinding) { DATA_PACKAGE r; Form1->Memo1->Lines->Add("received " + IntToStr(AData.Length)); By

Categories : C++

C++:How to use windows media player to play and pause mp3 file in a visual studio console application program?
For your console application. You can simply call the system to launch windows media player system ("start wmplayer.exe -p C:\Folder\Music\Sample.mp3"); this will start your player. You can change track by doing this system ("start wmplayer.exe -p C:\Folder\Music\Sample2.mp3"); this will run Sample2.mp3. You can store other information in your program like for playlist store information i

Categories : C++

Interrupt a getLine() while loop in C++
getline() is a blocking call, you'll probably have to use something different, if you want to receive messages (i.e. a shut down command) from other threads. You did not mention which library you use for multithreading and how you terminate the console reading thread (it's possible, that your way of stopping the thread still does not force it to exit from getline) This question seems to have some

Categories : C++

Can I pass a member function to mu::Parser::DefineFun()?
Looks like the muParser API sadly isn't ready for C++. In C++11 Lambdas can "decay" to function pointers, but this means they have to be stateless, so, you're back at the same spot: you can't bind extra parameters. Is muParser open source? Perhaps there is a fork that has already amended this design flaw Oh and, yes, boost::bind cannot break the laws of physics do this for you

Categories : C++

boost::any_range and operator []
I would say the answer depends on your performance needs and your laziness when it comes to implementing a new iterator abstraction. The core reason for your [] operator not working is the fact that std::list<...> does not provide a random access traversal iterator. If you would have chosen a container that provides such an iterator. You any_range<...> could have taken the random_access_trav

Categories : C++

Calling GetDisplayName returns same result as GetIconPath
If you read the remarks for both GetDisplayName and GetIconName in MSDN you'll see that the functions can return NULL if no-one has set them. The GetIconName page also then remarks that the sndvol application (which you've got a screenshot of) will actually look up the icon of the main window if it's NULL, and therefore by induction will lookup the main window title for the display name if it does

Categories : C++

VS2015 preview: NDK_ROOT is not defined
I wanted VS to use my existing Android tools and changing string key 'NDK_HOME' at 'HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftVisualStudio14.0SetupVSSecondaryInstallerAndroidNDK' did the trick. Maybe you can add it manually.

Categories : C++

Variable change without any direct action
This might be the problem. I am not sure. Check it out. This line: char *utf8_text = str.toLatin1().data(); What does the documentation say toLatin1() does? It creates a new QByteArray object and then you call data() on that and you get a pointer to character and then the QByteArray is destroyed at the end of the line because it was TEMPORARY. And now you have an invalid pointer to freed me

Categories : C++

How to exclude a source file from being build in eclipse (C++)?
I ran into a similar problem. The C/C++ perspective of Eclipse Luna (4.4) is missing the contextual menu "Exclude from build". I solve my problem by using the java perpective: Window -> Open Perspective -> Other... -> Java(default) Navigate to the file/folder you want to exclude Right Click -> Resource -> Exclude from build Then you can switch back to the C/C++ CDT perspective

Categories : C++

Microsoft Visual Studio C++ 2013 Linking Error (when using SQLite wrapper)
You will need to include the source file(s) that came with sqlite3 in your project. (Or, you could create a library that you would include with your project, but that's a slightly more complex answer.) Anyway, yea, you probably have a file called "sqlite.c" -- just include that with your project so that it compiles as well. You may still have some other errors/warnings to resolve; however, I t

Categories : C++

Why are the raw pointer values being overwritten/falling out of scope
Because the c_str() doesn't prevent the string from being cleaned up. After the function returns and bar is cleaned up then the foo strings are also cleaned up which may be before the thread starts. You should pass the actual std::string (possibly to a wrapper that then extract the char* before calling func) or otherwise ensure the strings don't get cleaned up before you join()ed all the threads.

Categories : C++

Calling a function on the this keyword
if((this.length()) > (string.length())){ This should be if((this->length()) > (string.length())){ as this is a pointer.Basically this is just a pointer referring to the object on which member function is called. So, you have to use -> for all reference to members of that class. One more advice stop using variable names which are standard keywords. like string in your case. Had yo

Categories : C++

Wrong breakpoint being hit
Actually this code is ok and should work as you expected. VS allows you to place a breakpoint at the end of an execution block (the if statement inside the for loop in this case). As you did not wrap the if statement with curly braces (as in the image above), VS assumes that the breakpoint you placed in the b++ statement refers to the end of the for execution block and therefore breaks, without

Categories : C++

Delphi - Convert (read) C++ NULL terminated array from dll call
The pointer you get back points to the first result. Doing Inc(clientids) moves you on to the next result. Keep going until you reach an anyid that is zero ("NULL"). (You also need to save the original value of clientids so you can pass it to the free function as the documentation says to avoid leaking the memory.)

Categories : C++

Detecting memory leaks in Visual C++ (Windows)
I have used the Visual Leak Detector with quite positive results. It is small and neat, and can be built into your project (assuming you have a running Debug configuration) in a matter of seconds: https://vld.codeplex.com/ If set-up correctly (which can be done using the installer) then you only have to #include <vld.h> in one of your .cpp files for each module - that's it, the header

Categories : C++

error: incomplete type 'typename' named in nested name specifier
The type is incomplete, like it says. This is not legal (intrusive containers need to know the implementation details - bases, size etc. - at instantiation time). The documentation specifically mentions that you should avoid deducing hook types when you do this kind of 'nested' use. Given this, there are several ways to fix it: You could just shuffle things around: Live On Coliru. If you reall

Categories : C++

Not recognizing keyboard input
You are using the SDL_PollEvent incorrectly. The function does not return the type of event, but rather 1 if there are still items in the event queue, or 0 if the queue is empty. So you'd want to poll events as long as there are things in the queue and THEN do a switch over the event.type as such: void Game::handleEvents() { SDL_Event event; // Poll events until the queue is empty...

Categories : C++

How to call a Functor template class with template function
Looks like a bug in MSVC. It thinks &addValueTemplate<unsigned int> is a function, not a function pointer. Use an intermediate function pointer variable: unsigned int (*av)(unsigned int const&) = &addValueTemplate; j = unary_apply(av, i); Or use this to fool MSVC: template <typename T> T* identity(T* x) { return x; } j = unary_apply(identity(&addValueTemplate<un

Categories : C++

How to get average from array
Maybe it because the input number d is larger than 100 #include <iostream> using namespace std; int main() { int d = 0, i; double avg = 0, sum = 0, *Temperature=0; // ----------------------------------------- cin >> d; Temperature=new double[d]; //<== Use new to allocate array for (i = 0; i < d; i++) //<== Normaly array start at 0 {

Categories : C++

When and why would I use -fno-elide-constructors?
As Benjamin Lindley commented on the question, if your program relies on the side effects of copy constructors, your code is very badly written. Your copy constructors should always be written so that such optimisations are safe. Not only because the compiler may perform such optimisations, also because other human readers will otherwise have a very hard time understanding what is going on. That

Categories : C++

Error in linker c++ linux Scons : CLAM project
I don't think that you have to change anything in the SConstruct, this error doesn't seem to be related to SCons at all from my angle. The error message shows that your installation of /usr/local/lib/libclam_core.so depends on the unresolved symbols. This will give you trouble, even when trying to link "clam_core" against a simple C++ main program on the command line. Try to check the dynamic dep

Categories : C++

C++ Member Reference base type 'Vertex *const' is not a structure or union
vit is an iterator. Iteratirs work like pointers to container elements. Your container element type is Vertex*. Therefore vit works like Vertex**. To call a member function given a Vertex** p you would have to get to a Vertex* first. This can be done by dereferencing p like this: (*p) and at this point you can call your member function like (*p)->getEdges() Iterators are no different.

Categories : C++

Segmentation fault on glShaderSource()
You are using the C syntax incorrectly: char buffer[1024]; ... glShaderSource(..., (const char **)&buffer, ...); This is not a pointer to a pointer to the real string data. By definition, &buffer is the same as buffer here - a pointer to the first char in buffer, of type char *. Casting that to something else only conceals the error here. This construct can not work in principle. There

Categories : C++

Merge sort variant: using link array
I cleaned up the code, and I also added a bottom up version that uses an array of starting indexes (see below). I changed high in MergeSort() to end, so the call is now MergeSort(0, SIZE). i = MergeSort() returns the index of the smallest value in a[], then i = link[i] is the 2nd element, i = link[i] is the 3rd element, until i = -1. Instead of using insertion sort, MergeSort() directly sorts grou

Categories : C++

How to generate C++ Code from UML Diagrams in VIsual Studio 2013
Similar to the question: Any tool which generate C++ code against a design, try and investigate software packages that help you achieve your code without Visual Studio. http://en.wikipedia.org/wiki/List_of_Unified_Modeling_Language_tools

Categories : C++

Copy constructor with a parameter as a reference to a derived class
A a = b; This would call the conversion constructor of class A. A(const B&){ } << This is conversion constructor for class A which defines conversion from B to A Its same like we declare A(int i) {} << Convert int to class A object. Even if you remove the relationship between class A and B then also it lead to that constructor call.

Categories : C++

What is the default build configuration of cmake
target_link_libraries with optimized keyword corresponds to all configurations, which are not debug. Try adding message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") to your CMakeLists.txt to see the actual build type (I suppose it should be empty).

Categories : C++

SpotLight is not seen - OpenGL
The order of a couple of members of the LightSourceProp struct in the C++ code is different from the one in the uniform block. Last two members of the uniform block: uniform float cutOffExponent; uniform float spotCutoff; }; Last two members of C++ struct: float spotlightCutoffAngle; float cutOffExponent; }; These two values are swapped. Also, the cutoff angle looks suspic

Categories : C++

Using classes and constructors and create a object name with an array size of 3
You have not shared with us the value for SIZE; however, I'm guessing that you probably have it less than 10. If that were the case, then it would crash later when you're looping through Kmart3. Making this change should stop the crashing (at least it does in my testing): for (int i = 0; i < SIZE; i++) { if (Kmart3[i].get_item_name().length() > 0) cout << Kmart3[i].get_i

Categories : C++

C++ assign default hash function into member variable
You need to make your default_hasher use const for its parameter, since HashFunction specified so. Besides, it's the sensible thing to do, in the name of const-correctness.

Categories : C++

return char from std::string vector
You are getting an error when calling init in main. The string literal "/usr/bin/php getMyorders.php 155" has type const char * and call to init requires an implicit conversion to char *. Such conversion (for string literals) was allowed, but it's now deprecated. popen's first argument has type const char *, so I don't see a reason why should init require a non-const parameter. Declare it as FIL

Categories : C++

Modify date time to a specific format
I am not really sure but try this, txtMonday->Text = Convert::ToString(dtpMondayIn->Value.ToString("hh:mm tt",CultureInfo.InvariantCulture)); OR Convert::ToString(dtpMondayIn->Value.ToString("hh:mm",CultureInfo.InvariantCulture)); Also check DATETIME PICKER VALUE PROP and DATETIME FORMATS Let me know in case it works.

Categories : C++


Recently Add
Returning the actual value of maximum of absolutes of variables
Microsoft c++ optimizing compiler has stopped working
Overloading operator[] changing value
what does the printf/snprintf format character %N do? (not %n)
Eigen and C++11 type inference fails for Cholesky of matrix product
Qt KeyPress Event on QlineEdit
Any reasons to look at alternatives to inheritance / polymorphism?
Cannot cast the structure pointer to char pointer in c++
Changing a C/++ OpenCV program to CUDA from video stabilization program
c++ change of coordinates (Pixels 1920 x 1080 to 640 x 480)
WinAPI SetSystemCursor and LoadCursorFrom - how to set default cursor?
Multiple clients in c++ server
avoid specifying redundant template parameters which contain templated function pointer
How to obtain mp3 audio packets for streaming in C/C++
How do I search for an element from each node in C++ using queue?
Difference between private static members and having them in the cpp file
Is the size of built-in datatypes in c++ managed on source code level?
Deleting elements dequeued using "top" from priority_queue c++
C++ Ordering the names of a scoreboard
QColor hsl hue precision
cannot read the text file properly anymore
g++ 4.8.* std::chrono Undeclared
How can I make a 'const tm*' from a 'const tm&'?
Can clang-format align variable or macro assignments in columns?
Obtaining First and Last Charsof Each String From A Vector of Strings
boost filesystem canonical path is not valid after conversion to const char *
SIGSEGV, Segmentation fault
Is there a way to detect if a primitive argument is variable size?
why can I pass a reference as an argument to a constructor's pointer parameter?
Which compiler flag am I missing in my build on the so file?
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.