Search Results

Search found 3518 results on 141 pages for 'smooth operator'.

Page 18/141 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • c# "==" operator : compiler behaviour with different structs

    - by Moe Sisko
    Code to illustrate : public struct MyStruct { public int SomeNumber; } public string DoSomethingWithMyStruct(MyStruct s) { if (s == null) return "this can't happen"; else return "ok"; } private string DoSomethingWithDateTime(DateTime s) { if (s == null) return "this can't happen"; // XX else return "ok"; } Now, "DoSomethingWithStruct" fails to compile with : "Operator '==' cannot be applied to operands of type 'MyStruct' and '<null>'". This makes sense, since it doesn't make sense to try a reference comparison with a struct, which is a value type. OTOH, "DoSomethingWithDateTime" compiles, but with compiler warning : "Unreachable code detected" at line marked "XX". Now, I'm assuming that there is no compiler error here, because the DateTime struct overloads the "==" operator. But how does the compiler know that the code is unreachable ? e.g. Does it look inside the code which overloads the "==" operator ? (This is using Visual Studio 2005 in case that makes a difference). Note : I'm more curious than anything about the above. I don't usually try to use "==" on structs and nulls.

    Read the article

  • Java Newbie can't do simple Math, operator error

    - by elguapo-85
    Trying to do some really basic math here, but my lack of understanding of Java is causing some problems for me. double[][] handProbability = new double[][] {{0,0,0},{0,0,0},{0,0,0}}; double[] handProbabilityTotal = new double[] {0,0,0}; double positivePot = 0; double negativePot = 0; int localAhead = 0; int localTied = 1; int localBehind = 2; //do some stuff that adds values to handProbability and handProbabilityTotal positivePot = (handProbability[localBehind][localAhead] + (handProbability[localBehind][localTied] / 2.0) + (handProbability[localTied][localAhead] / 2.0) ) / (handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0)); negativePot = (handProbability[localAhead][localBehind] + (handProbability[localAhead][localTied] / 2.0) + (handProbability[localTied][localBehind] / 2.0) ) / (handProbabilityTotal[localAhead] + (handProbabilityTotal[localTied] / 2.0)); The last two lines are giving me problems (sorry for their lengthiness). Compiler Errors: src/MyPokerClient/MyPokerClient.java:180: operator / cannot be applied to double[],double positivePot = ( handProbability[localBehind][localAhead] + (handProbability[localBehind][localTied] / 2.0) + (handProbability[localTied][localAhead] / 2.0) ) / (handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0) ); ^ src/MyPokerClient/MyPokerClient.java:180: operator + cannot be applied to double, positivePot = ( handProbability[localBehind][localAhead] + (handProbability[localBehind][localTied] / 2.0) + (handProbability[localTied][localAhead] / 2.0) ) / (handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0) ); ^ src/MyPokerClient/MyPokerClient.java:180: operator / cannot be applied to double, positivePot = ( handProbability[localBehind][localAhead] + (handProbability[localBehind][localTied] / 2.0) + (handProbability[localTied][localAhead] / 2.0) ) / (handProbabilityTotal[localBehind] + (handProbability[localTied] / 2.0) ); Not really sure what the problem is. You shouldn't need anything special for basic math, right?

    Read the article

  • Using overloaded operator== in a generic function

    - by Dimitri C.
    Consider the following code: class CustomClass { public CustomClass(string value) { m_value = value; } public static bool operator==(CustomClass a, CustomClass b) { return a.m_value == b.m_value; } public static bool operator!=(CustomClass a, CustomClass b) { return a.m_value != b.m_value; } public override bool Equals(object o) { return m_value == (o as CustomClass).m_value; } public override int GetHashCode() { return 0; /* not needed */ } string m_value; } class G { public static bool enericFunction1<T>(T a1, T a2) where T : class { return a1.Equals(a2); } public static bool enericFunction2<T>(T a1, T a2) where T : class { return a1==a2; } } Now when I call both generic functions, one succeeds and one fails: var a = new CustomClass("same value"); var b = new CustomClass("same value"); Debug.Assert(G.enericFunction1(a, b)); // Succeeds Debug.Assert(G.enericFunction2(a, b)); // Fails Apparently, G.enericFunction2 executes the default operator== implementation instead of my override. Can anybody explain why this happens?

    Read the article

  • Trying to overload + operator

    - by FrostyStraw
    I cannot for the life of me understand why this is not working. I am so confused. I have a class Person which has a data member age, and I just want to add two people so that it adds the ages. I don't know why this is so hard, but I'm looking for examples and I feel like everyone does something different, and for some reason NONE of them work. Sometimes the examples I see have two parameters, sometimes they only have one, sometimes the parameters are references to the object, sometimes they're not, sometimes they return an int, sometimes they return a Person object. Like..what is the most normal way to do it? class Person { public: int age; //std::string haircolor = "brown"; //std::string ID = "23432598"; Person(): age(19) {} Person operator+(Person&) { } }; Person operator+(Person &obj1, Person &obj2){ Person sum = obj1; sum += obj2; return sum; } I really feel like overloading a + operator should seriously be the easiest thing in the world except I DON'T KNOW WHAT I AM DOING. I don't know if I'm supposed to create the overload function inside the class, outside, if it makes a difference, why if I do it inside it only allows one parameter, I just honestly don't get it.

    Read the article

  • Visitor and templated virtual methods

    - by Thomas Matthews
    In a typical implementation of the Visitor pattern, the class must account for all variations (descendants) of the base class. There are many instances where the same method content in the visitor is applied to the different methods. A templated virtual method would be ideal in this case, but for now, this is not allowed. So, can templated methods be used to resolve virtual methods of the parent class? Given (the foundation): struct Visitor_Base; // Forward declaration. struct Base { virtual accept_visitor(Visitor_Base& visitor) = 0; }; // More forward declarations struct Base_Int; struct Base_Long; struct Base_Short; struct Base_UInt; struct Base_ULong; struct Base_UShort; struct Visitor_Base { virtual void operator()(Base_Int& b) = 0; virtual void operator()(Base_Long& b) = 0; virtual void operator()(Base_Short& b) = 0; virtual void operator()(Base_UInt& b) = 0; virtual void operator()(Base_ULong& b) = 0; virtual void operator()(Base_UShort& b) = 0; }; struct Base_Int : public Base { void accept_visitor(Visitor_Base& visitor) { visitor(*this); } }; struct Base_Long : public Base { void accept_visitor(Visitor_Base& visitor) { visitor(*this); } }; struct Base_Short : public Base { void accept_visitor(Visitor_Base& visitor) { visitor(*this); } }; struct Base_UInt : public Base { void accept_visitor(Visitor_Base& visitor) { visitor(*this); } }; struct Base_ULong : public Base { void accept_visitor(Visitor_Base& visitor) { visitor(*this); } }; struct Base_UShort : public Base { void accept_visitor(Visitor_Base& visitor) { visitor(*this); } }; Now that the foundation is laid, here is where the kicker comes in (templated methods): struct Visitor_Cout : public Visitor { template <class Receiver> void operator() (Receiver& r) { std::cout << "Visitor_Cout method not implemented.\n"; } }; Intentionally, Visitor_Cout does not contain the keyword virtual in the method declaration. All the other attributes of the method signatures match the parent declaration (or perhaps specification). In the big picture, this design allows developers to implement common visitation functionality that differs only by the type of the target object (the object receiving the visit). The implementation above is my suggestion for alerts when the derived visitor implementation hasn't implement an optional method. Is this legal by the C++ specification? (I don't trust when some says that it works with compiler XXX. This is a question against the general language.)

    Read the article

  • Table and Column names causing problems

    - by craig
    I have an issue when the T4 linq templates generate the classes for my MySql db using subsonic 3. It looks like one of our table names "operator" is causing problems in the Context.cs generated class. In the following line of code in Context.cs Visual Studio sees <operator> as a c# operator and generates a compilation error of "Type expected" public Query<operator> operators { get; set; } Is there anyway I can work around this without having to rename my database table and column names? For example hard coding something in Settings.ttinclude to use or map different names to specific db tables and columns?

    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

  • Overloading new, delete in C++

    - by user265260
    i came across this line is stroustrup An operator function must either be a member or take at least one argument of a user-defined type (functions redefining the new and delete operators need not). Dont operator new and operator delete take an user defined type as one of their arguments? what does it mean, am i missing something here

    Read the article

  • C++ Code Clarification Needed..

    - by ke3pup
    Hi guys I'm trying to understand what the code below says: struct compare_pq; struct compare_pq { bool operator() (Events *& a, Events *& b); }; std::priority_queue<Events *, std::vector<Events *>, compare_pq> eventList; i looked at what priority_queue is and how its declared but can't quit understand what compare_pq is doing in the priority_queue eventList. Also what does operator() do since i've never seen *& before and empty operator overloading operator()! any help would be appreciated. Thank you

    Read the article

  • What is the best signature for overloaded arithmetic operators in C++?

    - by JohnMcG
    I had assumed that the canonical form for operator+, assuming the existence of an overloaded operator+= member function, was like this: const T operator+(const T& lhs, const T& rhs) { return T(lhs) +=rhs; } But it was pointed out to me that this would also work: const T operator+ (T lhs, const T& rhs) { return lhs+=rhs; } In essence, this form transfers creation of the temporary from the body of the implementation to the function call. It seems a little awkward to have different types for the two parameters, but is there anything wrong with the second form? Is there a reason to prefer one over the other?

    Read the article

  • jQuery Smooth Sliding DIV Height

    - by Stu
    I have a Div that is 400px in height with the ID "content", I then do a slideToggle on the Div, load some data into the Div of a varying height e.g. 200px, and then do another slideToggle. What I get is the slide expanding to 400px, then jump back to 200px. And the same in reverse, expanding to 200px, then jump to 400px. This is my code: $('#content').slideToggle(600, function() { $("#content").load('data.php').slideToggle(600); }); So I thought I could do something like this, which would slide up the content Div, load the data, and then after it's loaded slide back down. This doesn't jump like the above method, but it is quite jerky for some reason. $('#content').slideUp(600, function() { $("#content").load('data.php', function() { $("#content").slideDown(600); }); }); Can anybody tell me if there is a better way of doing this so that I can slide it smoothly?

    Read the article

  • Jquery, Jcarousel smooth infinite scrolling

    - by nharry
    Hi all, I am using jcarousel to auto scroll some images. I would like to know how to make them scroll in one fluid scroll with no pauses or stops. Currently there is a pause and then it scrolls again. If I am not making myself clear then ask and I will try to explain a little better. This is the code: jQuery(document).ready(function() { jQuery('#mycarousel').jcarousel({ auto: 1, wrap: 'last', vertical: true, animation: 5000 });

    Read the article

  • What does the caret operator in Python do?

    - by Fry
    I ran across the caret operator in python today and trying it out, I got the following output: >>> 8^3 11 >>> 8^4 12 >>> 8^1 9 >>> 8^0 8 >>> 7^1 6 >>> 7^2 5 >>> 7^7 0 >>> 7^8 15 >>> 9^1 8 >>> 16^1 17 >>> 15^1 14 >>> It seems to be based on 8, so I'm guessing some sort of byte operation? I can't seem to find much about this searching sites other than it behaves oddly for floats, does anybody have a link to what this operator does or can you explain it here?

    Read the article

  • Conditional Operator in SQL Where Clause

    - by Marc
    I'm wishing I could do something like the following in SQl Server 2005 (which I know isnt valid) for my where clause. Sometimes @teamID (passed into a stored procedure) will be the value of an existing teamID, otherwise it will always be zero and I want all rows from the Team table. I researched using Case and the operator needs to come before or after the entire statement which prevents me from having a different operator based on the value of @teamid. Any suggestions other than duplicating my select statements. declare @teamid int set @teamid = 0 Select Team.teamID From Team case @teamid when 0 then WHERE Team.teamID > 0 else WHERE Team.teamID = @teamid end

    Read the article

  • Can operator= may be not a member?

    - by atch
    Having construction in a form: struct Node { Node():left_(nullptr), right_(nullptr) { } int id_; Node* left_; Node* right_; }; I would like to enable syntax: Node parent; Node child; parent.right_ = child; So in order to do so I need: Node& operator=(Node* left, Node right); but I'm getting msg that operator= has to be a member fnc; Is there any way to circumvent this restriction?

    Read the article

  • iPhone smooth move and pinch of UIImageView

    - by Jacob
    I have an image view that I'm wanting to be able to move around, and pinch to stretch it. It's all working, but it's kinda jumpy when I start to do any pinch movements. The position will jump back and forth between the two fingers. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { startLocation = [[touches anyObject] locationInView:mouth_handle]; if([touches count] == 2) { NSArray *twoTouches = [touches allObjects]; UITouch *first = [twoTouches objectAtIndex:0]; UITouch *second = [twoTouches objectAtIndex:1]; initialDistance = distanceBetweenPoints([first locationInView:mouth_handle],[second locationInView:mouth_handle]); } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint pt = [[touches anyObject] locationInView:mouth_handle]; CGRect frame = [mouth_handle frame]; frame.origin.x += pt.x - startLocation.x; frame.origin.y += pt.y - startLocation.y; frame.origin.x = (frame.origin.x < 58) ? 58 : frame.origin.x; frame.origin.x = (frame.origin.x > (260 - mouth_handle.frame.size.width)) ? (260 - mouth_handle.frame.size.width) : frame.origin.x; frame.origin.y = (frame.origin.y < 300) ? 300 : frame.origin.y; frame.origin.y = (frame.origin.y > 377) ? 377 : frame.origin.y; if(frame.origin.x - prevDistanceX > 2 && frame.origin.x - prevDistanceX < -2) frame.origin.x = prevDistanceX; if(frame.origin.y - prevDistanceY > 2 && frame.origin.y - prevDistanceY < -2) frame.origin.y = prevDistanceY; prevDistanceX = frame.origin.x; prevDistanceY = frame.origin.y; CGFloat handleWidth = mouth_handle.frame.size.width; if([touches count] == 2) { NSArray *twoTouches = [touches allObjects]; UITouch *first = [twoTouches objectAtIndex:0]; UITouch *second = [twoTouches objectAtIndex:1]; CGFloat currentDistance = distanceBetweenPoints([first locationInView:mouth_handle],[second locationInView:mouth_handle]); handleWidth = mouth_handle.frame.size.width + (currentDistance - initialDistance); handleWidth = (handleWidth < 60) ? 60 : handleWidth; handleWidth = (handleWidth > 150) ? 150 : handleWidth; if(initialDistance == 0) { initialDistance = currentDistance; } initialDistance = currentDistance; } mouth_handle.frame = CGRectMake(frame.origin.x, frame.origin.y, handleWidth, 15); } Any thoughts on how to make this smoother?

    Read the article

  • Looped jQuery slideshow with smooth cross-fades

    - by artlung
    I'm trying to do a simple rotating image on the home page. Under the hood I'm reading a directory and then populating urls for the images into an array. What I want to do is cross-fade the images. If it was just a matter of showing the next one, it's easy, but since I need to cross-fade, it's a bit harder. I think what I want to do is do the fades by calling animate() on the opacity value of the <img> tag, and in between swapping out the css background-image property of the enclosing <div>. But the results are not that great. I've used tools for more full featured slideshows, but I don't want the overhead of adding a plugin if I can avoid it, and a simple crossfade seems like it should be easier. Here's my JavaScript (I'm using jQuery 1.3.2): var slideshow_images = ["http:\/\/example.com\/wordpress\/wp-content\/themes\/testtheme\/sidebar-home-bg\/bg1.jpg","http:\/\/example.com\/wordpress\/wp-content\/themes\/testtheme\/sidebar-home-bg\/bg2.jpg","http:\/\/example.com\/wordpress\/wp-content\/themes\/testtheme\/sidebar-home-bg\/bg3.jpg"]; var slideshow_index = 0; var delay = 4000; var swapSlides = function() { var slideshow_count = slideshow_images.length; // initialize the background to be the current image $('#home-slideshow').css({ 'background-image': 'url(' + slideshow_images[slideshow_index] + ')', 'background-repeat:': 'no-repeat', 'width': 200, 'overflow': 'hidden' }); slideshow_index = ((slideshow_index + 1) == slideshow_count) ? 0 : slideshow_index + 1; // fade out the img $('#home-slideshow img').animate({opacity: 0}, delay); // now, the background is visible // next change the url on the img $('#home-slideshow img').attr('src', slideshow_images[slideshow_index]); // and fade it up $('#home-slideshow img').animate({opacity: 1.0}, delay); // do it again setTimeout('swapSlides()', 4000); } jQuery(document).ready(function(){ if (swapSlides) { swapSlides(); } }); And here's the markup I'm using: <div id="home-slideshow"><img src="http://example.com/wordpress/wp-content/themes/testtheme/sidebar-home-bg/bg1.jpg" alt="" /></div>

    Read the article

  • Is a switch statement the fastest way to implement operator interpretation in Java

    - by Mordan
    Is a switch statement the fastest way to implement operator interpretation in Java public boolean accept(final int op, int x, int val) { switch (op) { case OP_EQUAL: return x == val; case OP_BIGGER: return x > val; case OP_SMALLER: return x < val; default: return true; } } In this simple example, obviously yes. Now imagine you have 1000 operators. would it still be faster than a class hierarchy? Is there a threshold when a class hierarchy becomes more efficient in speed than a switch statement? (in memory obviously not) abstract class Op { abstract public boolean accept(int x, int val); } And then one class per operator.

    Read the article

  • Flash as3 smooth threshold

    - by arkzai
    hello, I'm building a flash app that pulls images from flickr and removes the white background I'm dong this using threshold and i get a really ragged outcome is there any way to get a better and smoother color key? thanks photoNumber = Math.floor(Math.random() * (photos.length)); loader.load(new URLRequest(photos[photoNumber].path)); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,draw); trace ( "trying to load photo " + photoNumber ); function draw(e:Event) { trace ("show photo " + photoNumber) var W:int=e.target.content.width; var H:int=e.target.content.height; bitmapdata=new BitmapData(W,H); bitmap=new Bitmap(bitmapdata); bitmapdata.draw(e.target.content); var threshold:uint = 0xF9F8F800; var color:uint = 0x00000000; var maskColor:uint = 0x00FF0000; bitmapdata.threshold(bitmapdata,new Rectangle(0,0,W,H),new Point(0,0),">", threshold, color, maskColor, true); bitmap.smoothing = true; //bitmap.scaleX = bitmap.scaleY = 0.99; // <---- imgHolder.addChild(bitmap); } }

    Read the article

  • FLVPlayback, go fullscreen smooth?

    - by Marcel
    Hello, Im looking into using and customizing FLVPlayback in a project. How to go about this is clear, but I noticed 1 anoying thing. When going fullscreen, first Flash player goes fullscreen and then briefly shows the FLVPlayback component in its original size, before jumping to show the video itself fullscreen. I noticed on Youtube this doesnt happen. How can I escape this 'flicker' and have the video go fullscreen as the videos do on youtube? Thanks a lot for any tips! Marcel

    Read the article

  • Arrow operator (->) usage in C

    - by Mohit Deshpande
    I am currently learning C by reading a good beginner's book called "Teach Yourself C in 21 Days" (I have already learned Java and C# so I am moving at a much faster pace). I was reading the chapter on pointers and the - (arrow) operator came up without explanation. I think that it is used to call members and functions (like the equivalent of the . (dot) operator, but for pointers instead of members). But I am not entirely sure. Could I please get an explanation and a code sample?

    Read the article

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