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 |
|---|---|---|---|---|
4,135,312 | 4,135,413 | template function matching in g++ | I'm having an odd problem, and am wondering why g++ 4.1.2 is behaving the way it does.
Stripped to its essentials:
#include <iostream>
template<typename T>
inline void f(T x) { std::cout << x*x; }
namespace foo {
class A {
public:
void f() const { f(2); }
};
}
The call to f(2) fails because the compiler fa... | The compiler examines all scopes for a candidate, starting with the current scope. It finds a function named f in the immediate scope, and there stops the search. Your template version is never examined as a candidate.
See Namespaces and the Interface Principle for a complete explanation.
|
4,135,313 | 4,135,424 | is non-blocking concurrent programming for real? | I have been reading random links on non-blocking algorithms and uses thereof in concurrent programming. Are there any useful libraries using non-blocking algorithms with C/C++ and what types of concurrent data structures that benefit the most from the use of non-blocking algorithm? Thanks.
| boost::thread uses compare-and-swap semantics for shared_mutex on Windows - only if contention occurs is a blocking call made (using semaphores).
Windows itself supports use of a spin count on Critical Sections via InitializeCriticalSectionAndSpinCount to attempt to optimize a bit for high-contention locks on MP syst... |
4,135,516 | 4,140,338 | JVM signal chaining SIGPIPE | We have a C++ application with an embedded JVM (Sun's). Because we register our own signal handlers, it's recommended we do so before initializing the JVM since it installs its own handlers (see here).
From what I understood, the JVM knows internally if the signal originated from its own code and if not it passes it al... | The JVM can't tell whether the SIGPIPE came from it's own code, or your code. That information just isn't given by the signal. Because it doesn't want you to miss out on any possible events that you could be interested in, it has to pass you all SIGPIPEs, even the ones that it turns out were from its own code.
Unix s... |
4,135,586 | 4,135,630 | Is there a more efficient way to sort two numbers? | I want dLower and dHigher to have the lower and higher of two double values, respectively - i.e. to sort them if they are the wrong way around. The most immediate answer, it seems is:
void ascending(double& dFirst, double& dSecond)
{
if(dFirst > dSecond)
swap(dFirst,dSecond);
}
ascending(dFoo, dBar);
But ... | This is a good way of approaching it. It is as efficient as you are going to get. I doubt that this specific function has a generally recognized name. This is apparently called comparison-swap.
Generalizing it on type is as easy as:
template <typename T>
void ascending(T& dFirst, T& dSecond)
{
if (dFirst > dSecond)... |
4,135,604 | 4,135,724 | Variadic templates: Pass parameter pack without expansion | The old C stdio facilities provided a way to pass along a variadic argument set using the vprintf facilities.
Is there a similar way to pass along a C++0x variadic template parameter pack without expanding it?
This might be useful if you have a derived class constructor that takes a variadic template parameter pack, an... | I don't understand how expanding is an issue : won't expanded arguments be just re-packed in Base constructor ? I believe using args... will work as expected.
|
4,135,936 | 4,139,571 | IDE / setup for package development with C++ code integrated | I'm trying to get a grip on C++/Rcpp as an extension to R for heavy computational tasks. Ultimately, these C++ libs should be integrated in a package, and therefor I'm looking for a setup / combination of tools / IDE that I would need to work easily. I know much is taste dependent, but still it would be nice to know my... | Eclipse + statet if you want to join in us in the modern world :)
|
4,135,975 | 4,136,005 | What is this syntax? |
Possible Duplicate:
What does a colon following a C++ constructor name do?
I am finding this syntax strange in C++
TagDetails::TagDetails(QWidget *parent) :
QDialog(parent),
ui(new Ui::TagDetails)
This is declaration of constructor in C++... What does the thing after colon stand for, i.e. what does ui(new Ui::TagDe... | It is a member initialization list.
ui(new Ui::TagDetails) means that the member variable ui is initialized with the pointer to newly allocated object of type Ui::TagDetails.
|
4,136,156 | 4,136,642 | const member and assignment operator. How to avoid the undefined behavior? | I answered the question about std::vector of objects and const-correctness, and received a comment about undefined behavior. I do not agree and therefore I have a question.
Consider the class with const member:
class A {
public:
const int c; // must not be modified!
A(int c) : c(c) {}
A(const A& copy) :... | Your code causes undefined behavior.
Not just "undefined if A is used as a base class and this, that or the other". Actually undefined, always. return *this is already UB, because this is not guaranteed to refer to the new object.
Specifically, consider 3.8/7:
If, after the lifetime of an object
has ended and before... |
4,136,429 | 4,136,492 | Creating a MFC DLL in Visual Studio | As far as I can tell, Visual Studio 2008 provides two ways of making a MFC DLL:
New Project -> MFC DLL
New Project -> Win32 Project -> select DLL, Export symbols, & MFC
What is the difference? The two methods seem to generate very different starter code. The second methods appears to generate code that I would expe... | The first creates what is called an MFC "Extension DLL". The key distinction here is that this DLL is only available to MFC programs and other DLLs that use MFC. Its public interface may pass MFC types between the DLL and its clients.
The second creates a "Regular DLL" that links to MFC. It can use MFC internally bu... |
4,136,498 | 4,136,662 | gtkmm and MSAA accessibility | I'm interested to know if gtkmm w/ ATK (or whatever) works with MSAA like Qt does. We're looking right now at switching toolkit from WX and it turns out that our testing software relies on MSAA to do it's thing (something I wish I'd known 3 years ago when we picked WX to begin with). Of all the GUI toolkits, I prefer... | I can’t say for sure but I would lean toward very little to no support. I use the Jaws screen reader SOFTWARE SINCE I’m blind. It uses MSAA quite heavily and GTK applications such as Pidgin are almost completely inaccessible. While I can read some of the text on a screen figuring out weather I’m in an edit field or wea... |
4,136,762 | 4,136,878 | copy/conversion constructor definitions (const/non-const) | Let me demonstrate with a simple example:
class A
{
public:
A() { cout << "A::A()" << endl; }
A(A const& a) : _a(a._a) { cout << "A::(A Copy Const)" << endl; }
A(A& a) : _a(a._a) { cout << "A::(A Copy)" << endl; }
template <typename _T1>
A(_T1& v1) : _a(v1) { cout << "A::(T conversion)" << endl; }
~A() { ... | A templated constructor is never a (formal) copy constructor.
You're right that a declaration that could be a function declaration is treated as a function declaration. It's called "the most vexing parse" of C++. One workaround is to use extra parentheses, like T v(( U )).
It may be that adding an auto keyword would fi... |
4,136,766 | 4,136,798 | Reporting an exception in Boost::test | Using the boost::test framework, is there a way to detect if an exception (of some type) has been thrown from a function?
| Are you looking to test that a function correctly throws under some circumstances?
If so
BOOST_CHECK_THROW( function(), exception_type );
will do it. You can use
BOOST_CHECK_EXCEPTION( function(), exception_type, predicate )
to call an arbitrary predicate on the exception when it's caught and
BOOST_CHECK_NO_THROW( ... |
4,136,770 | 4,137,056 | receiving data from a boost socket problem | i made a server via boost networking and its working good but when i store the clients connecting to it in a std::map, then loop all the map and receive from them it gives me segmentation fault, heres the backtrace (gdb):
Program received signal SIGSEGV, Segmentation fault.
boost::asio::basic_stream_socket<boost::asio:... | Try this, to limit the amount of data read into your read_some buffer:
sock->read_some(boost::asio::buffer(buffer, 1024), err);
You could also use the std::string overload directly:
std::string buffer(1024, 0);
sock->read_some(boost::asio::buffer(buffer, 1024), err);
return buffer;
|
4,136,788 | 4,147,621 | Interrupting a C function execution and getting back to C++ caller | I currently have a problem implementing the following scenario using the following configuration: GCC 3.4, Linux.
I have written a tool (in C++) which loads a shared library (written in C). This library has a bug which I cannot influence to fix. The problem is that it reads some input and writes decoded output. Sometim... | Ok Guys,
I did it with sigsetjmp/siglongjmp. Works like a charm. I can jump over the function into the stack of the caller function and do error handling there.
Thanks for all the suggestions.
Best Regards,
Ovanes
|
4,136,815 | 4,136,870 | set vs vector with custom iterator | I understand this question may be quickly flagged as a duplicate of many other more popular questions, but I'll still ask it:
I need a container that provides duplicate checking on insert (like std::set, but allows me to modify elements already present (like std::vector). It should also be relatively fast to search for... | What is to stop you from using a std::set? If you need to modify an element, copy it, erase it, then re-insert.
|
4,136,900 | 4,137,166 | What Rules does compiler have to follow when dealing with volatile memory locations? | I know when reading from a location of memory which is written to by several threads or processes the volatile keyword should be used for that location like some cases below but I want to know more about what restrictions does it really make for compiler and basically what rules does compiler have to follow when dealin... | A particular and very common optimization that is ruled out by volatile is to cache a value from memory into a register, and use the register for repeated access (because this is much faster than going back to memory every time).
Instead the compiler must fetch the value from memory every time (taking a hint from Zach... |
4,137,039 | 4,137,126 | Errors using decltype() and SFINAE | In response to .. some other question somewhere, I wrote this code.
struct no_type{};
template<typename T> struct has_apply {
static decltype(T().apply<0u>(double())) func( T* ptr );
static no_type func( ... );
static const bool result = !std::is_same<no_type, decltype(func(nullptr))>::value;
};
class A {
... | SFINAE applies when substitution fails for a function template's template parameter, not for a class template's template parameter that has the (non-template) function in question as a member, as is in your case.
After fixing that, you should at least change decltype(T().apply<0u>(double())) to decltype(T().template ap... |
4,137,131 | 4,138,934 | Problem with the boost program options descriptions | Here is a striped down version of one of the examples in boost::program_options:
#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include <iostream>
#include <iterator>
using namespace std;
int main( int argc, char *argv[ ] )
{
try {
int opt;
po::options_description d... | You can adapt the technique of hidden options to provide one set of options for parsing and another set for printing the help. This will require you to maintain two copies of the option list, though.
For example, start with your current desc definition, and then below it add another one:
po::options_description display... |
4,137,162 | 4,137,211 | How to create a release built of Win32 C++ app that uses lots of libs and not only included in VS environment headers? | So I created an app (with lots of help from SO and my friends). It compiles and runs on my machine (I tied to place it into different folders). VS created for me a debug older with my app : HelloVideoStreaming.exe some HelloVideoStreaming.ilk and HelloVideoStreaming.pdb. Problem is - when I try to run my app on another... | Do you mean "side-by-side" configuration is flagged as incorrect? You have to make sure that the runtime libraries you built with are available on the target machine, also any third-party DLLs that you need, though it sounds like you tried to use all static libraries there. For info on how to run VC++ apps from VS201... |
4,137,239 | 4,137,257 | garbage values in C/C++ |
Possible Duplicate:
How an uninitialised variable gets a garbage value?
How are garbage values generated in C and C++ ? Does the compiler use some random number generation technique for generating garbage values?
| If you mean the values of uninitialized variables, those aren't generated. They're just whatever garbage happened to be in that memory location.
int *foo = new int;
std::cout << *foo << std::endl;
New returned a pointer to some address in memory. That bit of RAM has always existed; there is no way to know what was sto... |
4,137,295 | 4,137,624 | How can one make a Visual Studio 2010 Project Dependency be Configuration-specific? | This one may be a bit strange. I have a solution in Visual Studio 2010 with three C++ projects. Two libraries and one executable application. Two configurations. In one configuration, I need the executable application to have a project dependency on one library, in the other configuration I need the executable applicat... | Is the C++ project format msbuild? If so, you should just be able to put a condition on the reference. Reference both projects and then edit the project file and add a condition on each one. This is how it would work in a C# project, not sure if c++ is the same:
<ProjectReference Include="..\DirectXLib\DirectXLib.cs... |
4,137,305 | 4,137,321 | Why is this output waiting for something after it? | void Wait(double Duration)
{
clock_t End;
End = clock() + (Duration*CLOCKS_PER_SEC);
while (clock() < End)
{
// This loop just stalls the program.
}
}
My function works perfectly half the time, but it occasionally stalls the program before it's even called. For example, take the following... | try
cout.flush();
before your Wait
|
4,137,367 | 4,137,935 | Why doesn't lsof show that libstdc++ is loaded on Mac OS X? | I have an application that I know uses libstdc++, but even as the super user, I cannot see /usr/lib/libstdc++.6.0.9.dylib on my Mac OS X 10.6 Snow Leopard system?
lsof | grep libstdc++
If I use DYLD_LIBRARY_PATH to use my own copy of libstdc++ it shows up in the full path while my app is running:
fooo 1701 foooo txt ... | I guess the reason is libstdc++ is considered a system library in OS X and is treated differently than other user libraries.
If you want the system to load it just like a user supplied library use something like:
export DYLD_SHARED_REGION=avoid
./your_program_name
man dyld for more information on what the above enviro... |
4,137,494 | 4,138,435 | template class and insertion extraction overloaded | How can I make the insertion (<<) and/or extraction (>>) operator overloaded in a template class WITHOUT making it inline. I would like to have the << or >> operator as a friend class.
I know how to make it inline
example of inline in a matrix class
friend ostream& operator<<(ostream& ostr, const Matrix<T>& inputMatrix... | If you really want to define the operator externally and befriend only the operator instantiation that coincides in type with this template instantiation, the correct syntax is:
template <typename T> class test; // forward declare template class
template <typename T> // forward declare the templated operat... |
4,137,609 | 4,137,747 | Where to get OpenAl32.Dll that would be capable of running from folder with your app not from system32? | So I created an app. Usualy its enough to put dlls like ffmpeg ones in folder with it for further app distribution during project creation steps but this OpenAL32.DLL just does not want to work for me like that. So where to get redistributable OpenAL32.dll?
| This is pretty much all you'll ever need/find. Most apps that use openAL, use the installed version. Are you sure you're using the right bitness DLL (32-bit vs 64-bit) and that the missing DLL is the cause of the failure?
|
4,137,627 | 4,137,727 | Function overloading from a base class when all types are not known | I've stumbled into a problem which, at a glance, is easy cplusplusable, but on careful study appears not to be.
I have items in my program which I will need to work with many types, so I have decided to handle these in a generic, extensible way:
class ItemBase
{
public:
virtual ~ItemBase() = 0 {}
// pure virtual c... | The easy answer would be : add a virtual buildComponent method in ItemBase. However, as you want to keep the GUI Components separated, I'd recommend a Visitor pattern.
A very simple implementation would consist of :
Adding a single accept(AbstractVisitorType &) virtual method in ItemBase
Implementing this method in ev... |
4,137,661 | 4,138,128 | Can't read from socket (hangs) | I am using PHP to connect to a local C++ socket server to keep state between a web app and a couple of daemons. I can send data to the socket server, but not receive from it; it just blocks on socket_read() and hangs indefinitely. Am I forgetting something dumb (like a NULL character or a different combination of new... | Sockets in PHP, as in most programming languages, are opened in blocking mode by default, unless set otherwise using socket_set_nonblock.
This means that unless a timeout/error occurs or data is received, socket_read will hang there forever.
Since your termination character seems to be a new line, try that:
while($resp... |
4,137,672 | 4,137,750 | Passing LPCWSTR by reference | I was tidying up some code I wrote a long time ago, putting it into methods and the like, when I tried this to get an input string and LPCWSTR from an input prompt for a directory search.
void GetInfo(string &stdStr, LPCWSTR &wStr)
{
cout << endl << "Enter String: ";
getline(cin, stdStr);
string sTempP = s... | There are several things that I would improve in that code, but your main problem is that LPCWSTR is a pointer to a string, not a string. You are assigning a new pointer value to wStr, but by the time your function has returned, the memory that is being pointed to is no longer valid.
When UNICODE is defined, that memor... |
4,137,748 | 37,625,936 | C++ Converting a time string to seconds from the epoch | I have a string with the following format:
2010-11-04T23:23:01Z
The Z indicates that the time is UTC.
I would rather store this as a epoch time to make comparison easy.
What is the recomended method for doing this?
Currently (after a quck search) the simplist algorithm is:
1: <Convert string to struct_tm: by manual... | Using C++11 functionality we can now use streams to parse times:
The iomanip std::get_time will convert a string based on a set of format parameters and convert them into a struct tz object.
You can then use std::mktime() to convert this into an epoch value.
#include <iostream>
#include <sstream>
#include <locale>
#inc... |
4,137,923 | 4,147,625 | Causing cpp (C preprocessor) to remove C++ comments on Mac OS X | I have a user report (unfortunately can't verify it due to lack of appropriate machine) that the C preprocessor (cpp) command on Mac OS X 10.6.4 doesn't remove C++/C99 double slash // comments from files it processes, no matter what option it's given. This is the gcc version:
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 ... | I've found a formula that works with the cpp command: try cpp -xc++ (note the lack of spaces between -x and c++).
$ printf '/* block comment */\n// line comment\nnot a comment\n' | cpp -xc++
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
not a comment
contrast:
$ printf '/* block comment */\n// li... |
4,137,970 | 4,139,707 | Enumerable Qt widgets | I have a Qt dialog box with several controls that need more or less uniform processing. I want to store pointers to them in an array and enumerate over them.
In Windows, I'd use sequential control IDs and GetDlgItem(hDlg, IDC_BASEID + i) in a loop. In Cocoa, i'd use sequential view tags or include them in an invisible ... | Maybe QObject::findChildren(QRegExp) can do the trick if the widgets have similar names.
QList<QLineEdit*> lineEdits = dialog->findChildren<QLineEdit*>(QRegExp("lineEdit[0-9]+"));
foreach (QLineEdit* lineEdit, lineEdits) {
lineEdit->clear();
}
|
4,137,992 | 4,138,084 | Overriding operator>> for a Strings class | I just have a quick question. I need to override the operator >> for a custom String class and I can't quite figure out how to do it.
I know that this code works, because it was my original method of solving the problem:
istream& operator>>(istream &is, String &s) {
char data[ String::BUFF_INC ]; //BUFF_INC is prede... | You don't seem to be doing anything with the character you get from the stream
istream& operator>>(istream &is, String &s) {
char data[ String::BUFF_INC ];
int idx = 0;
data[ 0 ] = is.get();
while( (data[ idx ] != *String::WHITESPACE) && !is.ios::fail() ) {
++idx;
is.get(); // you don't do ... |
4,138,153 | 4,138,181 | Double Entry Accounting in C/C++/Objective-C | I am working on a program and need to implement a double-entry accounting system. It would seem to me that there should be some open source project or code base out there already with most all of the basic accounting functions already written, but Google didn't turn anything up.
I don't want to re-invent the wheel, so... | GnuCash - http://www.gnucash.org/
|
4,138,168 | 4,138,730 | What happens when I throw a C++ exception from a native Java method? | Suppose I'm embedding Sun's JVM in a C++ application. Through JNI I call a Java method (my own), which in turns calls a native method I implemented in a shared library.
What happens if this native method throws a C++ exception?
edit: compiler is gcc 3.4.x, jvm is sun's 1.6.20.
| Within the JNI literature, the word exception appears to be used exclusively to refer to Java exceptions. Unexpected events in native code are referred to as programming errors. JNI explicitly does not require JVMs to check for programming errors. If a programming error occurs, behavior is undefined. Different JVMs may... |
4,138,236 | 4,138,272 | converting c++ class to an equivalent java class | Suppose I have a constructor in c++ as:
public class Machine {
public:
Machine(int boltCount, bool failure=false);
};
How do I convert this to an equivalent class in Java?
Thanks,
| something like that
public class Machine {
public Machine(int boltCount) { this(boltCount, false); }
public Machine(int boltCount, bool failure) { /*body here*/ }
};
|
4,138,252 | 4,138,623 | Is tail recursion possible if a comparison depends on the return value? | I had a homework assignment that asked for a function that uses direct recursion to find the index of the left-most, lowest, negative integer in an array. Additional requirements were for the parameters of the function to be the array and the size and that the return value for no valid value was -999.
I came up with t... | You need to store the lowest number found so far somewhere. With your function you're using the stack
to store that.
With a tail recursive function you'll need to store the lowest number found so far elsewhere.
e.g:
As a global variable (ugh..).
As a parameter to the function itself.
As a member variable
The requi... |
4,138,410 | 4,138,491 | C++ --- how to write the correct code to release the allocated memory for this example? | Based on this http://sourcemaking.com/design_patterns/command/cpp/1,
I think the posted code has memory leak b/c the allocated memory stored in the array is never released. I made one modification as follows,
#include "stdafx.h"
#include <iostream>
using namespace std;
class Giant
{
public:
Giant()
{
m... |
I think my code only release the memory allocated by new command. Is this correct?
Yes it is correct. But...
Why would you even bother allocating those on the heap? Just create them on the stack, and pass pointers in where needed. Then you will have zero chance of forgetting to deallocate them.
Giant giant;
std::... |
4,138,540 | 4,138,576 | How to interpret custom scripting language? | I was wondering what the easiest way to parse/interpret a custom language would be. Are there any libraries that could help me out?
I essentially want the end-user to be able to write scripts using a custom syntax that I design (the syntax will probably be similar to c++) and I would need my C++ protogram to interpret ... | There are numerous frameworks to help, but remember that language design is not to be taken lightly - are you sure you're not better off just using Lua?
Boost-Spirit
ANTLR (in Java, but produces code for other languages)
Flex, Bison, Lemon
|
4,138,660 | 4,138,665 | in c++ how do I return an array of objects from a function? | in c++ how do I return an array of objects from a function?
| By returning a std::vector.
|
4,139,049 | 4,139,100 | Initialization of a three dimensional static const array | I have a three dimensional static const array that is acting as a lookup table. Each cell of the array can return up to 8 separate numbers (each number is the corner of a cube - a voxel to be exact). So for example, MyStaticArray[0][1][1] might return 1,2,5,7. It can return a single number or a maximum of eight numbers... | You could pad each element up to the maximum length with dummy elements, and go with a 4D array:
static const unsigned char x[M][N][P][8] = { { 1, 2, 5, 7, -1, -1, -1, -1 },
{ 1, 2, 3, 4, 5, 6, 7, 8 },
...
or you could use in... |
4,139,130 | 4,139,471 | Move a range of elements between containers? | I've been looking at the C++ documentation for a function which would move a range of elements from one container to another, using move semantics. However, I have not found such a function. What am I missing?
How would I do the following without copying and using explicit loops?
// Move 10 elements from beginning of s... | I think you're looking for std::move in <algorithm>:
std::move(source.begin(), source.begin() + 10,
std::insert_iterator(dest, dest.end()));
It's just like std::copy, except it move-assigns instead of copy-assigns.
|
4,139,448 | 4,149,795 | Dumping Useful Data to Console on Caught Exception | I have a CExceptionHandler class that is invoked whenever my application detects a run-time exception. For example:
if ( val == NULL )
{
TRACE(_T("Unexpected NULL in sequence."));
AfxThrowException( ERROR_INVALID_DATA );
}
AfxThrowException is very simple:
void AfxThrowException( DWORD error )
{
CExceptio... | CDumpContext sends output to the debugger, not to the console (see OutputDebugString for more information), and if you run under the Visual Studio debugger, the output will appear in the Output window.
If you want to also send output to the console, you can configure CDumpContext to write to a CFile by passing a pointe... |
4,139,456 | 4,139,567 | How to reuse a .Net assembly from a pure C application | I have a legacy application written in C , and i would like to gradually move some code to c#. But before being able to rewrite everything i will need to have just few components writen in c# first that are going to be used from C.
| I assume your C# class is a static class. You need to create an interop layer in C++/CLI before you can use it in pure C. Create a C++/CLI class to wrap your C# class. Once that is done use the export function to export the specific C functions. C++/CLI will manage the interop on your behalf. The rule of thumb is if yo... |
4,139,576 | 4,139,756 | C++ Allocated Memory Problem | It has been a long time since I have programmed in C++, but I recently wrote a little C++ function and am having a little bit of trouble. The function returns a struct, Result, that have some strings in it. I thought I allocated memory for the strings, but jsonResult is sometimes partially overwritten.
//The struct... | I'd put money on your problem being in here:
jsonResult = interp.ResultData().Print(SI_FORMAT_ECMA);
Who 'owns' the char* array returned by Print()? Maybe it's attempting to return a pointer to memory that's out of scope???
example:
char* badFunction(void)
{
char test[100];
strcpy(test,"This is really cl... |
4,139,710 | 4,139,730 | Splitting range into sub-ranges | I have a container std::vector and I would like to efficiently split it into sub-ranges with x items in each. The original container is not needed so the items should be moved and not copied into the sub-ranges.
I've managed to do the splitting using copying, however I'm unsure how to do it with move assignments?
r... | You can use std::make_move_iterator in <iterator> to wrap your iterator into a move_iterator. This iterator will std::move the result of dereferencing its base iterator, allowing that to be moved elsewhere.
// assuming I understand your code, which I don't
range.insert(range.end(), new_items.begin(), new_items.end());
... |
4,139,917 | 4,140,005 | Checking if Linked List is palindromic | Consider a linked list whose nodes are chars, so the list represents a string. How do you write a recursive routine to check whether the string is a palindrome such that
the the said function starts unwinding the stack when it processes the character(s) at the middle of the string?
For example, suppose that my string i... | If you do feel like using a stack, this is a common exercise in computation theory using nondeterministic pushdown automata. The idea is to push every char onto the stack and at each char, branch off, with one branch skipping a char (in case it's an odd palindrome) and popping each char off the stack while comparing i... |
4,140,127 | 4,140,205 | Simple Building for a C++ Hello World | So I am trying to learn C++ while going through the Facebook Puzzles.
To test if submittals to the Puzzle Master are working properly, the meepmeep program can be used.
The input file will contain ASCII text that is going to be completely ignored by your program. In fact, do not even bother opening up the file, it wil... | You're using gcc version 4.2.1. The Facebook puzzle page you linked to explicitly states in its Submission directions that it only accepts gcc 4.2.3.
Darwin is a *NIX environment, so that's not the problem, but you should definitely upgrade your compiler, because the support libraries won't be the same and your program... |
4,140,202 | 4,140,240 | Template specialization for destructor | I'm building a hashmap class that can have string keys and ints, bools, strings or pointers of different types as its values, and I want it to work. For the program I'm using it for I create the pointer and pass it into the hashmap. The problem comes when I need to destruct the map. If the type for the hashmap is a poi... | Your container should handle values. That's it, no more, no less. If someone wants to stick pointers in, let them. Don't take ownership of whatever they may or may not be pointing at.
It's up to the users of your hash map to know how to manage the lifetime of their memory. They should be using smart pointers, so your c... |
4,140,207 | 4,140,381 | Qt/C++ Exited with code -1073741819 (Program crashes with exception code c0000005) | I'm having trouble with my program crashing. I get that "Program.exe has stopped working" windows pop-up which mentions my exception code is c0000005. When I return to the output from the application in Qt, it shows:
C:\Users\Me\Desktop\project\project-build-desktop\debug\project.exe exited with code -1073741819
I've ... | The faulting line:
db=newDb;
And you say:
and db is a private member of wndChild
It sounds like your this pointer might be invalid. That is, if this happens in a method foo you are doing something like wndChild->foo() and wndChild is an invalid pointer. Therefore when it access the offset of db relative to wndChild ... |
4,140,307 | 4,140,344 | C++ Agent : Base class undefined error in Game | I have 6 C++ header files. There are a lot of includes so I tried to make it so that I use as little as I can. But I keep getting an error from the very beginning saying that a class "Agent" is undefined. I defined it and included it and can't find the problem here are the 2 header files that are causing the problem... | It looks like something is referring to class Agent before it is defined, i.e. probably in aStar.h.
EDIT: Search for #define AGENT_H everywhere in your source. If you find it anywhere outside Agent.h, that means the Agent class might never be defined, if only because Agent.h can be #included with AGENT_H already #defin... |
4,140,329 | 4,141,708 | binary object file changing in each build | When compiling using G++ GNU compiler every time I do a build, without changing source code I get a different binary object file. Is there a compile option that will give me the same binary each time.
| Copied from the GCC man-page:
-frandom-seed=string
This option provides a seed that GCC uses when it would otherwise
use random numbers. It is
used to generate certain symbol names that have to be different
in every compiled file. It
is also used to place unique stamps in coverage data files
and the obje... |
4,140,445 | 4,170,549 | Link QT 32Bit libraries with 64 Bit Application (MinGW64 compiler )? | Greetings all,
In my application I need to allocate memory beyong 4GB memory-address-space.So I need compile my application in 64Bit.
My development environment is QT 32 bit libraries(LGPL),and going to use MinGW64 to compile 64bit build.
Since QT doesnt support MinGW64 (only 32bit supported) , can I link 32Bit QT libr... | @umanga
My reply does not answer your question, but it might give you detail on what you actually want to do--building Qt 64-bit libraries using MinGW-w64.
As suggested by MSalters, porting Qt to the 64-bit environment may be simpler. Also, Qt 4.7 is 99.99% compatible with current MinGW-w64. I just tried building Qt ... |
4,140,455 | 4,140,595 | Qt Jambi and threads | I'm trying to create a Qt widget in C++ as a child of a Jambi widget. Passing the parent's native pointer into a JNI method seems to be the straightforward approach, but Qt complains about creating the widget on a different thread than the parent.
Does JNI run methods on a different thread than the Java code? Or is Jam... | Quit writing your own JNI, use The Qt Jambi Generator to generate stub for your C++ Widget and do all your code in java.
|
4,140,504 | 4,140,520 | Linux Global Includes Path | I am trying to use OpenBabel and am experiencing great difficulty with setting up a global search path for include files. I have successfully linked to the libraries with $LD_LIBRARY_PATH, but when compiling with the GNU C++ compiler, it cannot find the include files. Is there a global include environment variable on L... | You could give the include path to GCC using the option -I:
g++ -I/path/to/the/include/dir blabla
Please note that also the library dir may be bassed via -L option -L/path/to/lib/dir. LD_LIBRARY_PATH is usually considered a dirty hack.
You can have multiple -I (and -L) options:
g++ -I/dir/include1 -I/dir/include2
|
4,140,732 | 4,140,987 | Looking for an accurate way to micro benchmark small code paths written in C++ and running on Linux/OSX | I'm looking to do some very basic micro benchmarking of small code paths, such as tight loops, that I've written in C++. I'm running on Linux and OSX, and using GCC. What facilities are there for sub millisecond accuracy? I am thinking a simple test of running the code path many times (several tens of millions?) will g... | You can use "rdtsc" processor instruction on x86/x86_64. For multicore systems check the "constant_tsc" capability in CPUID (/proc/cpuinfo in linux) - it will mean that all cores use the same tick counter, even with dynamic freq changing and sleeping.
If your processor does not support constant_tsc, be sure to bind you... |
4,140,739 | 4,140,882 | VC2005 got slower after installing VC2008 | I have installed VS2008 SP1 and now when I compiled solution (a mix of C++ and managed C++ projects) it takes much more time to embed the manifest into .dll.
Is it a known issue? Any workarounds/directions please.
| This is not a known issue. Time to defrag your hard drive.
|
4,140,803 | 4,140,855 | GlobalAlloc explanation | (char*)GlobalAlloc(GPTR, len + 1);
This is the line of code in question, which I'm using from a tutorial. I'm reading from an EDITTEXT. I'd mostly like to know where GPTR came from, and what it's for. It hasn't been defined anywhere else in the code.
I've got a basic understanding of the rest of the line, but MSDN'... | Refer here
GPTR 0x0040 Combines GMEM_FIXED and GMEM_ZEROINIT.
As you can see, it is just a bit pattern (0x0040) and can be combined with other permissible flags
|
4,140,877 | 4,140,898 | Problem with vector<T>.erase() with g++ | The following code builds error free on msvc, but does not compile on g++.
if(*it == listener){
it = listeners.erase(it);
}
The error is in erase,
The full code is:
void AguiListener::removeListener( AguiWidget* listener )
{
for(std::vector<AguiWidget*>::const_iterator it = listeners.b... | In the current C++ standard (C++03), std::vector::erase takes an iterator, not a const_iterator.
In the forthcoming C++ standard (C++0x), std::vector::erase takes a const_iterator. The Visual C++ Standard Library implementation already supports this (at least it does in the latest version, Visual C++ 2010).
|
4,141,034 | 4,141,066 | weird end of program error | im getting a weird error in my program. my compiler is telling me :
expected `}' at end of input
expected unqualified-id at end of input
expected `,' or `;' at end of input
and its highlighting the last line of my code, which is the closing bracket for my main() function. i have commented out all of the code in in... | You probably forgot the semicolon after the closing brace on a class or structure definition.
class C
{
} // <<-- HERE, semicolon needed
One of the other things that can appear there is a variable declaration:
class C
{
} c; // <<-- creates a global variable of type "class C"
Since a variable name is an unqualified-i... |
4,141,044 | 4,141,110 | Which is better: Function overriding or passing a function pointer for event handling | So, I'm writing code for a class that will go into a library that will be used by others. This class will intercept and process incoming messages (details are not important but it's using the activemq-cpp library). The outline of this consumer class is
class MessageConsumer {
...
public:
void runConsume... | In one approach, clients are allowed to register a callback and then the MessageConsumer invokes the registered callback. This is something like an observer/broadcast design pattern.
The second approach, where clients have to inherit and override MessageConsumer would be something like Strategy design pattern.
Basic de... |
4,141,078 | 4,141,091 | Any better alternatives for getting the digits of a number? (C++) | I know that you can get the digits of a number using modulus and division. The following is how I've done it in the past: (Psuedocode so as to make students reading this do some work for their homework assignment):
int pointer getDigits(int number)
initialize int pointer to array of some size
initialize int i ... | The time it takes to extract the digits will be dwarfed by the time required to dynamically allocate the array. Consider returning the result in a struct:
struct extracted_digits
{
int number_of_digits;
char digits[12];
};
You'll want to pick a suitable value for the maximum number of digits (12 here, which i... |
4,141,278 | 4,142,094 | C++ const lvalue references | Assuming I have:
class A which is non-copyable
class B which has as a member, const A& a (and takes an A in its constructer and sets it in its initialization list)
a function A GenerateA();
Does this mean that it should be valid to do:
B(GenerateA())
?
i.e, does the const ref mean that no copy of the A that generateA... | As it has already been stated by others, A GenerateA() cannot compile if A is not copyable.
Regarding the const ref : no, the lifetime of the temporary will not be extended to the lifetime of B. The standard [12.2.5] states :
A temporary bound to a reference member in a constructor's ctor-initializer (12.6.2) persists... |
4,141,307 | 4,141,345 | C and C++ source code profiling tools |
Possible Duplicate:
What's your favorite profiling tool (for C++)
Are there any good tools to profile a source code which is mix of of C and C++. What are the pros and cons of any, and which ones have you used and would reccomend for usage. Please do not get me a list of tools from google. I can do that too, what i ... | I've found gprof to be the best CPU hotspot profiler, and Google Performance Tools to be the best sampling profiler. Both work for C and C++.
In my opinion there are no good profiling tools on Windows.
GNU gprof pros and cons
GCC only
Works with C and C++
Only treats CPU time, and code inside the binary, you need ever... |
4,141,312 | 4,471,362 | How to Link Imagemagick library to Qt(windows) | I have developed an application with mac and for one month now, Im trying to link Qt with ImageMagick on windows.
I just cant find the files and the version of Imagemagick library that need to be linked to Qt in order to make my application work on windows.
I have tried most of the libraries from here
Thats the only th... | I have found that the minGW tool set is very much treated as a "stepchild" in the Windows world. I know it doesn't help your particular situation, but we had numerous problems with third-party libs while trying to use Qt with minGW. There were always extra steps, or non-existent build instructions that we had to figure... |
4,141,322 | 4,141,349 | is 'giving out' a reference to 'this' inside the constructor ok? | my code :
Scene::Scene(const std::string &scene_file) : ambient_light(0, 0, 0), background(0, 0, 0){
scene_parser parser(*this);
parser.parse(scene_file);
}
scene_parser is a friend of Scene, and in the parse method it accesses(r/w) the members of Scene. Is this going to cause any problems?
| In your particular example, no problems should arise.
Generally the problem with giving out this references is that the lifetimes of the two objects don't exactly align and the other object could try to access the referred-to object after it has already been destroyed.
In your example, the scene_parser object is on the... |
4,141,511 | 4,141,518 | What are the SCons alternatives? | I have projects in C++, Java and Python. Projects in C++ export SWIG interfaces so they can be used by Java and Python projects.
My question is: what building mechanism can I use to manage dependencies and build these projects?
I have used SCons and GYP. They are fairly easy to use and allow plugins (code-generators, c... | One promising alternative is waf:
https://waf.io/
Others:
http://code.google.com/p/fabricate/
Not exactly but very relevant:
http://www.buildout.org/docs/index.html
|
4,141,715 | 4,141,910 | checking input using a do-while loop with c, c++ | Hello i'm trying to use a do-while loop to check the input and repeat the prompt until the user types in a correct integer. So that's my code:
#include <iostream>
#include <stdio.h>
#include <ctype.h>
int main ()
{
int a;
do
{
printf("Please type in your number: ");
}while(scanf_s("%d", &a) == 0);
... | Here's what's going on -- I'll go through step by step. Starting from the do:
output: Please type in your number:
call to scanf Scanf finds that stdin is empty, and therefore waits for a line to be typed in.
input : letter (note that the input buffer now contains "letter")
scanf attempts to parse the string as an int... |
4,141,796 | 4,141,819 | C++ CString equivalent in C# | What is the C# equivalent for MFC's CString?
| Probably System.String. But in an effort to provide more useful information:
System.String instances are immutable. Concatenation/substring/etc actually create new string objects, so using a string instance as a buffer for building up output is a really bad idea, in case you were going to do that. Think of System.S... |
4,141,848 | 4,141,873 | What does it means if I declare function pointer in c++ | What does it means when I in my code declare something like :
Foo * foo();
What benefits it gives me ?
Ist not simple pointer variable as you see .
Also
What does it mean if I declare it in the c++ source above all methods for example :
// Test cpp class
.
#include "Foo.h"
Foo * foo();
Test::Test() {}... | Foo * foo(); is a declaration to a function named foo which returns a pointer to a Foo object. It is not a function pointer.
The code Foo()->someMethod(); is probably a typo. You probably meant foo()->someMethod();. In this case, the code calls foo() which as stated above returns a pointer to a Foo object, and then... |
4,141,875 | 4,143,887 | Tool for model checking large, distributed C++ projects such as KDE? | Is there a tool which can handle model checking large, real-world, mostly-C++, distributed systems, such as KDE?
(KDE is a distributed system in the sense that it uses IPC, although typically all of the processes are on the same machine. Yes, by the way, this is a valid usage of "distributed system" - check Wikipedia.)... | You're obviously looking for a static analysis tool that can
parse C++ on scale
locate code fragments of interest
extract a model
pass that model to a model checker
report that result to you
A significant problem is that everybody has a different idea about what model they'd like to check.
That alone likely kills yo... |
4,141,876 | 4,141,901 | Stack object doesn't get recognized by Qt but heap object does | I have difficulties understanding a problem I encountered during instantiation of a QT class but I have the feeling that it might be general oop thing. The problem was that it only worked after I used a pointer to the object but didn't work with just the object variable itself.
In main() I create an instance of a widge... | Because in C++, stack variables are automatically destructed when they go out of scope. In your case, boardView will be destructed when the Board constructor returns, so the test picture doesn't show at all (since boardView doesn't exist anymore).
On the other hand, the lifetime of heap-allocated objects are not bound ... |
4,142,347 | 4,142,369 | Vim: source code formatting | Take a look at the enum:
enum TestEnum
{
First = 1,
Second = 2,
Unknown = 3,
TestTestTest = 100,
Zero = 0,
Foo = 123,
}
How can I use the whole power of Vim to reformat it?
enum TestEnum
{
First = 1,
Second = 2,
Unknown = 3,
TestTestTest = 100,
... | You can harvest from two plug-ins that can do this stuff:
Align.vim
, or
Tabular.vim
|
4,142,395 | 4,145,179 | How can I catch QTreeView deselected event? | How can I catch QTreeView deselected event?Is there in QT this type event? Thanks
| QAbstractItemView::selectionModel() will return a pointer to the selection model of the view. That model fires a signal whenever the selection is changed, whether it's selected or deselected.
Connect the QItemSelectionModel::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected) signal to ... |
4,142,453 | 4,142,487 | a problem with Pointer to Pointer(AnyType **var) in C++ | As you know there is a generic class List in .NET framework.
I want to write a generic class List in C++ and i want to store pointers to a type in my list. this is header and source code of class and test program :
// header
template <class Type>
class List
{
public:
List(int size); // constructor
.
.
.... | this->list = new Type[size]; should be this->list = new Type*[size];
Edit: did it actually compile? The assignment should at least generate a warning.
|
4,142,498 | 4,142,548 | Delphi DLL to enhance C++ Project | I have inherited an old C++ (MFC) project and will have to add new functionality.
The new functionality will mostly not conflict with the existing C++ code, like additional dialogs etc.
Having limited experience with C++ MFC, I would very much prefer to do the additional functionality in Delphi, create a DLL and use th... | Delhi if I recall my history should create Dll's happily. See here 'Calling delphi DLL from MS Visual C++' for an example
|
4,142,562 | 4,142,580 | What's the advantage of making methods public in an interface, but protected in the implementation? | In my C++ application I have an interface that looks like this:
class ICalculator
{
public:
virtual double calculateValue(double d) = 0;
};
I have implementations of this interface that look like this:
class MySpecificCalculator
{
public:
virtual double calculateValue(double d);
};
Now m... | Your colleague is right.
Never make virtual functions public.
Guideline #1: Prefer to make
interfaces nonvirtual, using Template
Method.
Guideline #2: Prefer to
make virtual functions private.
Guideline #3: Only if derived classes
need to invoke the base implementation
of a virtual function, make the... |
4,142,697 | 4,142,741 | C++ strings, when to use what? | It's been quite some time now that I've been coding in C++ and I think most who actually code in C++, would agree that one of the most trickiest decisions is to choose from an almost dizzying number of string types available. I mostly prefer ATL Cstring for its ease of use and features, but would like a comparative stu... | Don't mean to put a dampener on your enthusiasm for this, but realistically it's inefficient to mix a lot of string types in the one project, so the larger the project gets the more inevitably it should settle on std::string (which is a typedef to an instantiation of STL's basic_string for type char, not a different en... |
4,142,743 | 4,143,215 | How to output in buffer console output? | How to output in buffer console output? For example I just need output of command "ipconfig -all", and want to store that information in some buffer?
| It seems you have an XY problem
What you really want to do is capture the output of another command. The whole "buffer" part is your first stab at an answer. It doesn't help you, and in fact it got you stuck thikning in the wrong direction.
badgerr offers some solutions, but the most common solution is popen("ifconfig ... |
4,143,010 | 4,143,065 | How do you use PHP to interact with a running C++ process? | Is it possible to have a C++ program running on a server that sits and waits to be passed arguments by a PHP process.
The C++ program would then process these arguments and return a result to PHP.
I’ve been searching the web and can see a couple of ways to run a C++ program from PHP but can’t find a way to interact wi... | Use named pipes.
https://web.archive.org/web/20140223054156/http://my.opera.com/zomg/blog/2007/08/29/php-and-named-pipes
and
C++ https://web.archive.org/web/20110926155246/http://ist.marshall.edu/ist480acp/namedpipes.html
|
4,143,256 | 4,144,216 | Finding the angles for the X, Y and Z axis in 3D - OpenGL/C++ | I am currently trying to use OpenGL (With SDL) to draw a cube to the location where I left click in the screen and then get it to point at the position in the screen where I right click.
I can successfully draw a cube at my desired location using gluUnproject - Meaning I already know the coordinates of which my cube is... | If your cube is at A = (x0,y0,z0)
If your cube is currently looking at B=(x1,y1,z1)
and if you want it to look at C=(x2,y2,z2) then;
let v1 be the vector from A to B
v1 = B - A
and v2 be the one from A to C
v2 = C - A
First normalize them.
v1 = v1 / |v1|
v2 = v2 / |v2|
then calculate the rotation angle and the rotatio... |
4,143,382 | 4,143,405 | How to check deallocation of memory | How to check if memory to which pointer p points has been succesfully deallocated?
| In few words: you can't.
Check out tools like Valgrind to help you debugging memory leaks issues.
Some other things you should consider:
Use smart pointers so that you don't have do think about memory management,
Set your pointers to 0 after you free them, so that a further delete has no effect,
Use standard classes (... |
4,143,416 | 4,143,604 | Newline character in Text Document? | I wrote a pretty simple function that reads in possible player names and stores them in a map for later use. Basically in the file, each line is a new possible player name, but for some reason it seems like all but the last name has some invisible new line character after it. My print out is showing it like this...
nam... | ReadLine clearly includes the newline in the data it returns. Simply check for and remove it:
char *nameLine = filesystem->ReadLine(line, size, file);
// remove any newline...
if (const char* p_nl = strchr(nameLine, '\n'))
*p_nl = '\0';
(What this does is overwrite the newline character with a new NUL terminator... |
4,143,483 | 4,143,653 | Can I create automatic Unit Tests for C++ |
When I create a program using C# and VS2008 , then I can create a test case just by Rightclicking on the method. But I am not sure If I can create the tests in the same way if it is a C++ project.
| Due to the lack of reflection in C++, you propably wont be able to have these kind of unit tests, VS provides.
|
4,143,575 | 4,144,752 | Expressions with no side effects in C++ | See, what I don't get is, why should programs like the following be legal?
int main()
{
static const int i = 0;
i < i > i;
}
I mean, surely, nobody actually has any current programs that have expressions with no side effects in them, since that would be very pointless, and it would make parsing & compiling th... |
it would make parsing & compiling the
language much easier
I don't see how. Why is it easier to parse and compile i < i > i if you're required to issue a diagnostic, than it is to parse it if you're allowed to do anything you damn well please provided that the emitted code has no side-effects?
The Java compiler for... |
4,143,644 | 4,143,700 | C++ 64 bit int: pass by reference or pass by value | This is an efficiency question about 64 bit ints. Assuming I don't need to modify the value of a "int" parameter, should I pass it by value or reference.
Assuming 32 bit machine:
1) 32 bit int: I guess the answer is "pass by value" as "pass by reference" will have overhead of extra memory lookup.
2) 64 bit int: If... | Pass by value - definitely. If the system is 64-bit it means it copies 64-bit word extremely fast.
|
4,143,701 | 4,143,942 | How to create object required for the class constructor in inversion of control? | I am programming in c++ using TDD, which suggests to use inversion of control when creating objects (when creating objects of certain class, pass constructed objects to it's constructor). This is fine, but how do I create objects required for the constructor?
Right now, I am using a factory (which I can easy change for... | Use the Builder design pattern. Builder and Factory are very similar design patterns, but specifically Builder creates an object made of multiple components by first building its components.
That is what you do in IOC. You build the components then pass them as parameters to the object.
When I created this model (4 tim... |
4,143,823 | 4,144,082 | Add delay to raw data before send it? | I want to know how can I add a delay (ex:200ms) to some received raw data before send it again through the network.
Is it possible to use memory to store bits(8000) in memory before send it.
| Yes, but it is really beyond the scope of this site to give you a full implementation. However here are some tips
Storing memory is basic enough. To store 8000 bits you could use std::bitset or you could manually implement it, no doubt in 1000 bytes on a regular 8 bits-per-byte system. If you need to send it across a n... |
4,143,946 | 4,144,086 | How is a situation when different implementations of an inline function are linked into one executable classified? | According to One Definition Rule (ODR) I can't have a function
void function()
{
}
defined more than once in one executable - linker will object. However ODR is ignored for inline functions:
inline void function()
{
}
can be defined in a header file that will be #included into multiple .cpp files and so when resultin... | Yes, it is UB for inline functions with external linkage (I think that's what the OP intends).
$3.2/5-
There can be more than one definition
of a class type (clause 9),
enumeration type (7.2), inline
function with external linkage
(7.1.2), class template (clause 14),
non-static function template (14.5.5),
... |
4,144,030 | 4,144,644 | Why calling main() is not allowed in C++ | C++03 3.6.1.3: The function main shall not be used (3.2) within a program. ...
I wonder why this rule exists... Is anyone aware of any system/implementation where it would be a problem if main were used?
P.S. 1. I know the definition of the term used. 2. I know there are simple workarounds like calling a single MyMai... | In addition to the other answers: The c++ spec guarantees that all static initialization has happened before main is called.
If code could call main then some static scoped object could call main, in which case a fundamental guarantee is violated.
The spec can't say "static scoped objects should not call main()" becaus... |
4,144,033 | 4,144,761 | FFmpeg: How to put encoded media data from one container to another with out re-encoding? | So for example: I have file.mp3, I know that my desired format can play sound with out video (for example FLV) so how to put encoded mp3 data using ffmpeg from mp3 container into flv (where to get articles/code samples on this)?
I mean not from cmd but from C++ using ffmpeg as library. (see tags)
| Here is the command to convert .mp3 file to .flv(which does not have any video data).
ffmpeg -i test.mp3 -ab 32k -acodec libmp3lame -ac 1 -ar 44100 audio.flv.
You can execute this command from your program.
If you need help on how to install and use ffmpeg you can go to their site:
http://ffmpeg.org
Thanks,
Mahmud
|
4,144,038 | 4,144,334 | C++ Exception Handling | Can somebody refer me reference book for in depth understanding of C and C++ exception handling mechanisms.
| Exceptions
From Herb Sutter's Guru of the Week
And the usual culprits More Effective C++ by Scott Myers
C++ Coding Standards: 101 Rules, Guidelines, and Best Practices By Herb Sutter, Andrei Alexandrescu
|
4,144,234 | 4,144,544 | C++ - template instantiation with reference type | I've heard a little bit about reference-to-reference problem and this resolution. I'm not very good with C++ Committee terminology, but I understand the "Moved to DR" annotation in the link means that this is the current interpretation that standard-conforming compilers should adhere to.
I have this sample code that I ... | DR only means "Defect Report", and to my knowledge, the described resolution hasn't made it (yet) to the standard. For this reason, I believe a strictly conforming C++03 implementation should not compile this code because of it is forming a reference to a reference.
[Edit] Just found a nice answer on this issue.
|
4,144,477 | 4,145,231 | Problem linking c++ code using boost with mingw | I'm trying to port/build some of my code written for gcc (on linux) as a dll on windows. First I tried to build in under VC++ but there were so many errors/warnings (mainly in VC's own include files, which didn't really make much sense to me :)) so I installed MinGW distro (which includes Boost libraries). Compilation ... | Ok, I found the answer. Looks like the problem is in boost libraries being static in MinGW-distro. Normally they are configured to be linked dynamically and that caused above issue. This answer explains it...
|
4,144,525 | 4,144,626 | Storing a generic value and its type in C++: merge type+value in one class or separating them? | If have a union that currently foresees some simple data types:
union Value
{
const char *str;
double d;
long l;
short s;
bool b;
void *reference;
};
The union also allows more complex data types to be stored (like enumerations, references to instances, ...), but all data is stored in one of th... | You should use a boost::variant or boost::any. That's what they're for. Using them doesn't mean that you have to template your entire solution. Moreover, if you don't need dynamic, run-time variance between types, then that IS what templates are for. The right tool for the right job - and this is templates for static v... |
4,144,600 | 4,171,211 | SuspendThread WOW64 suspending in kernel code | UPDATE: Microsoft have yet to fix it in Windows 8.1.
EDIT: This turned out to be a bug in WOW64 - GetThreadContext() may return stale contents when the thread is suspended in long mode ring-3 (user mode). I've suggested to Microsoft to use ring-2 to perform the translation. SuspendThread would then only suspend thread ... | I've confirmed that this is an OS issue returning stale contents when GetThreadContext is called under WOW64.
More info here.
Thanks to everyone who attempted to answer this question. I'm working with MS to resolve this.
|
4,144,690 | 4,144,757 | Win32, wait for thread in main msg queue? | I created a thread in WinMain, and after that I have a classic msg loop:
while(GetMessage(&msg, NULL, 0, 0))
{
if (!done){
GetExitCodeThread(dThread,&dwCode);
if (dwCode!=STILL_ACTIVE){
//thread done
}
}
if (!IsDialogMessage (UWnd, & msg))
{
TranslateMessage ( ... | Instead of testing the thread status inside the message loop, you could have the thread post a message to your UI thread (using PostThreadMessage) when it completes. Then all you would need to do is handle that message in your WindowProc.
|
4,144,821 | 4,144,971 | Problem with return type | I have a classes:
struct Policy_1
{
void signalFailure()
{
throw std::exception();
}
};
struct Policy_2
{
void* signalFailure()
{
return nullptr;
}
};
template<class Policy>
struct My
{
template<cla... | I see that you're using nullptr- which means that you must be in C++0x. In this case it is trivial to use decltype to solve this problem.
template<class Policy>
struct My
{
template<typename T> struct func_helper {
static T func() { return Policy::signalFailure(); }
};
template<> struct func_he... |
4,144,822 | 4,144,884 | std::copy and std::vector problem | I understand why this causes a segfault:
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
int iArr[5] = {1, 2, 3, 4, 5};
int *p = iArr;
copy(p, p+5, v.begin());
return 0;
}
But why does this not cause a segfault?
#include <algorithm>
#include <vector>
using... | This is undefined behavior - reserve() allocates a buffer for at least one element and the element is left uninitialized.
So either the buffer is big enough and so you technically can access elements beyond the first one or it is not big enough and you just happen to not observe any problems.
The bottom line is - don't... |
4,144,826 | 4,144,842 | Convert boost::shared_ptr to actual class | How would someone do that?
for example:
Client* client = it->second;
where it->second is a boost::shared_ptr to Client
error:
cannot convert `const ClientPtr' to `Client*' in initialization
| boost::shared_ptr has a .get() method to retrieve the raw pointer.
Documentation here about when and why not to use it: http://www.boost.org/doc/libs/1_44_0/libs/smart_ptr/shared_ptr.htm
|
4,145,226 | 4,145,404 | Trying to make a DLL of my lib and getting unresolved external symbol __tmainCRTStartup | I have added my declspecs to my classes and all. I basically created a new DLL project and added all of my lib's files. It builds fine except for that unresolved external symbol. Why would I need a main for a DLL?
The error is:
Error 84 error LNK2019: unresolved
external symbol main referenced in
function
__tma... | There is a DLLMain function (check the reference for it on MSDN) which you might have to provide. In addition, you may have just set the project settings wrong and the linker may be expecting to create an exe.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.