C++ developers, all know the basics of C++: Declarations, conditionals, loops, operators, etc.
Some of us even mastered the stuff like templates, object model, complex I/O, etc.
But what are the most hidden features or tricks or dark corners of C++/STL that even C++ fans, addicts, and experts barely know?
I am talking about a seasoned...
I have a question on the linear Towers of Hanoi.
I implemented it in C++ but am trying to do the same using the tail recursive or iterative method. I am having trouble with my algorithm.
This code snippet shows transferring blocks from the middle tower to the end tower.
#include <stdlib.h>
#include <stdio.h>
using namespace std;
//i...
Hello, I already looked for my answer but I didn't get any quick response for a simple example.
I want to compile a flex/bison scanner+parser using g++ just because I want to use C++ classes to create AST and similar things.
Searching over internet I've found some exploits, all saying that the only needed thing is to declare some funct...
How can I make my C++ code cross platform capable? I need it to work on Windows and Xubuntu.
...
Problem:
I have a hand held device that scans those graphic color barcodes on all packaging. There is a track device that I can use that will slide the device automatically. This track device functions by taking ascii code through a serial port. I need to get this thing to work in FileMaker on a Mac. So no terminal programs, etc...
What...
I want to write a new virtual webcam driver, which for example will take an AVI or live stream for example for screen and stream it as webcam source.
I'll not have webcam really, I want to add a virtual webcam which streams desktop screen.
I should write a webcam in kernel mode to do so ? If so, could you guide me to a sample webcam d...
Hi,
I would like to know a good syntax for C++ getters and setters.
private:
YourClass *pMember;
the setter is easy I guess:
void Member(YourClass *value){
this->pMember = value; // forget about deleting etc
}
and the getter?
should I use references or const pointers?
example:
YourClass &Member(){
return *this->pMember;
}
...
I have a friend who is trying to make the switch to Linux, but is hung up on the apparent lack of debugging/IDE environments for C++, especially as they relate to template programming. He has been using visual studio for years and is maybe a little spoiled by their awesome IDE. Does anyone have any good suggestions for an environment whe...
My disclaimer here is that I started teaching myself C++ about a week ago and my former experience with programming has been with dynamic languages (Python, javascript).
I'm trying to iterate though the contents of a vector using a generic function to print out the items:
#include <iostream>
#include <algorithm>
#include <vector>
usin...
Is there such a thing? First time I encountered a practical need for it, but I don't see one listed in stroustrup. I intend to write:
// Detect when exactly one of A,B is equal to five.
return (A==5) ^^ (B==5);
But there is no ^^ operator. Can I use bitwise ^ here and get the right answer (regardless of machine representation of true ...
I have some problems with OpenCVs cvCanny(...) and the Image data types it can handle. Well, maybe you guys/gals know a solution.
I have a 32 bit float image and I want to perform cvCanny on it.
The problem is cvCanny can only handle "IPL_DEPTH_8S" or U (signed / unsigned short), or at least that's what I suspect. The OpenCV manual doe...
One can create an anonymous object that is initialized through constructor parameters, such as in the return statement, below.
struct S {
S(int i_, int j_) : i(i_), j(j_) { }
int i, j;
};
S f()
{
return S(52, 100);
}
int main()
{
cout << f().i << endl;
return 0;
}
However, can one similarly create an anonymous aggregate th...
I'm designing a public API in C++ and believe I'd like to retain C++ property-function style conventions that look like int& Value(), and const int& Value() const as opposed to get/set prefixes which return/assign by value because I feel the usage patterns are more concise and equally readable, while blending into existing C++ code very ...
How can I achieve the best file streaming performance in Vista? My goal is to read a large file (several hundred MB) over the network directly into memory.
I've allocated a memory block the same size as the file. This is also my destination buffer. I've tried ReadFile, _read, fread, ifstream::read, and boost::iostreams::mapped_file::con...
How to write a getter that can not be deleted?
I want to own the variables and not share them.
reading here and there I figured out that no matter what I return the memory can be freed
however I define it, is this true?
references, const pointers, no matter what, the function which is calling the getter can delete it and my private var...
I have a class whose functionality I'd like to depend on a set of plug-in policies. But, I'm not sure how to get a class to derive from an arbitrary number of classes.
The code below is an example of what I'm trying to achieve.
// insert clever boost or template trickery here
template< class ListOfPolicies >
class CMyClass : public L...
I need a regular expression for finding class declarations so I can add a #define before the "class" keyword. The regular expression doesn't have to be perfect, just good enough that it catches most of the cases.
...
I have a class which I want to expose a list of structs (which just contain some integers).
I don't want the outside to modify these data, just iterate over it and read them
Example:
struct TestData
{
int x;
int y;
// other data as well
}
class IterableTest
{
public:
// expose TestData here
};
now in my code I want to use...
I'am trying to return a string from a function but it doesn't compile.
When I replace the std::string& type with int& it compiles, however I want to return additionally to the boolean a std::string how do I do this?
bool luacw_getElementContent( std::string name, std::string& content, bool fromBeginning )
{
content = "test";
retur...
According to the C / C++ standard (see this link), the >> operator in C and C++ is not necessarily an arithmetic shift for signed numbers. It is up to the compiler implementation whether 0's (logical) or the sign bit (arithmetic) are shifted in as bits are shifted to the right.
Will this code function to ASSERT (fail) at compile time f...