I came across the following code recently:
class Foo
{
public:
void bar();
// .. other stuff
};
void Foo::bar()
{
if(!this) {
// .. do some stuff without accessing any data members
return;
}
// .. do normal actions using data members
}
The code compiles because in C++ methods are just functions th...
When you have a Debug version of a C++ program running on an OS that has no VS or CRT installed, will you still get Debug Assertion error boxes?
The ones that say "Debug Assert Failed!".
Or will you only get them when the machine has certain components, such as CRT or Visual Studio installed?
...
So I ran into something interesting that I didn't realize about the ternary operator (at least in Visual C++ 98-2010). As pointed out in http://msdn.microsoft.com/en-us/library/e4213hs1(VS.71).aspx if both the expression and conditional-expression are l-values the result is an l-value.
Of course normally in c/c++ you'd write something ...
Hi.
int num = 0;
list<char>::iterator it;
for(it = binary.const_iterator; it !=binary.end(); ++it) {
if(*it == '1') {
abc.push_back(copyoflist.at(num));
}
num++;
}
Here binary is defined as list binary;
copyoflist is a char type vector.
I am getting this error:
invalid use of 'std::list >::const_iterator'
on the line
fo...
To the first O of the array?
...
When I'm testing my C++ class with Boost.Test and my custom exceptions are thrown (they are instances of my class), this is the message I see in log:
unknown location:0: fatal error in "testMethod": unknown type
It's very un-informative and I don't know how to teach Boost.Test to convert my exception to string and display it properly....
I have a class with an array of scoped pointers to objects which do NOT have a default constructor.
The only way I've found to "initialise" them is using swap() like this:
class Bar {
Bar(char * message) {};
}
class Foo
{
boost::scoped_ptr<Bar> arr[2];
Foo()
{
arr[0].swap(boost::scoped_ptr<Bar>( new Bar("ABC") ));
ar...
Even though OOP uses objects and data encapsulation, the code still writes out like a procedure. So what makes OOP loose the procedural label? Is it just because it is considered "high-level"?
Thank You.
...
Hi, basically have two questions.
1. Is there a c++ library that would do full text boolean search just like in mysql. E.g.,
Let's say I have:
string text = "this is my phrase keywords test with boolean query.";
string booleanQuery = "\"my phrase\" boolean -test -\"keywords test\" OR ";
booleanQuery += "\"boolean search\" -mysql ...
The following code
template<typename T, typename U> class Alpha
{
public:
template<typename V> void foo() {}
};
template<typename T, typename U> class Beta
{
public:
Alpha<T, U> alpha;
void arf();
};
template<typename T, typename U> void Beta<T, U>::arf()
{
alpha.foo<int>();
}
int main()
{
Beta<int, float> beta;
...
I'm fairly green when it comes to c++0x, lambda, and such so I hope you guys can help me out with this little problem.
I want to store a bunch of callbacks in a vector and then use for_each to call them when the time is right. I want the callback functions to be able to accept arguments. Here's my code right now. The trouble is in vo...
does struct member alignment in VC bring performance benefit? if it is what is the best performance implication by using this and which size is best for current cpu architecture (x86_64, SSE2+, ..)
...
I found a strange issue when porting my code from Visual Studio to gcc. The following code compiles fine in Visual Studio, but results in an error in gcc.
namespace Baz
{
template <class T>
class Foo
{
public:
void Bar()
{
Baz::Print();
}
};
void Print() { std::cout << "Hello, world!" << st...
Is there a way of passing both a type and a string to a parametrized test using google's test.
I would like to do:
template <typename T>
class RawTypesTest : public ::testing::TestWithParam<const char * type> {
protected:
virtual void SetUp() {
message = type;
}
};
TEST_P(RawTypesTest, Foo) {
ASSERT_STREQ(message, type)...
Is there any real sequence of characters that always compares greater than any other string?
My first thought was that a string constructed like so:
std::basic_string<T>(std::string::max_size(), std::numeric_limits<T>::max())
Would do the trick, provided that the fact that it would almost definitely fail to work isn't such a big issu...
Should SomeClass* initialEl = new SomeClass[5]; necessarily compile, assuming SomeClass does not have a non-publicly declared default constructor? Consider:
/*
* SomeClass.h
*
*/
#ifndef SOMECLASS_H_
#define SOMECLASS_H_
class SomeClass
{
public:
SomeClass(int){}
~SomeClass(){}
};
#endif /* SOMECLASS_H_ */
/*
* main.c...
Windows hooks allows you to poke inside other processes and sometimes alter their behaviors.
Is there such thing for Mac OS X?
Thanks!
...
Hi all,
How can I see the source code of an executable compiled by Delphi or C++?
Please help me.
After Edit:
I have a program. When I start this program, it shows a dialog and asks for a password. This password is saved in source code. I want to take this password quickly and easily.
...
I'm using the iPhone port of ImageMagick. I'm trying to loop through the frames of an animated gif and turn each frame into an UIImage. I know I can init a UIImage with NSData which I can init with a const void *. So how to I get the buffer and length of the image?
Here's the code:
MagickReadImage(wand, filename);
while...
Respected sir,
I am about to start my final year project "Real time/fast implemantation license plate recognition" using opencv. Opencv is totaly new for me and i am working on it now-a-days and i am facing couple of problems with it. I know how to display images but i don't know where to read image pixels or read image in mat...