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 |
|---|---|---|---|---|
3,159,395 | 3,159,629 | Why symbols of a shared library are not resolved at link time? | This is my 2nd post on this site in my effort to understand the compilation/linking process with gcc. When I try to make an executable, symbols need to be resolved at link time, but when I try to make a shared library, symbols are not resolved at link time of this library. They will perhaps be resolved when I am trying... | Does adding -z defs when building the library do what you want? If not, check the ld man pages, there are quite a few options on the handling of undefined symbols.
|
3,159,396 | 3,159,539 | is there a good way to combine stream manipulators? | If I wanted to output a fixed width hex number with 4 digits on a stream, I would need to do something like this:
cout << "0x" << hex << setw(4) << setfill('0') << 0xABC;
which seems a bit long winded. Using a macro helps:
#define HEX(n) "0x" << hex << setw(n) << setfill('0')
cout << HEX(4) << 0xABC;
Is there a bet... | Avoid the macros when you can! They hide code, making things hard to debug, don't respect scope, etc.
You can use a simple function as KenE provided. If you want to get all fancy and flexible, then you can write your own manipulator:
#include <iostream>
#include <iomanip>
using namespace std;
ostream& hex4(ostream& ou... |
3,159,470 | 3,159,504 | cin.get() is not getting out of loop | I am using the following code:
#include <stdio.h>
#include <iostream>
using namespace std;
int main ()
{
char c ;
c = cin.get() ;
do {
cout.put(c) ;
c = cin.get() ;
} while ( !cin.eof()) ;
cout << "coming out!" << endl;
return 0;
}
Problem with the above code is, its not gett... | Standard in never hits EOF, unless you press Ctrl+Z.
Therefore, cin.eof() is always false.
To fix it, press Ctrl+Z to send an End-Of-File character.
Alternatively, you could change the condition. (eg, while(c != '\n'))
|
3,159,754 | 3,159,784 | Sort C++ Strings with multiple criteria | I need to sort a C++ std::vector<std::string> fileNames. The fileNames are labeled as such
YYDDDTTTT_Z_SITE
YY = Year (i.e 2009 = 09, 2010 = 10)
DDD = Day of the year (i.e 1 January = 001, 31 December = 365)
TTTT = Time of the day (i.e midnight = 0000, noon = 1200)
ZONE = Will be either E or W
SITE = Fou... | Use std::sort with a comparison function.
(The link has a nice example)
|
3,159,936 | 3,159,961 | Calculate Execution TIme using C++, rather than using <time.h> | I need to calculate the execution time of a C++ program. I am currently using the c-style head, <time.h> with the following code:
clock_t tStart = clock();
...
printf("Execution Time: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
Is there a c++ header I can use to calculate execution time? Please note this nee... | You can use the C++ versions of C headers. Add 'c' at the beginning, and remove '.h'
So you need
#include <ctime>
The rest stays the same, as you can just use the C approach.
|
3,160,403 | 3,160,851 | "pure virtual method called" when implementing a boost::thread wrapper interface | I have a small wrapper which centralize what's relative to threads :
class Thread {
protected:
boost::thread *m_thread;
virtual void work() = 0;
void do_work() {
work();
}
public:
Thread() : m_thread(NULL) {}
virtual ~Thread() {
catch_up();
delete m_thread;
}
... | Your crash happens only when your program exits immediately: it calls class A's destructor which finishes and calls Thread's destructor before the newly started thread had a chance to be scheduled. The thread then calls your virtual function, but class A no longer exists, so it attemps to call Thread's do_work(), which... |
3,160,483 | 3,160,494 | "Bitwise And" and Left-Padding in C++ | I have a macro that looks something like this:
Foo(x) ((x - '!') & 070)
If I call the following code:
Foo('1') => 16
However, if I call the following code:
(('1' - '!') & 70) => 0
So my question is, what's going on here? Why does x & 070 compute to x but x & 70 compute to 0?
My guess is that the extra 0 on the left ... | In C++, a constant with a leading 0 is an octal constant, not a decimal constant. It is still an integer constant but 070 == 56.
This is the cause of the difference in behaviour.
|
3,160,491 | 3,160,569 | iPhone Radio program with VU Meter | I wrote an iPhone app that plays wma stream, using libmms and ffmpeg open source libraries. The app has already been approved by Apple and is available for download, free of charge.
Now I'd like to have a VU meter on my app.
I'm using the avTouch code sample, downloaded from Apple (https://developer.apple.com/iphone/li... | To use Objective-C++ you will need to (the simplest way) ensure your source file name ends in ".mm" instead of ".m". If the latter, the compiler guesses it's just Objective-C, if the former it assumes Objective-C++. You can explicitly set the compiler flags in the build settings, but why when you can just rename the fi... |
3,160,584 | 3,160,626 | Will GetPath() work for this? | I basically want to get the outline for a character. I was wondering how I could do this without drawing to the DC. Could I do something like this: (Psudocodeishly)
BeginPath()
TextOut("H")
EndPath()
GetPath()
Will something like this work for GetPath? Will it return the glyph outline that I can then draw?
Otherwise, h... | If you want to get a glyph outline, why not just use GetGlyphOutline? There's the theoretical limitation that this is limited to TrueType fonts, but given the percentage of other fonts typically used on Windows, that's rarely a concern...
Edit: Yes, if you want to avoid using GetGlyphOutline, using a path instead will ... |
3,160,653 | 3,160,830 | what could make 32 bit app incompatible with 64 bit linux OS? | It seems that most 32 bit applications will run on 64 bit linux assuming all the 32 bit libraries are present. But it seems to me there could be issues with architecture-dependent functions, and here I'm thinking of signals and setjmp/longjmp. I'm wondering if someone with greater experience could comment on what func... | Even setjmp and longjmp should work correctly. There are no particular issues, from a user space application, which would present any issues. The actual 32bit emulation is done by the processor. System calls are the interface back to the 64bit kernel, which Linux correctly handles.
If the application was evil, and sent... |
3,160,882 | 3,160,962 | This is illegal right? | For a personal project I have been implementing my own libstdc++. Bit by bit, I've been making some nice progress. Usually, I will use examples from http://www.cplusplus.com/reference/ for some basic test cases to make sure that I have the obvious functionality working as expected.
Today I ran into an issue with std::b... | This will appear to work if replace operates in-place. I don't think it's required to be implemented that way though. So yes, I would say your code is technically illegal.
|
3,160,975 | 3,161,128 | VS: Tooltip help for doxygen-style commented functions? | I am using Visual Studio and an external library that is commented in doxygen-style. Is there any way to display doxygen documentation in the editor tooltip like DocXML?
| The VS plugin Visual Assist shows doxygen comments. From what I can see, it doesn't actually process them, but it shows doxygen comments (in their raw form) nevertheless.
There's a trial at their website.
Be warned, though. I have seen very few C++ programmers who tried it for a few days and were not begging their mana... |
3,161,271 | 3,161,284 | Why should I avoid using malloc in c++? |
Possible Duplicates:
What is the difference between new/delete and malloc/free?
In what cases do I use malloc vs new?
Why should I avoid using malloc in c++?
| Because malloc does not call the constructor of newly allocated objects.
Consider:
class Foo
{
public:
Foo() { /* some non-trivial construction process */ }
void Bar() { /* does something on Foo's instance variables */ }
};
// Creates an array big enough to hold 42 Foo instances, then calls the
// constructor ... |
3,161,342 | 3,161,374 | serialize any data type as vector<uint8_t> - use reinterpret_cast? | I didnt find anything directly related in searching, so please forgive if this is a duplicate.
What I am looking to do is serialize data across a network connection. My approach is to convert everything I need to transfer to a std::vector< uint8_t > and on the receiving side unpack the data into the appropriate variabl... | My suggestion is to ignore all the people telling you that reinterpret_cast is bad. They tell you it is bad, because it's generally not a good practice to take the memory map of one type and pretend that it's another type. But in this case, that is exactly what you want to do, as your entire purpose is to transmit the ... |
3,161,392 | 3,163,749 | Different ways of observing data changes | In my application I have many classes. Most of these classes store quite some data, and it is important that other modules in my application are also 'updated' if the content of one of the data classes changes.
The typical way to do this is like this:
void MyDataClass::setMember(double d)
{
m_member = d;
notifyAllObse... | The two methods you've described cover (conceptually) both aspects, however I think you haven't explained sufficiently their pros and cons.
There is one item that you should be aware of, it's the population factor.
Push method is great when there are many notifiers and few observers
Pull method is great when there are... |
3,161,407 | 3,161,444 | Compare and swap library? | What is the best cross platform library to use for atomic compare and swap operations in c++?
...Or at least for amd64 on Linux and Windows?
| It depends on the compiler compatibility you need.
If you are using GCC on both platforms, you can just use GCC's atomic primitives, as they are tied to the hardware architecture, not the OS platform.
Otherwise, as PeterK suggested, look at Boost. There is a Boost.Atomic candidate library; I don't know what its status... |
3,161,435 | 3,161,476 | Communication with running Windows service | How can I communicate with running Windows service without stopping it using native C++? I need to pass integers and strings to service and get integers and to get back integers and strings.
Currently I do it through registry, but I would like use another, faster way.
Thank you in advance.
| A few options:
Communicate via ports
Use RPC
Use the file system
|
3,161,676 | 3,161,703 | Why is it counting the last number twice? | My program is reading numbers from a file- and it reads the last number twice. What is wrong with my program and what can I do to fix it?
int main()
{
ifstream inputFile;
int number = 0; //the input for the numbers in the file
double total = 0; //the total of the numbers
double counter = 0;//number of... | Because the inputFile becomes false1 after an unsuccessful reading attempt has been done, and not when there's just no more data to read. So, when you've read successfully the last element you are inputFile still evaluates to true, and the next iteration of the while is started. Now, at inputFile>>number the failbit is... |
3,161,757 | 3,161,851 | A crash in injected / hooked target application | I have injected my DLL into a target application where I've hooked few WINAPI-functions
as well. One of them is DrawTextExW. I'm trying to replace all 'l' letters to '!' before
it prints it out. My solution works fine for a few seconds, but then the target application crashes. I really don't understand why.
Here's the ... | I see that you ignore cchText, could you be receiving an non-NULL-terminated string with a positive value for cchText, resulting in reading past the end of the string into invalid memory? That error would present as a Win32 exception in the constructor of s_wc, though.
Also, you aren't checking for DT_MODIFYSTRING in ... |
3,161,846 | 3,161,981 | Best practice for a Qt application with multiple UIs in C++ | The case is as follows:
You have a main window (ui1) that is to contain two other UIs (ui2 and ui3). Neither ui2 nor ui3 care about any other uis. They only have slots to react to, and they might emit signals as well. See drawing below.
+----------------------------+
| +------+ +------+ |
| | | | ... | When creating ui1, drag two basic widgets (i.e. QWidget) into the UI. Then, in designer, you can right click and choose Promote To .... Within that dialog specify the "Promoted class name" and the "Header file" that correspond to ui2 and ui3.
You won't be able to see a live preview using this method, but when the heade... |
3,162,030 | 3,162,067 | Difference between angle bracket < > and double quotes " " while including header files in C++? |
Possible Duplicate:
What is the difference between #include <filename> and #include “filename”?
What is the difference between angle bracket < > and double quotes " " while including header files in C++?
I mean which files are supposed to be included using eg: #include <QPushButton> and which files are to be include... | It's compiler dependent. That said, in general using " prioritizes headers in the current working directory over system headers. <> usually is used for system headers. From to the specification (Section 6.10.2):
A preprocessing directive of the form
# include <h-char-sequence> new-line
searches a sequence of im... |
3,162,149 | 3,162,161 | Assuring proper maintenance of Clone() in C++ | In C++, I find it very useful to add a "Clone()" method to classes that are part of hierarchies requiring (especially polymorphic) duplication with a signature like this:
class Foo {
public:
virtual Foo* Clone() const;
};
This may look pretty, but it is very prone to bugs introduced by class maintenance. Whenever any... | Why not just use the copy constructor?
virtual Foo* Clone() const { return new Foo(*this); }
Edit:
Oh wait, is Foo the BASE class, rather than the DERIVED class? Same principle.
virtual Foo* Clone() const { return new MyFavouriteDerived(*this); }
Just ensure that all derived classes implement clone in this way, and y... |
3,162,181 | 3,162,186 | Would making 'this' a reference rather than a pointer be better in retrospect? |
Possible Duplicate:
Why ‘this’ is a pointer and not a reference?
Is there any reason for this in C++ to be a pointer rather than a reference other than historical language decision? It feels a tad strange given that e.g. copy constructor or assignment operators both accept reference to "that", not a pointer.
[I hon... | References didn't exist in the language when this was created.
|
3,162,227 | 3,162,240 | Link lists in C++ (pt. 2) | How come void del_begin() crashes when there's only one node left (I have other functions to add nodes)?
#include <iostream>
using namesspace std;
node *start_ptr = NULL;
node *current;
int option = 0;
void del_end()
{
node *temp, *temp2;
temp = start_ptr;
if (start_ptr == NULL)
cout <<... | You didn't show us the code for del_begin(), but your del_end() has a bug in the case you're mentioning (single node list).
If you have only one node, your while loop will never execute, and temp2 will be uninitialized when you get to the line:
temp2->nxt = NULL;
Crash!
|
3,162,291 | 3,162,304 | Mediator pattern vs Publish/Subscribe | Can someone point out the main differences between the two?
It seems that, at least conceptually, the two are very closely related. If I were to hazard a guess, I would say that the publish/subscribe method is a subset of the mediator pattern (since the mediator need not necessarily be used in the publish/subscribe ma... | How I would describe the difference is that in mediator you probably care if the end application receives the message. So you use this to guarantee who is receiving the message. Whereas with pub/sub you just publish your message. If there are any subscribers they will get it but you don't care.
|
3,162,430 | 3,162,441 | iads.h / VS2005 / W2003 SP2 - which SDK and what are the side-effects? | I'm trying to compile someone elses C++ program using VS2005 on Windows 2003 (SP2).
The compile fails because it can't find iads.h
Which SDK should I install to get this header ?
When I install the SDK is there a danger I might break something already in use ? As far as I can tell the W2003 has no SDK's installed but i... | You need to the windows sdk. The SDK doesn't install like a regular application. Just because you "installed" it it doesn't change any settings in your compiler.
You will still have to add the directories to header files and libraries in the vs settings page.
You can have multiple version of the windows sdk, you just... |
3,162,502 | 3,162,534 | Is realloc guaranteed to be in-place when the buffer is shrinking? | Are there any guarantees that realloc() will always shrink a buffer in-place?? So that the following:
new_ptr = (data_type *) realloc(old_ptr, new_size * sizeof(data_type));
will always give new_ptr == old_ptr if new_size < old_size (except of course when new_size == 0). It seems sensible (to me) that it would work th... | No.
That's it. None of this "it may work in some architectures" or "it should, based on experience". The standard states clearly that the address may change so rely on that and nothing more. In any case, you asked if it was guaranteed - the answer that is a definite no(a).
In terms of coding to the standard: do, or do ... |
3,162,506 | 3,162,514 | C++: How to declare an array at the top of the method? | I'd like to declare an array at the top of my method, but it's not compiling:
Foo Bar()
{
int arr[]; // C2133
// …
// C2059, C2143, C2143
arr[] = {1, 2, 3};
}
What am I doing wrong here?
UPDATE I know that C++ doesn't force me to do it this way, but the project's convention wants all variables decla... | When you declare an array in C/C++, you need to specify the size. If you do not specify the size, then you need to define the array elements in the same declaration statement, like this:
int arr[] = {1, 2, 3};
|
3,162,510 | 3,164,874 | How to make GCC search for headers in a directory before the current source file's directory? | I am using GCC precompiled headers in my project with multi-architecture build, but things break down when I try to place it in a directory different from current source's directory.
The file is included with double quotes, and it works if I change it to angle brackets, but the problem is that I have a lot of other pr... | I have found a workaround.
Build a precompiled header under a different name. For example is the header is a.h, original precompiled header is pchdir.i686/a.h.gch, build it as
gcc a.h -o pchdir.i686/a-precompiled.h.gch
Use GCC's -include switch to make sure the renamed header is included before anything else (even be... |
3,162,533 | 3,162,557 | using BOOST_TYPEOF in expression | Can the following be done in a single line?
typedef BOOST_TYPEOF(generator) G;
typename G::value_type next;
typename BOOST_TYPEOF(generator)::value_type next; //does not compile
thank you
| Try to use mpl::identity
typename mpl::identity<BOOST_TYPEOF(generator)>::type::value_type next;
The macro is probably expanding to some compiler intrinsics like __typeof__(...) which aren't necessarily eligible to appear as nested name specifier. Even the C++0x proposed decltype(...) initially wasn't allowed before a... |
3,162,643 | 3,162,731 | Proper Trigonometry For Rotating A Point Around The Origin | Do either of the below approaches use the correct mathematics for rotating a point? If so, which one is correct?
POINT rotate_point(float cx,float cy,float angle,POINT p)
{
float s = sin(angle);
float c = cos(angle);
// translate point back to origin:
p.x -= cx;
p.y -= cy;
// Which One Is Correct:
// T... | It depends on how you define angle. If it is measured counterclockwise (which is the mathematical convention) then the correct rotation is your first one:
// This?
float xnew = p.x * c - p.y * s;
float ynew = p.x * s + p.y * c;
But if it is measured clockwise, then the second is correct:
// Or This?
float xnew = p.x *... |
3,162,814 | 3,163,025 | Does GetPath() return cubic or quadratic bezier control points? | Microsoft's docs say:
Specifies that the corresponding point
in lpPoints is a control point or
ending point for a Bèzier curve.
PT_BEZIERTO values always occur in sets of three. The point in
the path immediately preceding them
defines the starting point for the
Bèzier curve. The first two
PT_BEZ... | It's a cubic with shared endpoints. p[0], p[1], p[2], p[3] make up the first segment; p[3], p[4], p[5], and p[6] make up the second segment. And so forth.
|
3,162,826 | 3,162,847 | Fastest timing resolution system | What is the fastest timing system a C/C++ programmer can use?
For example:
time() will give the seconds since Jan 01 1970 00:00.
GetTickCount() on Windows will give the time, in milliseconds, since the system's start-up time, but is limited to 49.7 days (after that it simply wraps back to zero).
I want to get the curre... | For timing, the current Microsoft recommendation is to use QueryPerformanceCounter & QueryPerformanceFrequency.
This will give you better-than-millisecond timing. If the system doesn't support a high-resolution timer, then it will default to milliseconds (the same as GetTickCount).
Here is a short Microsoft article w... |
3,162,876 | 3,162,900 | Can't catch atan2 domain error | I am using a thirdparty library eg. Lib::ValueType value. I then do a call to a member function, value.theta() which performs some mathematical operations including a call to atan2 from <cmath>. Sometimes the theta component is empty and an "atan2: domain error" is thrown. However, I can't catch the exception even by w... | The C standard library isn't aware of C++ exception handling, so try-catch won't work. You might want to look at the matherr function - according to the documentation, you can redefine this function in your program in order to handle math exceptions by yourself.
|
3,163,017 | 3,163,019 | Intentional compiler warnings for Visual C++ that appear in Error List? | How can you create a compiler warning (in the model of #error, except as a warning) on purpose in Visual C++ that will show up on the Error List with the correct file and line number?
GCC and other compilers offer #warning, but the MSVC compiler does not.
The "solution" at http://support.microsoft.com/kb/155196 does no... | Just add this to your common include file (ex, stdafx.h):
#define __STR2__(x) #x
#define __STR1__(x) __STR2__(x)
#define __LOC__ __FILE__ "("__STR1__(__LINE__)") : warning W0000: #pragma VSWARNING: "
#define VSWARNING(x) message(__LOC__ x)
Use this like:
#pragma VSWARNING("Is this correct?!?!")
The compiler will out... |
3,163,055 | 3,163,060 | TestFixtureSetUp-like method in CppUnit | In NUnit, the TestFixtureSetup attribute can be used to mark a method which should be executed once before any tests in the fixture.
Is there an analogous concept in CppUnit?
If not, is there a C++ unit testing framework that supports this concept?
Based on the answer below, here is an example which accomplishes this (... | Since you cannot use the fixture constructor this implies that CPPUnit is using instance per test. I think you''ll have to have a method and a static boolean flag that is read many times and written only the first time. Then call this in the constructor.
|
3,163,241 | 3,233,984 | CDialog doesnt show in task bar | Im trying to get a CDialog that has no border or frame to show in the task bar.
It is created in the InitInstance of CWinApp (used to update the app) and i have tried setting the WS_EX_APPWINDOW flag but it still doesnt show in the task bar.
Any ideas?
Edit:
As defined in the resource:
IDD_UPDATEFORM_DIALOG DIALOGEX 0... | I figured out a hack to get this to work. Instead of disabling the toolbar/caption bar styles to get no border, i used SetWindowRgn to clip the frame and title bar. Same affect, less issues.
RECT rect;
GetWindowRect(&rect);
int w = rect.right - rect.left;
int h = rect.bottom - rect.top;
HRGN region = CreateRoundRectRg... |
3,163,281 | 3,163,296 | Reading a text document character by character | I am reading a text file character by character using ifstream infile.get() in an infinite while loop.
This sits inside an infinite while loop, and should break out of it once the end of file condition is reached. (EOF). The while loop itself sits within a function of type void.
Here is the pseudo-code:
void function (... | In C++, you don't compare the return value with EOF. Instead, you can use a stream function such as good() to check if more data can be read. Something like this:
while (infile.good()) {
ch = infile.get();
// ...
}
|
3,163,364 | 3,626,967 | Excluding certain functions from gcov/lcov coverage results | Is it possible to exclude certain functions or lines of code from the gcov coverage analysis. My code contains certain functions that are used for debugging, and are not exercised as part of my test suite. Such functions reduce the coverage percentage reported by gcov. I would like to exclude these functions from the r... | I filter out certain source files by running the output of lcov --capture through a simple awk script. The output of lcov --capture has a very simple format and the awk script below filters out source files matching file_pattern. I think it is possible to adapt the script to make it filter functions instead of file nam... |
3,163,424 | 3,163,460 | About "GUI in C# and code in C++" | First of all, until now, all my programming education, has been targeted to console applications, just like everyone who starts learning C and C++. (the 2 languages i know)
Now, i want to jump to the nice graphical World.
So, I am exploring Windows Forms, i have already got many headaches trying to understand the lang... | Joan, while it is certainly possible to develop an applications Front End in C# and the logic in C++ I believe it to be a huge waste of effort to do it this way since you only complicate yourself for no real benefit since you can code both things in the same language.
C# has many advantages over C++ and I personally us... |
3,163,489 | 3,163,507 | why default constructor is not available by default in some case | class foo {
public:
int a;
int b;
foo(int a_, int b_) : a(a_), b(b_) {}
};
int main() {
foo f;
}
when I try to compile the above code snippet, I got error message as below:
foo.cc: In function 'int main()'
foo.cc:12: error: no matching function for call to 'main()::foo::foo()'
foo.cc:10: note: candidates... | Compiler generates default constructor only if there're no user defined constructors.
C++ Standard 12.1/5:
A default constructor for a class X is a constructor of class X that can be called without an argument. If
there is no user-declared constructor for class X, a default constructor is implicitly declared.
|
3,163,569 | 3,163,616 | C++0x - lambda expression does look same as Java's anonymous inner class? | Is my interpretation of lambda expression in the context of c++ and Java is correct?
| They are not quite as same. Both create unnamed classes, but their similarity ends at that point.
In C++ you create a closure catching your local variables, optionally by reference. In Java, you just get a snapshot of the current local variable's values (and those variables need to be "final").
The purpose of anonymou... |
3,163,684 | 3,164,165 | checking if time is in specific interval in C++? | I need to generate values according to time of the day, is there a neat way to accomplish that ?
from 9-12 value should be between x - y
from 6-9 value should be between a - b
is there any other way than getting timeinfo struct and extracting hour out of it?
| You should take a look at boost::posix_time.
using namespace boost::posix_time;
using namespace boost::gregorian;
ptime now = second_clock::local_time();
// You can compare now with other ptime values
ptime nine_o_clock = day_clock::local_day() + hours(9);
ptime twelve_o_clock = day_clock::local_day() + hours(12);
i... |
3,163,757 | 3,163,801 | C++ factory function with boost::noncopyable | Suppose I need to implement factory function which returns object O which inherits/has members inheriting from boost::noncopyable.
struct O : boost::noncopyable {};
O factory() { return O(); }
Obviously returning value fails to compile.
What method do you know or use to implement such factory methods? I really like t... | Boost does have support for this in the form of BOOST_MOVABLE_BUT_NOT_COPYABLE, but in my opinion it's far more trouble than it's worth to implement (without C++11) and just returning a (smart) pointer is far easier...
|
3,163,901 | 3,164,000 | Asynchronous distributed file transfers | I need to build a system where we have a set of machines produce unique files, lets call them PRODUCERS and a set of machines receive these files which we call CONSUMERS. Any machine from the PRODUCERS can send files to one or more of the CONSUMERS[ based on some hash mechanism]. I need to build a mechanism which ensur... | What you describe is probably most easily implemented using some form of message passing. You might want to take a look at http://www.zeromq.org; I've worked with this library myself and can whole-heartedly recommend it.
On a side-note: if you don't need to use C++, picking up some Erlang might be interesting in your ... |
3,163,916 | 3,163,997 | how a variable can be access in all dialogs of a project using MFC? | i have made a file open dialog, it contains an edit control whose variable is "path" that contains the file name. what i want is to use this variable's value in other dialogs but it gives the error that "path" is an undeclard identifier.
i declare path by right click on edit control, add a variable of CString type. pat... | Before the dialog closes, pass this "path" back to the CWinApp (by implementing Get/Set functions in the CWinApp)
Your main class, which is derived from CWinApp, is in effect the "global" class (static class, or singleton). Anything you wish to put into global variables, can be put into your CWinApp-derived class inste... |
3,164,034 | 3,170,433 | Sort, pack and remap array of indexed values to minimize overlapping | Sitation:
overview:
I have something like this:
std::vector<SomeType> values;
std::vector<int> indexes;
struct Range{
int firstElement;//first element to be used in indexes array
int numElements;//number of element to be used from indexed array
int minIndex;/*minimum index encountered between firstElement ... | Okay, it looks like there is only one way to reliably solve this problem:
Make sure that no index is ever used by two ranges at once by duplicating values.
I.e scan entire array of indexes, and when you find index (of value) that is being used in more than one range, you add copy of that value for each range - each wit... |
3,164,234 | 3,298,482 | How do I read stdout/stderr output of a child process correctly? | I have written a program a.exe which launches another program I wrote, b.exe, using the CreateProcess function. The caller creates two pipes and passes the writing ends of both pipes to the CreateProcess as the stdout/stderr handles to use for the child process. This is virtually the same as the Creating a Child Proces... | Is seems that on Windows versions prior to Windows Vista (where you can use the CancelSynchronousIO function, there is no way around terminating the reading threads using TerminateThread.
A suitable alternative (suggested by adf88) might be to use asynchronous ReadFile calls, but that's not possible in my case (too man... |
3,164,237 | 3,164,289 | Problem with QMap return as reference? | Greetings all,
I have a code snippet as follows :
class AppCtx {
private:
QMap<QString,IRzPlugin*> pluginsMap;
public :
void addPlugin(IRzPlugin *plugin)
{
pluginsMap.insert(plugin->getPluginUID(),plugin);
}
QMap<QString,IRzPlugin*> & getPlugins()
{
return pluginsMap;
}
}
In my client code I access the ... | I notice you are copying the QMap with
QMap<QString,IRzPlugin*> plugins=appctx->getPlugins();
I assume you want to take a reference to it i.e.
QMap<QString,IRzPlugin*>& plugins=appctx->getPlugins();
If you only need a reference-to-const then the docs say that it is implicitly shared so it's not such a big deal.
If t... |
3,164,602 | 3,184,440 | GOF State Pattern State Transition Implementation Issues | Firstly, can anyone explain how a state object can be shared when the state object has no instance variables ?
This text is taken from GOF, page 308, item 3 (consequences section):
The state object can be shared.
If state objects have no instance variabkes - that is, the state they
represent is encoded entirely ... | In the state pattern you have an represent the state of an object by using state-objects. These state-objects represent a certain state, but they do not have any mutable state of their own. This means they never change. Therefore, any number of objects can use the same state-object at the same time (even from different... |
3,164,792 | 3,164,828 | whats an example usage of c++ pointers? | i'm self-teaching c++ and i get how pointers work. but the doc i'm using is quite literal and the examples don't really go into why or when pointers would be used. a couple of real world examples would help me retain the knowledge.
| You use pointers when you want your objects to exist longer than the current stack. You can also use them to avoid copying objects into containers.
// TODO: Remember to call DeleteObjects() when you're done here!!
std::vector<MyObject*> Objects;
void Test()
{
MyObject *const pObject = new MyObject();
Objects.p... |
3,165,080 | 3,169,833 | How to call Matlab from C++ code? | I am trying to call Matlab functions from C++ code.
With Matlab it comes an example of such code at /extern/examples/eng_mat/engdemo.cpp, however I found no way to build that source code.
Here is the makefile I use:
CFLAGS = -Wall -O3
INCLUDES = -I/opt/Matlab-2009a/extern/include
LIBRARIES = -Wl,-R/opt/Matlab-2009a/b... | Assuming $MATLABROOT is the path to MATLAB:
$MATLABROOT/bin/mex -f $MATLABROOT/bin/engopts.sh engdemo.cpp
If you add the -v switch, the verbose output will show you what commands are being used to compile the engine application.
|
3,165,289 | 3,165,378 | C++ desktop applications framework | I am not new to c++,but i have not found a c++ desktop applications framework.I have found one and it seems to complex.Are there other frameworks available for c++ out there?.
| There are various choices when it comes to c++ Desktop app frameworks,
it mainy depends on your skills and on the plattform you want the app to run.
Two Opensource Frameworks that are plattform independent, I have used so far are
The QT-Framework from trolltech now nokia and wxWidgets
if you need something in the mult... |
3,165,400 | 3,166,094 | To use or not to use C++0x features |
Possible Duplicate:
How are you using C++0x today?
I'm working with a team on a fairly new system. We're talking about migrating to MSVC 2010 and we've already migrated to GCC 4.5. These are the only compilers we're using and we have no plans to port our code to different compilers any time soon.
I suggested that af... | I'd make the decision on a per-feature basis.
Remember that the standard is really close to completion. All that is left is voting, bugfixing and more voting.
So a simple feature like auto is not going to go away, or have its semantics changed. So why not use it.
Lambdas are complex enough that they might have their wo... |
3,165,563 | 3,165,672 | Flexible logger class using standard streams in C++ | i would like to create a flexible logger class. I want it to be able to output data to a file or to standard output. Also, i want to use streams. The class should look something like:
class Logger
{
private:
std::ostream m_out; // or ofstream, iostream? i don't know
public:
void useFile( std::string fname);
v... | The way I've attacked this problem before is to make Logger an abstract base class and create separate FileLogger and OutStreamLogger classes. Then create a CompositeLogger object that implements the Logger interface, which just outputs all loggers:
CompositeLogger compLogger;
compLogger.Add(new FileLogger("output.txt... |
3,165,964 | 3,166,016 | Multiple animation at a time | I'm making a Asteroids game but I can not get to play more than one explosion at a time. Just get to do one at a time ...
This is my code I call in the main loop:
for(i = 0; i < MAX_SHOTS; i++) {
for(j = 0; j < MAX_ASTEROIDS; j++) {
if(shot[i].CheckCollision(asteroide[j])) {
shot[i].SetPos(-100,... | Inside your second loop, you're moving each explosion to the location of the asteroid asteroide[numAst] - you're playing all the explosions, just all at the same place!
You should only position the explosion once after you Enable(true) it, when it's created in the first loop, not each time you draw it.
Hope that helps.... |
3,166,201 | 3,166,277 | c++ STL queues, references and segmentation fault | Newbie to C++ learning by converting a java program to c++. The following code results in a segmentation fault (SIGSEGV) when executed.
//add web page reference to pages queue (STL)
void CrawlerQueue::addWebPage(WebPage & webpage) {
pagesBuffer.push(webpage);
}
//remove and return web page reference from pages que... | pagesBuffer.pop();
This line invalidate your reference.
Remember that standard container works with values, not "references", so when you add an object using a reference to it, in fact you add a copy of the object in the container.
Then using pop(), you destroy this object, making any reference or pointer pointing to... |
3,166,319 | 3,166,391 | Is it worth learning Eclipse for C++ development | As far as I know it is hard to learn using Eclipse from scratch. But I will get such benefits as fast source code browsing, call graphs, static code analysis. What other benefits will I get from using Eclipse for C++ (CDT)?
| I used Eclipse with C++ only for a short time, and rather I could use Eclipse with Java for some months. Now that I'm not using it, I feel that some important features are missing.
Eclipse is pretty heavy, but has some great features that I can't find easily somewhere else.
I can live without code analysis and project ... |
3,166,395 | 3,166,460 | Win7 Drag&Drop: Possible to find out if COleDataObject contains shell library? | I have an application with a file and folder list control which supports Drag&Drop operations. Now I would like to make it possible for the user to be able to drop a Windows 7 Library (e.g. Music, Pictures and so on) into this control.
In my drop handler I have a COleDataObject and now I'm trying to find out, if a libr... | These MSDN pages might help:
http://msdn.microsoft.com/en-us/library/bb776902%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ff729168%28VS.85%29.aspx
They don't have the exact format values you've given, but it should be a start.
|
3,166,510 | 3,166,556 | c++: Call derrived function from base constructor? |
Possible Duplicate:
Calling virtual functions inside constructors
class Base
{
virtual void method()
{ cout << "Run by the base."; };
public:
Base() { method(); };
};
class Derived: public Base
{
void method()
{ cout << "Run by the derived."; };
};
void main()
{
... | You can't do this without adding extra code.
A common way to achieve this is to use a private constructor and a create function that first calls the constructor (via new) and then a second finish_init method on the newly created object. This does prevent you from creating instances of the object on the stack though.
|
3,166,541 | 3,166,640 | Tips on creating a C++ DLL to be used from .NET | Hey guys, I'm creating a DLL in C++ and I want it to be usable from .NET apps (both C# and VB.NET). I've been scouring the internet for tips and what I've found so far suggests:
Declaring my C++ functions as extern C and using __stdcall
Using basic C types for parameters and return types instead of STL containers (e.g... | The managed code cannot free the memory, it doesn't have access to the allocator built into the CRT. You could use CoTaskMemAlloc() to allocate the buffer instead, the managed code can call Marshal.FreeCoTaskMem(). You'd have to declare the buffer pointer argument as "ref IntPtr" or declare the return type of the fun... |
3,166,569 | 3,166,664 | What's the best way to move on to advanced C++? | And what's your suggestion to move to the next level of C++ programming for someone who may be called, well, an intermediate C++ programmer?
Intermediate Programmer: Understands ISO C++ reasonably well, can read and modify other's code with some luck, good with data structures and algorithms but not great
Learn C++0x... | To answer your specific questions:
Learn C++0x
You definitely need to do this. So possibly you have your answer right there...
Learn what kind of assembly code gets generated for different construct
types, maybe for x86
I would say learn how to understand the assembly language the compiler generates, in outline i... |
3,167,045 | 3,167,077 | Do I need to specify virtual on the sub-classes methods as well? | This has probably been asked before on SO, but I was unable to find a similar question.
Consider the following class hierarchy:
class BritneySpears
{
public:
virtual ~BritneySpears();
};
class Daughter1 : public BritneySpears
{
public:
virtual ~Daughter1(); // Virtual specifier
};
class Daughter2 : publ... | No you technically do not need to specify virtual. If the base method is virtual then C++ will automatically make the matching override method virtual.
However you should be marking them virtual. The method is virtual after all and it makes your code much clearer and easier to follow by other developers.
|
3,167,183 | 3,167,503 | System.TypeLoadException when using a vector as argument in a method | I have a class Param.cpp which is a set of parameters for the main class Model.cpp. I create an instance of Param.cpp in a C# file using a graphic interface. It works great, I can see in debug that the param has a PropList containing one element - in my example.
My Model class has a function BuildModel(Param param) wh... | Look at the exception's InnerException property. That tells you what really went wrong. If that doesn't help, update your question with its message and stacktrace.
|
3,167,188 | 3,167,255 | Is casting could lead to a issue? | In one RTOS, i'm debugging one issue which is, program is crashing one point always when it send a 8-bit value (Lets call it 'Int8 rogue_int')to a function (lets call it 'Infected( Int16 )' ) whose definition is taking that variable as 16-bit variable. Before entering to that last function Infected(..), value for 'rogu... | I'm not a C++ expert, but what you've described does not make any sense. Casting from an 8-bit type to a 16-bit type cannot result in uninitialized memory being incorporated into to the value--upcasts of this type have narrow, strictly-specified semantics, and the compiler can't just grab an extra adjacent byte and add... |
3,167,272 | 3,167,372 | How does c++ std::vector work? | How does adding and removing elements "rescale" the data? How is the size of the vector calculated (I believe it is kept track of)? Any other additional resources to learn about vectors would be appreciated.
| In terms of sizing, there are two values of interest for a std::vector: size, and capacity (accessed via .size() and .capacity()).
.size() is the number of elements that are contained in the vector, whereas .capacity() is the number of elements that can be added to the vector, before memory will be re-allocated.
If you... |
3,167,280 | 3,167,310 | strtok problem in visual c++ | I am trying the strtok in visual c++, but it seems not working. This not my first time using strtok, but i just counldnt figure out what is wrong with it. the code is quite simple.
in main
cout<<getLevels("/'Group'/'Channel1'")<<endl;
in getLevels()
int getLevels(char * fullPath){
int level=0;
char *nextToken;
cha... | Strtok is trying to split the string by inserting nulls in place of the tokens. I'd guess that the literal "/'Group'/'Channel1'" is stored as a constant and can't be modified.
Try removing the "Enable String Pooling (/GF)" flag from the compiler options.
|
3,167,477 | 3,167,528 | Taking the Address of a Temporary, with a Twist | I have a function address_of, which returns a Pointer (encapsulating a shared_ptr) to its argument. address_of needs to work on both lvalues and rvalues, so there are two versions of address_of: one accepting a reference and the other accepting an rvalue reference. Since taking the address of a temporary is a Bad Thing... | The problem is caused by reference decay: (correct term is "reference collapse")
template < typename T >
void f(T && t) { .... }
int x; f(x); // what is f()?
The answer to the question in the code is that f() is:
void f(T& && t) { .... }
Which because of reference decay turns into this:
void f(T& t) { .... }
As you... |
3,167,554 | 3,177,752 | Global symbol not in symtab | I'm getting the following error when trying to output a stack trace through GDB:
global symbol 'object' found in a.cpp
psymtab but not in symtab
What does this error mean exactly, and is it caused by my code or is it a GDB issue?
| I think it's gdb issue. Try gdb 7.0 or 7.1
|
3,167,560 | 3,167,600 | Passing std::string in a library API | We are currently building an API for a certain library.
Part of the interface requires the library to get and return to the user classes such as vector and string.
When trying to simulate use of the library in a simple scenario, in debug mode the system crush when delivering a string as an input.
I believe there is a d... | You should avoid passing STL objects between different binary modules.
For string, you have to rely on const char* for read only parameter and char*, <buffer size> for input parameters...
For vectors, it could be a bit more difficult especially if you have to change the content of the vector...
About your ideas:
You a... |
3,167,565 | 3,167,726 | Declaring "friend" functions fails under Visual Studio 2008 | I am trying to declare a global function as a "friend" of a class:
namespace first
{
namespace second
{
namespace first
{
class Second
{
template <typename T> friend T ::first::FirstMethod();
};
}
}
}
When I compile this code under... | You have hit my quiz by accident - the sequence T ::first:: ... is interpreted as a single name. You need to put some token in between the colons and T. Solution is presented in the linked question too.
Notice that in any case you first have to declare the function designated by a qualified name in its respective names... |
3,167,661 | 3,167,835 | Picking a front-end/interpreter for a scientific code | The simulation tool I have developed over the past couple of years, is written in C++ and currently has a tcl interpreted front-end. It was written such that it can be run either in an interactive shell, or by passing an input file. Either way, the input file is written in tcl (with many additional simulation-specifi... | I was a strong Tcl/Tk proponent from pre-release, until I did a largish project with it and found how unmaintainable it is. Unfortunately, since prototypes are so easy in Tcl, you wind up with "one-off" scripts taking on lives of their own.
Having adopted Python in the last few months, I'm finding it to be all that Tcl... |
3,167,796 | 3,167,816 | Transfering code to a sub function | I have some code within one function that I want to separate into its own function. I want to do this with as little modification to the original code as possible. Below I have written a noddy example where the code segment is simply "x += y". I want to take out that code and put it in its own function. With C I have t... | I believe what you're looking for is a reference. In your example, the function sub_function would then look like this:
void sub_function(int y, int& x)
{
x += y;
}
and you'd call it this way:
sub_function(y, x);
|
3,168,056 | 3,168,092 | va_arg returning the wrong argument | With the following code va_arg is returning garbage for the second and third pass through vProcessType.
// va_list_test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <tchar.h>
#include <cstdarg>
#include <windows.h>
void processList(LPTSTR str, ...);
void vProcessList(LPTS... | You're passing the same va_list each time to vProcessType() - in each call to vProcessType() you're acting on the first va_arg in the list.
So you're always dealing with the TEXT("foobar") parameter when calling vProcessType().
Also note that the standard has this to say about passing a va_list to another function:
Th... |
3,168,076 | 3,168,191 | Will a class recall its constructor when pushed in a std::vector? | if for example I do:
FOO foo;
foovect.push_back(foo);
where FOO is a class with a default constructor.
Will the constructor be called only when foo is put on the stack, or is it called again when pushed into the std::vector?
Thanks
I'm doing:
OGLSHAPE::OGLSHAPE(void)
{
glGenBuffersARB(GL_ARRAY_BUFFER_ARB,&ObjectVB... | FOO foo; would call the constructor.
foovect.push_back(foo); would call the copy constructor.
#include <iostream>
#include <vector>
class FOO
{
public:
FOO()
{
std::cout << "Constructor" << std::endl;
}
FOO(const FOO& _f)
{
std::cout << "Copy Constructor" << std::endl;
}
};
int... |
3,168,158 | 3,168,236 | strange file reading problem in c++: fread() | I have a very strange problem when reading a binary file.
void metaDataProcess(FILE *f){
unsigned __int32 obLength;
unsigned __int32 numProp;
char* objPath;
unsigned __int32 rawDataIndex;
int level;
fread(&obLength,sizeof(obLength),1,f);
objPath=new char[obLength];
cout<<"i am at"<<ftel... | objPath=new char[obLength + 1];
cout<<"i am at"<<ftell(f)<<endl;
fread(objPath,sizeof( char),obLength,f);
objPath[obLength]='\0';
|
3,168,238 | 3,168,263 | const reference must be initialized in constructor base/member initializer list | I am trying to block access to the default constructor of a class I am writing. The constructor I want others to use requires a const reference to another object. I have made the default constructor private to prevent others from using it. I am getting a compiler error for the default constructor because the const r... | don`t declare default constructor.
It is not available anyway (automatically that it's) if you declare your own constructor.
class CBar
{
public:
CBar(const CFoo& foo) : fooReference(foo)
{
}
private:
const CFoo& fooReference;
};
fairly comprehensive explanation of constructors can be found here:
http:... |
3,168,299 | 3,168,531 | non-resizeable vector/array of non-reassignable but mutable members? | Is there a way to make a non-resizeable vector/array of non-reassignable but mutable members? The closest thing I can imagine is using a vector<T *> const copy constructed from a temporary, but since I know at initialization how many of and exactly what I want, I'd much rather have a block of objects than pointers. I... | What you're asking is not really possible.
The only way to prevent something from being assigned is to define the operator = for that type as private. (As an extension of this, since const operator = methods don't make much sense (and are thus uncommon) you can come close to this by only allowing access to const refer... |
3,168,607 | 3,168,740 | C++ boost template parameter traits | I believe I had seen macro in boost that recovers template template parameters, for example:
template<class>
struct parameters;
#define parameters(T) template<class A> \
struct parameters<T<A> > { typedef A type1; };
is there one like this, or am I wrong?
Thank you
| delctype support in C++0x makes this fairly trivial to implement:
template<template <typename> class Parent, typename Param1>
Param1 get_type(Parent<Param1> const &input) { return Param1(); }
SomeTpl<int> some_obj;
delctype(get_type(some_obj)) x;
(Though you need a separate get_type definition for templates with 2, 3... |
3,168,675 | 3,181,523 | DOS-reported error: Bad file number | I have a batch file that tries to compile a static library using Borland C++ Builder 6.0
It is called from Borland make (makefile created with bpr2mak) which is called from a .bat file (used to compile the whole project with Visual Studio and some Borland C++ Builder legacy projects), which is called from a bash shell ... | The problem was that TLib does not like to have his output redirected (seen here) without having an input pipe as well. Solved by creating an input pipe to in the Boost::Process::launcher using set_stdin_behavior
|
3,168,720 | 3,168,745 | Portable way to use shared_ptr in GCC | GCC 4.1 uses the <tr1/memory> header and GCC 4.3 uses <memory> header, I need a portable way to use shared_ptr with GCC 4.3.2 and with GCC 4.2.1, is there any way to do that without checking GCC version macros or using external libraries like Boost ?
| <tr1/memory> will still work with gcc 4.3. If you wan to support both versions, just use the tr1 name.
|
3,169,015 | 3,169,076 | How exactly should I implement a shuffle or random-number algorithm for an array to display quotes in random order? | I already know there's answers for this kind of thing, but I don't really know how to implement them in my code. Also, I would like to refrain from using any more functions unless neccessary.
Here's my code:
int main()
{
unsigned seed;
seed = 1;
srand(seed);
std::string starFox[8];
int x[8];
starFox[0] = "Do a b... | You're seeding the same value every time you run, so you'll always get the same pseudo-random sequence. Try this:
srand(time(0));
|
3,169,221 | 3,170,479 | Qt C++, Eclipse (on Win 7) - project build failed with "unresolved reference to _Unwind_Resume" error | I've got Windows 7 64-bit and I just installed Qt (open-source, version 2010.04) and integrated it into Eclipse (CDT, version Helios). Everything seemed to went fine, I added paths to both Qt and mingw32 compiler and configured Qt by running configure.exe. The integration with Eclipse works fine too.
However, I've prob... | Solved - problem was with the bad version of MinGW, I had the current version (5.1.6.) installed. I uninstalled it and replaced with version 4.4.0, downloaded from Qt website (http://get.qt.nokia.com/misc/MinGW-gcc440_1.zip) and everything is fine now.
|
3,169,392 | 3,173,210 | How to optimize this algorithm | I need help with making this bit of code faster:
UnitBase* Formation::operator[](ushort offset)
{
UnitBase* unit = 0;
if (offset < itsNumFightingUnits)
{
ushort j = 0;
for (ushort i = 0; i < itsNumUnits; ++i)
{
if (unitSetup[i] == UNIT_ON_FRONT)
{
if (j == offset)
unit = unitFormation[i];
++... | I have redesigned the solution completely, using two vectors, one for units on the front, and one for other units, and changed all algorithms such that a unit with a changed status is immediately moved from one vector to another. Thus I eliminated the counting in the [] operator which was the main bottleneck.
Before us... |
3,169,709 | 3,169,743 | C++ project reference in a C# project in visual studio 2008 | Is is possible to reference a C++ project in a C# Project? I've tried adding a reference in the c# project to that C++ one but I get an error saying "A reference to could not be added"
| If your C++ project is a native (standard C++) project, then no. If it's a managed project, you can add a reference to it.
For native code, you'll need to use P/Invoke to access functions within the C++ DLL.
|
3,169,895 | 3,169,899 | C++ inheritance public and private? | Is it possible to inherit both or all parts of a class (other than private) in C++?
class A {
}
clas B : ...? { }
| If you're asking whether you can make private members visible to derived classes, the answer is no - that's why they are private. Use protected members in the base class if you want derived classes to be able to access them.
|
3,169,905 | 3,169,976 | How can I do this for cubic beziers? | Right now i'm creating polygons with bezier handles. It's working well, except right now I always do something like this:
for(float i = 0; i < 1; i += 0.04)
{
interpolate A, a.handle to B.handle, B at time i
}
The problem is no matter how short the distance or long the distance between point A and B, it always prod... | What you probably want to investigate is an adaptive stepping algorithm.
The basic concept is that you want more points where the radius of curvature is small (i.e.- sharp bends), and fewer points where the radius of curvature is large (i.e.- more straight).
There is a great article here, that shows a good adaptive ste... |
3,170,093 | 3,182,197 | Palm OS 5.4 (Garnet) IR programming (Use CIR on IrDa port) | I would like to create an open source alternative to Palm OS programs like Noviiremote and Omniremote.
I need to access the IR port of my Tungsten E2 and use it to transmit remote control type signals (I assume NEC and/or RC-5).
Are there any libraries out there I could use? If not, how do I go about transmitting raw c... | Okay, I think I am asking the wrong question, so I am going to mark this answered and ask a new one.
What I really need is a way to translate RC-5 to serial bits, which I think is possible, since I can use raw IR.
New question is here: https://stackoverflow.com/questions/3182235/sending-rc-5-ir-signals-serially-using-r... |
3,170,236 | 3,170,248 | How can I "double overload" an operator? | If I have a database-like class, and I want to do something like this:
object[1] == otherObject;
How do I "double overload" operator[] and operator==?
| object[1] returns an object of someType. You need to overload operator== on that someType.
|
3,170,295 | 3,170,303 | Where can I find the implementation for std::string | I am looking for the code for the c++ string class. What header is it implemented in?
| There is no single implementation for std::string. But you can find your particular implementation in the <string> header.
On my system it can be found here:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.0/include/g++-v4/bits/basic_string.h and /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.0/include/g++-v4/bits/basic_string.tcc
On a Deb... |
3,170,319 | 6,438,608 | boost::asio fails to close TCP connection cleanly | I am trying to implement a simple HTTP server. I am able to send the HTTP response to clients but the issue is that on Firefox I get "Connection Reset" error. IE too fails, while Chrome works perfectly and displays the HTML I sent in the response.
If I telnet to my server then I get "Connection Lost" message, just afte... | The server should not close the socket. If the server closes the socket and the client sends more data or there is data in the receive queue then the client will receive a RST causing this error. See http://cs.baylor.edu/~donahoo/practical/CSockets/TCPRST.pdf
The HTTP server should read the entire client request or in ... |
3,170,440 | 3,170,450 | Cross platform recursive file list using C++? | What is the most efficient way to recursively list files in a specific directory and its subdirectories? Should I use the standard library, or use some third party?
I want this because I use v8 as a JavaScript engine, and I want to execute all scripts in some directory (and its subdirectories). If there's any built-in... | For a generic cross-platform C++ solution, check out boost::filesystem
|
3,170,623 | 3,170,784 | Secure data transfer over http with custom server | I am pretty new to security aspect of application. I have a C++ window service (server) that listens to a particular port for http requests. The http requests can be made via ajax or C# client. Due to some scope change now we have to secure this communication between the clients and custom server written in C++.
Theref... | Given that you have an existing HTTP server (non-IIS) and you want to implement HTTPS (which is easy to screw up and hard to get right), you have a couple of options:
Rewrite your server as a COM object, and then put together an IIS webservice that calls your COM object to implement the webservice. With this done, yo... |
3,171,241 | 3,172,258 | What do I call a "normal" variable? | int* p;
int& r;
int i;
double* p2;
double& r2;
double d;
p and p2 are pointers, r and r2 are references, but what are i and d? (No, I am not looking for the answer "an int and a double")
I am looking for a name to use for "normal" variables, setting them apart from pointers and references. I don't believe that such a ... | Value types (value variables) was my first thought, but it seems to make some people uncomfortable, so nonreferential types (nonreferential variables) works just as well: pointers and references are both "referential types" in the sense that they refer to another location, while ordinary value types do not.
|
3,171,418 | 3,184,000 | V8 FunctionTemplate Class Instance | I have the following class:
class PluginManager
{
public:
Handle<Value> Register(const Arguments& args);
Handle<ObjectTemplate> GetObjectTemplate();
};
I want the Register method to be accessible from JavaScript. I add it to the global object like this:
PluginManager pluginManagerInstance;
global->Set(Strin... | You're trying to bind two things at once: the instance and the method to invoke on it, and have it look like a function pointer. That unfortunately doesn't work in C++. You can only bind a pointer to a plain function or a static method. So image you add a static "RegisterCB" method and register it as the callback:
stat... |
3,171,535 | 3,171,567 | Standard C++ libraries headers on gnu gcc site | I want to browse the source code of gnu implementation of C++ standard libraries -- header files as well as the implementation.
I have landed myself into:
http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.4/index.html
My first step was to look header file at:
http://gcc.gnu.org/onlinedocs/libstdc++/libst... | A lot of libstdc++ is implemented using only headers, but some parts of the STL, like std::basic_string, have compiled implementations.
The declaration of template std::basic_string is located in /usr/include/c++/4.4.4/bits/basic_string.h (replace '4.4.4' with g++ -dumpversion) and the implementation is in /usr/include... |
3,171,540 | 3,171,557 | Long constructor initialization lists | How do you deal with them? I have some classes (usually classes that hold stats etc.) with some 20+ variable members, and the initialization lists end up very long, extending beyond the page width if I don't manually wrap around. Do you try and break down such classes or do you deal with this in some other way?
It doe... |
extending beyond the page width
Well, first off, you should probably decide on a page width and stick to it. Use auto line wrapping from your editor, if you want. Reading code that's greater than your window size is really difficult, especially for your coworkers using vi or emacs from terminals. Pick a page width... |
3,171,545 | 3,171,571 | Creating different instances in a loop | I'll be writing a validator for a specific file format (the format itself is unimportant). There's a large set of documents that specify what every section of the format needs to look like, how the different parts relate and so on. Lots and lots of MUST's, SHALL's, SHOULD's, MAY's etc.
The architecture I envision is as... | C++ is a static language that lacks reflection, hence you will have to enumerate your classes one way or another, be it a map of class names to factory functions, an explicit function that creates them all, or cppunit-style "registration" (same as putting them in a static map).
With that said, go with the simplest poss... |
3,171,579 | 3,171,797 | OpenGL: How much memory anisotropic filtered textures will use? | I'm curious, does the anisotropic texture filtering increase the memory usage? And how to calculate it?
| AFAIK it doesn't, but it requires mipmaps, which increase the texture memory usage by 33%.
|
3,171,821 | 3,171,902 | Using Autotools for a new shared library | What I want to do is to create a new shared library called libxxx that links against another shared library called libzzz, this shared library has an independent "pkg-config"-like tool, let's say it's called "zzz-config" which gives the cflags needed by the compilation phase when using the libzzz.
What I want to do is:... | My suggestion is to use CMake instead of autotools. It's much easier to work with and it will also create platform-dependent projects to work with (i.e. Makefile-based projects, Visual Studio projects, Eclipse CDT projects, etc.).
It will also create debug or release projects, depending on the CMAKE_BUILD_TYPE variable... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.