comma-operator

What does the ',' operator do in C?

What does the ',' operator do in C? ...

What's up with static_cast with multiple arguments???

Can anyone tell me what this cast has for effect (besides setting happyNumber to 1337), if any at all, and if it has no other effect, how come I can write code like this??? Is this a compiler bug, or some "hidden away feature" of C++? int happyNumber = static_cast<int>(123.456, TRUE, "WTF" , false , "IS" , NULL , "GOING" , 0xff , "ON???...

Performance difference in for loop condition?

Hello all, I have a simple question that I am posing mostly for my curiousity. What are the differences between these two lines of code? (in C++) for(int i = 0; i < N, N > 0; i++) for(int i = 0; i < N && N > 0; i++) The selection of the conditions is completely arbitrary, I'm just interested in the differences between , and &&. I'm...

C comma operator

Why is the expression specified inside a comma operator (such as the example below) not considered a constant expression? For example, int a = (10,20) ; when given in global scope yields an error "initializer is not a constant", though both the expressions separated by a comma operator are constants (constant expressions). Why is th...

Why doesn't my overloaded comma operator get called?

Hi, I'm trying to overload the comma operator with a non-friend non-member function like this: #include <iostream> using std::cout; using std::endl; class comma_op { int val; public: void operator,(const float &rhs) { cout << this->val << ", " << rhs << endl; } }; void operator,(const float &lhs, const comma_o...

What does this dynamic allocation do?

Today, I found out that you can write such code in C++ and compile it: int* ptr = new int(5, 6); What is the purpose of this? I know of course the dynamic new int(5) thing, but here i'm lost. Any clues? ...

C++ overloading operator comma for variadic arguments

is it possible to construct variadic arguments for function by overloading operator comma of the argument? i want to see an example how to do so.., maybe something like this: template <typename T> class ArgList { public: ArgList(const T& a); ArgList<T>& operator,(const T& a,const T& b); } //declaration void myFunction(ArgList<in...

C++ overide global operator comma gives error

the second function gives error C2803 http://msdn.microsoft.com/en-us/library/zy7kx46x%28VS.80%29.aspx : 'operator ,' must have at least one formal parameter of class type. any clue? template<class T,class A = std::allocator<T>> class Sequence : public std::vector<T,A> { public: Sequence<T,A>& operator,(const T& a) { this-...

C++ -- return x,y; What is the point?

Hello, I have been programming in C and C++ for a few years and now I'm just now taking a college course in it and our book had a function like this for an example int foo(){ int x=0; int y=20; return x,y; //y is always returned } I have never seen such syntax. In fact, I have never seen the , operator used outside of parameter ...

When all does comma operator not act as a comma operator?

If you see this code, class A{ public: A(int a):var(a){} int var; }; int f(A obj) { return obj.var; } int main() { //std::cout<<f(23); // output: 23 std::cout<<f(23, 23); // error: too many arguments to function 'int f(A)' return 0; } f(23, 23) does not compile because the comma acts as a separator here a...

Commas in for loop

Why is the following line producing errors? for(int i = 0, int pos = 0, int next_pos = 0; i < 3; i++, pos = next_pos + 1) { // … } error: expected unqualified-id before ‘int’ error: ‘pos’ was not declared in this scope error: ‘next_pos’ was not declared in this scope Compiler is g++. ...