Search Results

Search found 2995 results on 120 pages for 'logical operators'.

Page 16/120 | < Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >

  • sOperator as and generic classes

    - by abatishchev
    I'm writing .NET On-the-Fly compiler for CLR scripting and want execution method make generic acceptable: object Execute() { return type.InvokeMember(..); } T Execute<T>() { return Execute() as T; /* doesn't work: The type parameter 'T' cannot be used with the 'as' operator because it does not have a class type constraint nor a 'class' constraint */ // also neither typeof(T) not T.GetType(), so on are possible return (T) Execute(); // ok } But I think operator as will be very useful: if result type isn't T method will return null, instead of an exception! Is it possible to do?

    Read the article

  • Dynamically allocated structure and casting.

    - by Simone Margaritelli
    Let's say I have a first structure like this: typedef struct { int ivalue; char cvalue; } Foo; And a second one: typedef struct { int ivalue; char cvalue; unsigned char some_data_block[0xFF]; } Bar; Now let's say I do the following: Foo *pfoo; Bar *pbar; pbar = new Bar; pfoo = (Foo *)pbar; delete pfoo; Now, when I call the delete operator, how much memory does it free? sizeof(int) + sizeof(char) Or sizeof(int) + sizeof(char) + sizeof(char) * 0xFF ? And if it's the first case due to the casting, is there any way to prevent this memory leak from happening? Note: please don't answer "use C++ polymorphism" or similar, I am using this method for a reason.

    Read the article

  • Operator Overloading in C

    - by Leif Andersen
    In C++, I can change the operator on a specific class by doing something like this: MyClass::operator==/*Or some other operator such as =, >, etc.*/(Const MyClass rhs) { /* Do Stuff*/; } But with there being no classes (built in by default) in C. So, how could I do operator overloading for just general functions? For example, if I remember correctly, importing stdlib.h gives you the - operator, which is just syntactic sugar for (*strcut_name).struct_element. So how can I do this in C? Thank you.

    Read the article

  • Is Perl's flip-flop operator bugged? It has global state, how can I reset it?

    - by Evan Carroll
    I'm dismayed. Ok, so this was probably the most fun perl bug I've ever found. Even today I'm learning new stuff about perl. Essentially, the flip-flop operator .. which returns false until the left-hand-side returns true, and then true until the right-hand-side returns false keep global state (or that is what I assume.) My question is can I reset it, (perhaps this would be a good addition to perl4-esque hardly ever used reset())? Or, is there no way to use this operator safely? I also don't see this (the global context bit) documented anywhere in perldoc perlop is this a mistake? Code use feature ':5.10'; use strict; use warnings; sub search { my $arr = shift; grep { !( /start/ .. /never_exist/ ) } @$arr; } my @foo = qw/foo bar start baz end quz quz/; my @bar = qw/foo bar start baz end quz quz/; say 'first shot - foo'; say for search \@foo; say 'second shot - bar'; say for search \@bar; Spoiler $ perl test.pl first shot foo bar second shot

    Read the article

  • Problem with operator ==

    - by CPPDev
    I am facing some problem with use of operator == in the following c++ program. #include < iostream> using namespace std; class A { public: A(char *b) { a = b; } A(A &c) { a = c.a; } bool operator ==(A &other) { return strcmp(a, other.a); } private: char *a; }; int main() { A obj("test"); A obj1("test1"); if(obj1 == A("test1")) { cout<<"This is true"<<endl; } } What's wrong with if(obj1 == A("test1")) line ?? Any help is appreciated.

    Read the article

  • explicit copy constructor or implicit parameter by value

    - by R Samuel Klatchko
    I recently read (and unfortunately forgot where), that the best way to write operator= is like this: foo &operator=(foo other) { swap(*this, other); return *this; } instead of this: foo &operator=(const foo &other) { foo copy(other); swap(*this, copy); return *this; } The idea is that if operator= is called with an rvalue, the first version can optimize away construction of a copy. So when called with a rvalue, the first version is faster and when called with an lvalue the two are equivalent. I'm curious as to what other people think about this? Would people avoid the first version because of lack of explicitness? Am I correct that the first version can be better and can never be worse?

    Read the article

  • What does the symbol :=: mean

    - by Dan Maguire
    I've found the symbol :=: in some Clarion code and I can't seem to figure out exactly what it does. The code was written by a previous developer many years ago, so I can't ask him. I also have not been able to find any results for "colon equals colon" in Google. Here is an example of the code, where bufSlcdpaDtl is a file object: lCCRecord Like(bufSlcdpaDtl),Pre(lCCRecord) ! ...other stuff... lCCRecord :=: bufSlcdpaDtl I'm wondering if it's something similar to ::= in Python or possibly the assignment operator :=.

    Read the article

  • Logic differences in C and Java

    - by paragjain16
    Compile and run this code in C #include <stdio.h> int main() { int a[] = {10, 20, 30, 40, 50}; int index = 2; int i; a[index++] = index = index + 2; for(i = 0; i <= 4; i++) printf("%d\n", a[i]); } Output : 10 20 4 40 50 Now for the same logic in Java class Check { public static void main(String[] ar) { int a[] = {10, 20, 30, 40, 50}; int index = 2; a[index++] = index = index + 2; for(int i = 0; i <= 4; i++) System.out.println(a[i]); } } Output : 10 20 5 40 50 Why is there output difference in both languages, output is understandable for Java but I cannot understand output in C One more thing, if we apply the prefix ++ operator, we get the same result in both languages, why?

    Read the article

  • is mysql index useful on column 'state' when only doing bit-operations on the column?

    - by Geert-Jan
    I have a lot of domain entities (stored in mysql) which undergo lots of different operations. Each operation is executed from a different program. I need to keep (flow)-state for these entities which I implemented in as a long field 'flowstate' used as a bitset. to query mysql for entities which have undergone a certain operation I do something like: select * from entities where state >> 7 & 1 = 1 Indicating bit 7 (cooresponding to operation 7) has run. (<-- simplified) Anyway, I really didn't pay attention to the performance implications of this setup in the beginning, and I think I'm in a bit of trouble since queries as the above run pretty slow. What I'd like to know: Does an mysql index on 'flowstate' help at all? After all it's not a single value Mysql can quickly find using a binary sort or whatever. If it doesn't, are there any other things I could do to speed things up? . Are there special 'mask-indices' for fields with use-cases as the above? TIA, Geert-jan

    Read the article

  • How do I overload the square-bracket operator in C#?

    - by Coderer
    DataGridView, for example, lets you do this: DataGridView dgv = ...; DataGridViewCell cell = dgv[1,5]; but for the life of me I can't find the documentation on the index/square-bracket operator. What do they call it? Where is it implemented? Can it throw? How can I do the same thing in my own classes? ETA: Thanks for all the quick answers. Briefly: the relevant documentation is under the "Item" property; the way to overload is by declaring a property like public object this[int x, int y]{ get{...}; set{...} }; the indexer for DataGridView does not throw, at least according to the documentation. It doesn't mention what happens if you supply invalid coordinates. ETA Again: OK, even though the documentation makes no mention of it (naughty Microsoft!), it turns out that the indexer for DataGridView will in fact throw an ArgumentOutOfRangeException if you supply it with invalid coordinates. Fair warning.

    Read the article

  • Why does virtual assignment behave differently than other virtual functions of the same signature?

    - by David Rodríguez - dribeas
    While playing with implementing a virtual assignment operator I have ended with a funny behavior. It is not a compiler glitch, since g++ 4.1, 4.3 and VS 2005 share the same behavior. Basically, the virtual operator= behaves differently than any other virtual function with respect to the code that is actually being executed. struct Base { virtual Base& f( Base const & ) { std::cout << "Base::f(Base const &)" << std::endl; return *this; } virtual Base& operator=( Base const & ) { std::cout << "Base::operator=(Base const &)" << std::endl; return *this; } }; struct Derived : public Base { virtual Base& f( Base const & ) { std::cout << "Derived::f(Base const &)" << std::endl; return *this; } virtual Base& operator=( Base const & ) { std::cout << "Derived::operator=( Base const & )" << std::endl; return *this; } }; int main() { Derived a, b; a.f( b ); // [0] outputs: Derived::f(Base const &) (expected result) a = b; // [1] outputs: Base::operator=(Base const &) Base & ba = a; Base & bb = b; ba = bb; // [2] outputs: Derived::operator=(Base const &) Derived & da = a; Derived & db = b; da = db; // [3] outputs: Base::operator=(Base const &) ba = da; // [4] outputs: Derived::operator=(Base const &) da = ba; // [5] outputs: Derived::operator=(Base const &) } The effect is that the virtual operator= has a different behavior than any other virtual function with the same signature ([0] compared to [1]), by calling the Base version of the operator when called through real Derived objects ([1]) or Derived references ([3]) while it does perform as a regular virtual function when called through Base references ([2]), or when either the lvalue or rvalue are Base references and the other a Derived reference ([4],[5]). Is there any sensible explanation to this odd behavior?

    Read the article

  • C++ overloading operator comma for variadic arguments

    - by uray
    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<int> list); //in use: myFunction(1,2,3,4); //or maybe: myFunction(ArgList<int>(1),2,3,4);

    Read the article

  • what does this C++ line of code mean "sol<?=f((1<<n)-1,i,0)+abs(P[i])*price;"

    - by KItis
    Could anyone help me to understand following line of code. sol I am studying an algorithm written using c++ and it has following operator " following is the error message returned. Hello.cpp: In function ‘int main()’: Hello.cpp:115: error: ‘memset’ was not declared in this scope Hello.cpp:142: error: expected primary-expression before ‘?’ token Hello.cpp:142: error: expected primary-expression before ‘=’ token Hello.cpp:142: error: expected ‘:’ before ‘;’ token Hello.cpp:142: error: expected primary-expression before ‘;’ token may be " Thanks in advance for the time you spent reading this post.

    Read the article

  • When should I use $ (and can it always be replaced with parentheses)?

    - by J Cooper
    From what I'm reading, $ is described as "applies a function to its arguments." However, it doesn't seem to work quite like (apply ...) in Lisp, because it's a binary operator, so really the only thing it looks like it does is help to avoid parentheses sometimes, like foo $ bar quux instead of foo (bar quux). Am I understanding it right? Is the latter form considered "bad style"?

    Read the article

  • What does the '&' operator do in C++?

    - by rascher
    n00b question. I am a C guy and I'm trying to understand some C++ code. I have the following function declaration: int foo(const string &myname) { cout << "called foo for: " << myname << endl; return 0; } How does the function signature differ from the equivalent C: int foo(const char *myname) Is there a difference between using string *myname vs string &myname? What is the difference between & in C++ and * in C to indicate pointers? Similarly: const string &GetMethodName() { ... } What is the & doing here? Is there some website that explains how & is used differently in C vs C++?

    Read the article

< Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >