spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » C++ » Page 2
How to add OpenCV Contour Smoothing to Existing Buffer
This is the C# code converted to C++ in the second code block: //.h file code: using namespace Emgu::CV; using namespace Emgu::CV::Structure; namespace Microsoft { namespace Samples { namespace Kinect { namespace BodyIndexBasics { /// <summary> /// Class responsible for extracting out the contours of an image.

Categories : C++

Opencv 3 SVM training
with opencv3.0, it's definitely different , but not difficult: Ptr<ml::SVM> svm = ml::SVM::create(); // edit: the params struct got removed, // we use setter/getter now: svm->setType(ml::SVM::C_SVC); svm->setKernel(ml::SVM::POLY); svm->setGamma(3); Mat trainData; // one row per feature Mat labels; svm->train( trainData , ml::ROW_SAMPLE , labels ); // ... Mat query; // inpu

Categories : C++

Can't set timeout for Qt's waitForConnected
Did the method returned true or false? If it returned true, the connection has been established. According to the documentation, waitForConnected() waits up to 30 seconds for the connection, but if the connection has been established before, it returns directly.

Categories : C++

c++ - managing entities in a vector
You may have to refine the question a bit more: What is the scope of std::vector enemies? To answer the first part of the question: enemies has been declared to be a vector and not a pointer to Enemy. This is why you have to generate a reference by doing "*this" as an argument to push_back() call. You are effectively keeping a copy of all the objects constructed in this vector. Is that your inte

Categories : C++

How can I create a custom list in C++ for Qml?
There is good enough official documentation about using models in QML. First of all you need to know what is Model-View approach -- Models and Views in Qt Quick. Later on you can see exactly what you want here: Using C++ Models with Qt Quick Views. My recommendation for you (as for beginner) is to look more precisely at QObjectList-based model. Also I prepared little working exaple which can be

Categories : C++

How to append a large number of elements to stxxl vector efficiently?
According to the documentation: If one needs only to sequentially write elements to the vector in n/B I/Os the currently fastest method is stxxl::generate. Does not really answer why push_back should be I/O-inefficient, though.

Categories : C++

How to reuse function specialization code?
As suggested by @0x499602D2 in the comments, create another function and make sure it gets called only for int or double. template<typename T> void bar(const T & val) { // Make sure this gets called only for int or double. static_assert(std::is_same<T, int>::value || std::is_same<T, double>::value); // Do useful stuff with val. } template<> void fun<int&g

Categories : C++

Dynamically alloceted array, double free or corruption
There are several things wrong with your code: Usage of memcpy to copy data. If the template type T is a non-POD type, you cannot use memcpy to copy over the data. You have to copy the items one-by-one, or use std::copy If you haven't coded one, you are missing the copy constructor. Here is what it should look like: template<typename T> CArrays<T>::CArrays<T>(const CArra

Categories : C++

How do you write to a second console?
I am not quite sure where you are going with the separate process in your code snippet. However, you can't have more than one console associated with a single process in Windows, although you can have multiple screen buffers associated with a single console and toggle between them (see SetConsoleActiveScreenBuffer and go from there), but you'll have to implement a user-interface for that toggling;

Categories : C++

Returning the actual value of maximum of absolutes of variables
int z = (max(abs(x), abs(y)) == abs(x)) ? x : y; This is like an if-condition. Its equivalent to int z = x; if(max(abs(x), abs(y)) != abs(z)) z = y; But much shorter. There is no function in the STL to fit into your needs directly, so you need to make your own and this one could be one version. A more handy one can be int z = (abs(y) < abs(x)) ? x : y thought.

Categories : C++

Microsoft c++ optimizing compiler has stopped working
Template variables are new in c++14. VS2008 certainly doesn't implement them. template <typename T> std::vector<T> m_vMonitorVec; should likely be template <typename T> class testTemp { public: testTemp(void) { } ~testTemp(void) { } int MonitorSignal(T x, std::vector<T> const& vec, int len) { return 0; } private: std::vector<T>

Categories : C++

Overloading operator[] changing value
In the subscript operator you also should check that i is not less than first. Tale into account that relative to the pointer you have to use indices starting from zero. So instead of return arrPtr[i]; you have to write return arrPtr[i - first]; Also it would be better if constructor IntArray(int num); would be declared like IntArray( size_t num); and correspondingly data member size w

Categories : C++

what does the printf/snprintf format character %N do? (not %n)
According to standard documentation (e.g. POSIX printf) it does nothing defined (so %N could be undefined behavior, and is certainly unspecified behavior in the standards). However, the GNU glibc offers customizing printf abilities. Your program might have registered (elsewhere) with register_printf_function something to handle %N. This is not standard and is GNU glibc specific (however, it is a

Categories : C++

Eigen and C++11 type inference fails for Cholesky of matrix product
The problem is that the first multiplication returns a Eigen::GeneralProduct instead of a MatrixXd and auto is picking up the return type. You can implicitly create a MatrixXd from a Eigen::GeneralProduct so when you explicitly declare the type it works correctly. See http://eigen.tuxfamily.org/dox/classEigen_1_1GeneralProduct.html EDIT: I'm not an expert on the Eigen product or performance chara

Categories : C++

Qt KeyPress Event on QlineEdit
No, you can't do this with Designer.If you don't want to use inheritance, then you should use event filter. For example: bool Dialog::eventFilter(QObject *obj, QEvent *event) { if (obj == ui->lineEdit && event->type() == QEvent::KeyPress) { QKeyEvent *key = static_cast<QKeyEvent *>(event); qDebug() << "pressed"<< key->key(); } ret

Categories : C++

Any reasons to look at alternatives to inheritance / polymorphism?
Well if you want to be as generic as possible for just "a collection of tasks", you can use std::function: std::vector< std::function<void()> > tasks; That way your tasks don't all have to inherit from Task. Or even be objects. void printHello() { cout << "Hello "; } tasks.push_back(printHello); tasks.push_back([]{ /* do stuff */ }); struct Object // doesn't inherit fr

Categories : C++

Cannot cast the structure pointer to char pointer in c++
Based on your description (with char), you're trying to print it as a string printf("%s"). If eth->hlp will have a value of 0x12000000 (301989888) on x86 machine it will be stored in memory as 0x00000012. And strings in C/C++ are null terminated. while(*ptr != ''){ putc(*ptr); ++ptr; } And since your first byte is it terminates before the first character. I would use loop: for(in

Categories : C++

Changing a C/++ OpenCV program to CUDA from video stabilization program
Since OpenCV 3.0, a CUDA implementation of video stabilization is available. It is recommended to use the already available implementation instead of writing your own unless you are sure that your version would be better or faster. Here is a minimal code demonstrating how to use the OpenCV video stabilization module to stabilize a video. #include <opencv2/highgui.hpp> #include <opencv2/

Categories : C++

c++ change of coordinates (Pixels 1920 x 1080 to 640 x 480)
Wokay, since people urged me, let me explain the most important style improvements here: Naming: don't start names with underscores: It's illegal and the program invokes undefined behaviour struct tags: they're a thing of C, and obsolete in C++ ever since C++98 Single Responsibility Principle - don't make the transform function print things Make the Pixel struct capable of printing itself (using

Categories : C++

WinAPI SetSystemCursor and LoadCursorFrom - how to set default cursor?
According to the SetSystemCursor docs: To specify a cursor loaded from a resource, copy the cursor using the CopyCursor function, then pass the copy to SetSystemCursor. So doing this might fix your original problem: HCURSOR hCurDef = CopyCursor(LoadCursor(0, IDC_ARROW)); SetSystemCursor(hCurDef, OCR_NORMAL); DestroyCursor(hCurDef); If that doesn't work, you can store the filename of the

Categories : C++

Multiple clients in c++ server
Your question is quite open, but in general you need threads. Pseudocode: int main() { std::vector<std::thread> clients; Socket listener("localhost", "1337"); for (;;) { Socket tmp = listener.accept(); clients.push_back(std::thread(&myHandlerFunction, tmp)); clients.back().detach(); } } In the end you have a thread for every connected client and can codi

Categories : C++

avoid specifying redundant template parameters which contain templated function pointer
In this example u is not a function pointer, it's a type (the signature of a function pointer). If you want to store a function pointer you need to pass it. template<class T, class F = void(*)(T&)> void Foo(F f) { // store the function pointer f here } called like so: struct SomeType {}; void bar(SomeType& x); Foo(&bar); Is this what you mean to do?

Categories : C++

How to obtain mp3 audio packets for streaming in C/C++
An MP3 file is just a succession of MP3 frames. Each frame is made of a header and a data block. Splitting the MP3 file as MP3 frames will involve parsing the MP3 file. You can refer to this documentation for a good description of the format. Note that in the case of mpeg layer 3 codec, frames are not independant. In the worst case, 9 input frames may be needed before beeing able to decode one s

Categories : C++

How do I search for an element from each node in C++ using queue?
This is how your function probably should look, but if you still get crashes it means something else is wrong in your program and we would need to see more code. node* lookup(int _patient_id) { node *newnode = front; while (newnode != NULL) { if (newnode->patient_id == _patient_id) { cout<<"Found!!!!!!!"; return newnode; }

Categories : C++

Difference between private static members and having them in the cpp file
The difference is that the private static members are part of the class, and therefore have access to private and protected members of instances of the class. The free functions would not. Example: class A { A(a) : _a(a) {} private: // legal - _a is accessible because get_a is part of A static int get_a(const A& a) { return a._a; } private: int _a; }; // illegal - _a is a private m

Categories : C++

Is the size of built-in datatypes in c++ managed on source code level?
Short answer: no. The sizeof fundamental types like char (and therefore signed char) is defined by your compiler, based on the target system architecture. They're not defined in code. The typedef above means the opposite - it's defining a new type named int8_t, in terms of the predefined char type. On your system (as on most) char is 8 bits wide, so it's the natural way to define an 8-bit intege

Categories : C++

Deleting elements dequeued using "top" from priority_queue c++
The only satisfying solution is using std::unique_ptr or std::shared_ptr. You should anyway always try to avoid using a raw new, using smart pointers gives you exception safety and no memory leaks. The overhead for unique_ptr is almost non-existent, shared_ptr takes a bit more, but you get copy functionality. With C++14 you should use std::make_shared or std::make_unique. Edit: However, you

Categories : C++

C++ Ordering the names of a scoreboard
Sounds like you probably want a std::map. If your scoreboard_names are immutable and unique then you could just do this to construct your scoreboard: map<string, int> scoreboard{{"a", 10}, {"b", 9}, {"c", 8}, {"d", 7}, {"e", 6}}; Adding to your scoreboard could be done like this: scoreboard.insert(make_pair(newname, newscore)); And in std::map everything is sorted by key, here being y

Categories : C++

QColor hsl hue precision
The issue seems to be simply how Qt rounds the colour component values when requesting an integer output. To illustrate on your example: QColor col(255,168,177); std::cout << "hue_float " << col.hslHueF()*360.0f << std::endl; std::cout << "hue_int " << col.hslHue() << std::endl; Outputs: hue_float 353.79 hue_int 353

Categories : C++

cannot read the text file properly anymore
Are you sure your text-file is readable by the program? If the input file does not exist, the program will still try to print argv[2]**2 entries from array which does not contain any elements! The program ends up dumping garbage values. I am also not sure why you do the pow call - why not get the number of elements from argv[2]? Also, you use some c functions (atoi) when you could use C++ string

Categories : C++

g++ 4.8.* std::chrono Undeclared
There is no std::chrono::monotonic_clock in standard C++. There is a std::chrono::steady_clock, however. In fairness to Microsoft - and burritos everywhere - there was a monotonic_clock in the working drafts during the development of C++11 which was replaced by steady_clock.

Categories : C++

How can I make a 'const tm*' from a 'const tm&'?
static_cast<const tm*>(getTM()) You certainly don't want a static_cast<> (nor a reinterpret_cast<>) to do this! See the reference for std::asctime(), it wants a pointer actually: char* asctime( const std::tm* time_ptr ); // ^ "How can I make a 'const tm*' from a 'const tm&'?" Your function returns a const &, that's not a pointer. Cha

Categories : C++

Can clang-format align variable or macro assignments in columns?
Clang-format does not have any option to do this. If you want to tell clang-format to leave certain lines alone, you can make it do so with // clang-format off and // clang-format on comments.

Categories : C++

Obtaining First and Last Charsof Each String From A Vector of Strings
Assuming name is your string and you're OK with using C++11, name.front() and name.back() will work, otherwise dereference the iterator: *name.begin() and *name.rbegin(). Though you'd check whether the name is empty or not: if (!name.empty()) { // Safe to proceed now } You can iterate over names like (range loop - since C++11) for (auto& name : names) { // Do things with individual

Categories : C++

boost filesystem canonical path is not valid after conversion to const char *
Despite not being standard practice, forward slashes are also accepted on Windows, that's why boost isn't forcing the conversion. However, some libs won't accept forward slashes. boost::filesystem::path::make_preferred()[1] is meant to solve such situations, by converting the path to the system's preferred representation (i.e. using backslashes on Windows). [1] This older reference makes that be

Categories : C++

SIGSEGV, Segmentation fault
Your problem is that you're doubling the value of size, even though p_entry is of the initial size. Update the code to this: FriendInfo *growArray(FriendInfo *p_entry, int *size) { int newSize = *size * 2; FriendInfo *p_new_friends = new FriendInfo[newSize]; for (int i = 0; i < *size; ++i) { p_new_friends[i] = p_entry[i]; } delete [] p_entry; *size = newSize

Categories : C++

Is there a way to detect if a primitive argument is variable size?
Is there a way of causing a compiler error if somebody tries to use a non fixed size variable? No. This is completely nonsensical since int32_t might well be defined as a typedef to int (and very often is). I.e. std::is_same<int, std::int32_t>::value == true. You cannot distinguish them. Serialize the size of int and check for it on the platform you're deserializing on. That is, chec

Categories : C++

why can I pass a reference as an argument to a constructor's pointer parameter?
The reason it works is that when you call city(cityobj) it uses the compiler's implicitly defined copy constructor, and when you call city(&cityobj) it uses the converting constructor you defined yourself: city(city* cityobj). You didn't mean to say neighbor(&cityobj) did you?

Categories : C++

Which compiler flag am I missing in my build on the so file?
When you link a library with -lLib, the linker looks for a file named libLib.so in the standard library paths, but the current directory is not usually between them. You have two options: g++ -std=c++11 -o App App.cc -L. -lLib Or else: g++ -std=c++11 -o App App.cc libLib.so Note, however, that when running the program, the dynamic linker will look for the library following its own rule

Categories : C++


Recently Add
C++: error C2143: syntax error : missing ';' before '<'
Converting 2s compliment to a decimal. Output is double
how do you compare a string to a vector value?
Converting a long double to double with upward (or downward) rounding
C++: operator<< overloading in the nested classes
Unclear behavior with csv processing using getline
C++ Visual Studio Error: IntelliSense: expected a statement
Game of Nim - showing the remaining numbers and letting a player pick their name?
malloc 1D array in struct
How to create an array of smart pointers?
c++ swapping unique_ptr's
Functions as arguments
Any Fast & Efficient way to generate a 3D Grid?
Is string[] not a type?
C++ typeid(x).name() returns ph
Counting / Printing Path - From (1,1) to (m, n)
C++ input function that calls itself
Error: array must be initialized with a brace-enclosed initializer
SDL_ConvertSurface() causes break
C++ std deviation function?
libcURL Progress Function not being called
What is QList's maximum size?
Run batch with C++
Read a file and write its contents to another C++
extract from stringstream into 2D vector
How to stop Scons adding lib infront of a shared library
Blocking vs non-blocking mode in TCP sockets using C++
SDL2 toggle SDL_WINDOW_RESIZABLE state for fake fullscreen
How can I assign value to specific vector's index?
Operator Overloading with Constant Iterators
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.