c++

Is it legal/well-defined C++ to call a non-static method that doesn't access members through a null pointer?

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...

Do you get Debug Assertions under C++ when no CRT is installed?

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? ...

c++ ternary operator

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 ...

Invalid use of List Iterator in c++

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...

O* p = new O[5]; What does p point to?

To the first O of the array? ...

How can I catch my custom exception with Boost.Test?

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....

Correct way to initialize array of boost::scoped_ptr ?

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...

Why is programming with objects not considered procedural?

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. ...

c++ search text n boolean mode

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 ...

How to fix the syntax in this code rife with templates?

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; ...

C++ for_each calling a vector of callback functions and passing each one an argument

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...

which size of struct member alignment in VC bring performance benefit?

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+, ..) ...

Aren't template class member functions compiled at instantiation?

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...

Passing a typename and string to parameterized test using google test

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 it possible to construct an "infinite" string?

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...

SomeClass* initialEl = new SomeClass[5];

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...

SetWindowsHookEx for Mac OS X?

Windows hooks allows you to poke inside other processes and sometimes alter their behaviors. Is there such thing for Mac OS X? Thanks! ...

Show Delphi And C++ Source Code

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. ...

How to get c buffer from ImageMagick Image

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...

where to read image pixel?

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...