Search Results

Search found 4206 results on 169 pages for 'equals operator'.

Page 24/169 | < Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >

  • Two '==' equality operators in same 'if' condition are not working as intended.

    - by Manav MN
    I am trying to establish equality of three equal variables, but the following code is not printing the obvious true answer which it should print. Can someone explain, how the compiler is parsing the given if condition internally? #include<stdio.h> int main() { int i = 123, j = 123, k = 123; if ( i == j == k) printf("Equal\n"); else printf("NOT Equal\n"); return 0; } Output: manav@workstation:~$ gcc -Wall -pedantic calc.c calc.c: In function ‘main’: calc.c:5: warning: suggest parentheses around comparison in operand of ‘==’ manav@workstation:~$ ./a.out NOT Equal manav@workstation:~$ EDIT: Going by the answers given below, is the following statement okay to check above equality? if ( (i==j) == (j==k))

    Read the article

  • equality on the sender of an event

    - by Berryl
    I have an interface for a UI widget, two of which are attributes of a presenter. public IMatrixWidget NonProjectActivityMatrix { set { // validate the incoming value and set the field _nonProjectActivityMatrix = value; .... // configure & load non-project activities } public IMatrixWidget ProjectActivityMatrix { set { // validate the incoming value and set the field _projectActivityMatrix = value; .... // configure & load project activities } The widget has an event that both presenter objects subscribe to, and so there is an event handler in the presenter like so: public void OnActivityEntry(object sender, EntryChangedEventArgs e) { // calculate newTotal here .... if (ReferenceEquals(sender, _nonProjectActivityMatrix)) { _nonProjectActivityMatrix.UpdateTotalHours(feedback.ActivityTotal); } else if (ReferenceEquals(sender, _projectActivityMatrix)) { _projectActivityMatrix.UpdateTotalHours(feedback.ActivityTotal); } else { // ERROR - we should never be here } } The problem is that the ReferenceEquals on the sender fails, even though it is the implemented widget that is the sender - the same implemented widget that was set to the presenter attribute! Can anyone spot what the problem / fix is? Cheers, Berryl I didn't know you could edit nicely. Cool. Here is the event raising code: void OnGridViewNumericUpDownEditingControl_ValueChanged(object sender, EventArgs e) { // omitted to save sapce if (EntryChanged == null) return; var args = new EntryChangedEventArgs(activityID, dayID, Convert.ToDouble(amount)); EntryChanged(this, args); } Here is the debugger dump of the presenter attribute, sans namespace info: ?_nonProjectActivityMatrix {WinPresentation.Widgets.MatrixWidgetDgv} [WinPresentation.Widgets.MatrixWidgetDgv]: {WinPresentation.Widgets.MatrixWidgetDgv} Here is the debugger dump of the sender: ?sender {WinPresentation.Widgets.MatrixWidgetDgv} base {Core.GUI.Widgets.Lookup.MatrixWidgetBase<Core.GUI.Widgets.Lookup.DynamicDisplayDto>}: {WinPresentation.Widgets.MatrixWidgetDgv} _configuration: {Domain.Presentation.Timesheet.Matrix.WeeklyMatrixConfiguration} _wrappedWidget: {Win.Widgets.DataGridViewDynamicLookupWidget} AllowUserToAddRows: true ColumnCount: 11 Count: 4 EntryChanged: {Method = {Void OnActivityEntry(System.Object, Smack.ConstructionAdmin.Domain.Presentation.Timesheet.Matrix.EntryChangedEventArgs)}} SelectedCell: {DataGridViewNumericUpDownCell { ColumnIndex=3, RowIndex=3 }} SelectedCellValue: "0.00" SelectedColumn: {DataGridViewNumericUpDownColumn { Name=MONDAY, Index=3 }} SelectedItem: {'AdministrativeActivity: 130-04', , AdministrativeTime, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00} Berryl

    Read the article

  • Templated << friend not working when in interrelationship with other templated union types

    - by Dwight
    While working on my basic vector library, I've been trying to use a nice syntax for swizzle-based printing. The problem occurs when attempting to print a swizzle of a different dimension than the vector in question. In GCC 4.0, I originally had the friend << overloaded functions (with a body, even though it duplicated code) for every dimension in each vector, which caused the code to work, even if the non-native dimension code never actually was called. This failed in GCC 4.2. I recently realized (silly me) that only the function declaration was needed, not the body of the code, so I did that. Now I get the same warning on both GCC 4.0 and 4.2: LINE 50 warning: friend declaration 'std::ostream& operator<<(std::ostream&, const VECTOR3<TYPE>&)' declares a non-template function Plus the five identical warnings more for the other function declarations. The below example code shows off exactly what's going on and has all code necessary to reproduce the problem. #include <iostream> // cout, endl #include <sstream> // ostream, ostringstream, string using std::cout; using std::endl; using std::string; using std::ostream; // Predefines template <typename TYPE> union VECTOR2; template <typename TYPE> union VECTOR3; template <typename TYPE> union VECTOR4; typedef VECTOR2<float> vec2; typedef VECTOR3<float> vec3; typedef VECTOR4<float> vec4; template <typename TYPE> union VECTOR2 { private: struct { TYPE x, y; } v; struct s1 { protected: TYPE x, y; }; struct s2 { protected: TYPE x, y; }; struct s3 { protected: TYPE x, y; }; struct s4 { protected: TYPE x, y; }; struct X : s1 { operator TYPE() const { return s1::x; } }; struct XX : s2 { operator VECTOR2<TYPE>() const { return VECTOR2<TYPE>(s2::x, s2::x); } }; struct XXX : s3 { operator VECTOR3<TYPE>() const { return VECTOR3<TYPE>(s3::x, s3::x, s3::x); } }; struct XXXX : s4 { operator VECTOR4<TYPE>() const { return VECTOR4<TYPE>(s4::x, s4::x, s4::x, s4::x); } }; public: VECTOR2() {} VECTOR2(const TYPE& x, const TYPE& y) { v.x = x; v.y = y; } X x; XX xx; XXX xxx; XXXX xxxx; // Overload for cout friend ostream& operator<<(ostream& os, const VECTOR2<TYPE>& toString) { os << "(" << toString.v.x << ", " << toString.v.y << ")"; return os; } friend ostream& operator<<(ostream& os, const VECTOR3<TYPE>& toString); friend ostream& operator<<(ostream& os, const VECTOR4<TYPE>& toString); }; template <typename TYPE> union VECTOR3 { private: struct { TYPE x, y, z; } v; struct s1 { protected: TYPE x, y, z; }; struct s2 { protected: TYPE x, y, z; }; struct s3 { protected: TYPE x, y, z; }; struct s4 { protected: TYPE x, y, z; }; struct X : s1 { operator TYPE() const { return s1::x; } }; struct XX : s2 { operator VECTOR2<TYPE>() const { return VECTOR2<TYPE>(s2::x, s2::x); } }; struct XXX : s3 { operator VECTOR3<TYPE>() const { return VECTOR3<TYPE>(s3::x, s3::x, s3::x); } }; struct XXXX : s4 { operator VECTOR4<TYPE>() const { return VECTOR4<TYPE>(s4::x, s4::x, s4::x, s4::x); } }; public: VECTOR3() {} VECTOR3(const TYPE& x, const TYPE& y, const TYPE& z) { v.x = x; v.y = y; v.z = z; } X x; XX xx; XXX xxx; XXXX xxxx; // Overload for cout friend ostream& operator<<(ostream& os, const VECTOR3<TYPE>& toString) { os << "(" << toString.v.x << ", " << toString.v.y << ", " << toString.v.z << ")"; return os; } friend ostream& operator<<(ostream& os, const VECTOR2<TYPE>& toString); friend ostream& operator<<(ostream& os, const VECTOR4<TYPE>& toString); }; template <typename TYPE> union VECTOR4 { private: struct { TYPE x, y, z, w; } v; struct s1 { protected: TYPE x, y, z, w; }; struct s2 { protected: TYPE x, y, z, w; }; struct s3 { protected: TYPE x, y, z, w; }; struct s4 { protected: TYPE x, y, z, w; }; struct X : s1 { operator TYPE() const { return s1::x; } }; struct XX : s2 { operator VECTOR2<TYPE>() const { return VECTOR2<TYPE>(s2::x, s2::x); } }; struct XXX : s3 { operator VECTOR3<TYPE>() const { return VECTOR3<TYPE>(s3::x, s3::x, s3::x); } }; struct XXXX : s4 { operator VECTOR4<TYPE>() const { return VECTOR4<TYPE>(s4::x, s4::x, s4::x, s4::x); } }; public: VECTOR4() {} VECTOR4(const TYPE& x, const TYPE& y, const TYPE& z, const TYPE& w) { v.x = x; v.y = y; v.z = z; v.w = w; } X x; XX xx; XXX xxx; XXXX xxxx; // Overload for cout friend ostream& operator<<(ostream& os, const VECTOR4& toString) { os << "(" << toString.v.x << ", " << toString.v.y << ", " << toString.v.z << ", " << toString.v.w << ")"; return os; } friend ostream& operator<<(ostream& os, const VECTOR2<TYPE>& toString); friend ostream& operator<<(ostream& os, const VECTOR3<TYPE>& toString); }; // Test code int main (int argc, char * const argv[]) { vec2 my2dVector(1, 2); cout << my2dVector.x << endl; cout << my2dVector.xx << endl; cout << my2dVector.xxx << endl; cout << my2dVector.xxxx << endl; vec3 my3dVector(3, 4, 5); cout << my3dVector.x << endl; cout << my3dVector.xx << endl; cout << my3dVector.xxx << endl; cout << my3dVector.xxxx << endl; vec4 my4dVector(6, 7, 8, 9); cout << my4dVector.x << endl; cout << my4dVector.xx << endl; cout << my4dVector.xxx << endl; cout << my4dVector.xxxx << endl; return 0; } The code WORKS and produces the correct output, but I prefer warning free code whenever possible. I followed the advice the compiler gave me (summarized here and described by forums and StackOverflow as the answer to this warning) and added the two things that supposedly tells the compiler what's going on. That is, I added the function definitions as non-friends after the predefinitions of the templated unions: template <typename TYPE> ostream& operator<<(ostream& os, const VECTOR2<TYPE>& toString); template <typename TYPE> ostream& operator<<(ostream& os, const VECTOR3<TYPE>& toString); template <typename TYPE> ostream& operator<<(ostream& os, const VECTOR4<TYPE>& toString); And, to each friend function that causes the issue, I added the <> after the function name, such as for VECTOR2's case: friend ostream& operator<< <> (ostream& os, const VECTOR3<TYPE>& toString); friend ostream& operator<< <> (ostream& os, const VECTOR4<TYPE>& toString); However, doing so leads to errors, such as: LINE 139: error: no match for 'operator<<' in 'std::cout << my2dVector.VECTOR2<float>::xxx' What's going on? Is it something related to how these templated union class-like structures are interrelated, or is it due to the unions themselves? Update After rethinking the issues involved and listening to the various suggestions of Potatoswatter, I found the final solution. Unlike just about every single cout overload example on the internet, I don't need access to the private member information, but can use the public interface to do what I wish. So, I make a non-friend overload functions that are inline for the swizzle parts that call the real friend overload functions. This bypasses the issues the compiler has with templated friend functions. I've added to the latest version of my project. It now works on both versions of GCC I tried with no warnings. The code in question looks like this: template <typename SWIZZLE> inline typename EnableIf< Is2D< typename SWIZZLE::PARENT >, ostream >::type& operator<<(ostream& os, const SWIZZLE& printVector) { os << (typename SWIZZLE::PARENT(printVector)); return os; } template <typename SWIZZLE> inline typename EnableIf< Is3D< typename SWIZZLE::PARENT >, ostream >::type& operator<<(ostream& os, const SWIZZLE& printVector) { os << (typename SWIZZLE::PARENT(printVector)); return os; } template <typename SWIZZLE> inline typename EnableIf< Is4D< typename SWIZZLE::PARENT >, ostream >::type& operator<<(ostream& os, const SWIZZLE& printVector) { os << (typename SWIZZLE::PARENT(printVector)); return os; }

    Read the article

  • Retain, alloc, properties ... Topic to make your Obj-c life easier !

    - by gotye
    Hey everyone, The more I code, the more I get lost ... so I decided to create a topic entirely dedicated to the memory management for me (and others) not to waste hours understanding obj-c basics ... I'll update it as new questions are asked ! Okay below is some examples : // myArray is property (retain) myArray = otherArray; //myArray isn't a property myArray = otherArray; //myArray is a property (retain) myArray = [[NSArray alloc] init]; //myArray isn't a property myArray = [[NSArray alloc] init]; Could you explain to me what happens in every cases ? And especially the number 3 ;) Thanks for the time. Gotye.

    Read the article

  • += Overloading in C++ problem.

    - by user69514
    I am trying to overload the += operator for my rational number class, but I don't believe that it's working because I always end up with the same result: RationalNumber RationalNumber::operator+=(const RationalNumber &rhs){ int den = denominator * rhs.denominator; int a = numerator * rhs.denominator; int b = rhs.numerator * denominator; int num = a+b; RationalNumber ratNum(num, den); return ratNum; } Inside main //create two rational numbers RationalNumber a(1, 3); a.print(); RationalNumber b(6, 7); b.print(); //test += operator a+=(b); a.print(); After calling a+=(b), a is still 1/3, it should be 25/21. Any ideas what I am doing wrong?

    Read the article

  • ((System.Object)p == null)

    - by Daniel Bryars
    Why do this: // If parameter cannot be cast to Point return false. TwoDPoint p = obj as TwoDPoint; if ((System.Object)p == null) { return false; } Instead of this: // If parameter cannot be cast to Point return false. TwoDPoint p = obj as TwoDPoint; if (p == null) { return false; } I don't understand why you'd ever write ((System.Object)p)? Regards, Dan

    Read the article

  • KeyNotFound Exception in Dictionary(of T)

    - by C Patton
    I'm about ready to bang my head against the wall I have a class called Map which has a dictionary called tiles. class Map { public Dictionary<Location, Tile> tiles = new Dictionary<Location, Tile>(); public Size mapSize; public Map(Size size) { this.mapSize = size; } //etc... I fill this dictionary temporarily to test some things.. public void FillTemp(Dictionary<int, Item> itemInfo) { Random r = new Random(); for(int i =0; i < mapSize.Width; i++) { for(int j=0; j<mapSize.Height; j++) { Location temp = new Location(i, j, 0); int rint = r.Next(0, (itemInfo.Count - 1)); Tile t = new Tile(new Item(rint, rint)); tiles[temp] = t; } } } and in my main program code Map m = new Map(10, 10); m.FillTemp(iInfo); Tile t = m.GetTile(new Location(2, 2, 0)); //The problem line now, if I add a breakpoint in my code, I can clearly see that my instance (m) of the map class is filled with pairs via the function above, but when I try to access a value with the GetTile function: public Tile GetTile(Location location) { if(this.tiles.ContainsKey(location)) { return this.tiles[location]; } else { return null; } } it ALWAYS returns null. Again, if I view inside the Map object and find the Location key where x=2,y=2,z=0 , I clearly see the value being a Tile that FillTemp generated.. Why is it doing this? I've had no problems with a Dictionary such as this so far. I have no idea why it's returning null. and again, when debugging, I can CLEARLY see that the Map instance contains the Location key it says it does not... very frustrating. Any clues? Need any more info? Help would be greatly appreciated :)

    Read the article

  • Type casting Collections using Conversion Operators

    - by Vyas Bharghava
    The below code gives me User-defined conversion must convert to or from enclosing type, while snippet #2 doesn't... It seems that a user-defined conversion routine must convert to or from the class that contains the routine. What are my alternatives? Explicit operator as extension method? Anything else? public static explicit operator ObservableCollection<ViewModel>(ObservableCollection<Model> modelCollection) { var viewModelCollection = new ObservableCollection<ViewModel>(); foreach (var model in modelCollection) { viewModelCollection.Add(new ViewModel() { Model = model }); } return viewModelCollection; } Snippet #2 public static explicit operator ViewModel(Model model) { return new ViewModel() {Model = model}; } Thanks in advance!

    Read the article

  • Specifying $(this).val() for two different elements (by class)

    - by Chaya Cooper
    What would be the correct syntax for specifying 2 elements by class to evaluate their values when they have different classes? This snippet adds and/or removes values from "increase_priority1" when the user has selected both a complaint and ranked the importance level of the issue, however when I added the 2nd element (".complaint select") to the If Statement it stopped working properly and only accepts input from the 2nd item (Waist) after the 1rst item (Shoulders) has been selected. I believe the problem is that it's unable to determine which ".complaint select" to use, but I haven't been able to figure out how to use (this) for the 2nd element, or another similar approach. The complete function includes apx. 20 similar pairs of If Statements to set & unset other elements, and a working example with 4 pairs is available at http://jsfiddle.net/chayacooper/vWLEn/168/ I'm trying to avoid using ID's because that becomes pretty cumbersome to do for 25 Select elements and each of their values (ID's were also problematic because it stopped working when I added a 2nd element to the If Statement for removing/unsetting a value) Javascript var $increase_priority1 = $(".increase_priority1"); // If value is "Shoulders", complaint was Shoulders too small (select name=Shoulders value=Too_small) and it was assigned a level 1 priority (select class="ranking shoulders" value=1). // var's for other issues and priority levels go here $(".ranking, .complaint select").change(function() { var name = $(this).data("name"); //get priority name if ($(".complaint select").val() === "Too_small" && $(this).val() == 1 && !$(this).data("increase_priority1")) { //rank is 1, and not yet added to priority list $("<option>", {text:name, val:name}).appendTo($increase_priority1); $(this).data("increase_priority1", true); //flag as a priority item } if ($(this).data("increase_priority1") && ($(this).val() != 1 || $(".complaint select").val() != "Too_small")) { //is in priority list, but now demoted $("option[value=" + name + "]", $increase_priority1).remove(); $(this).removeData("increase_priority1"); //no longer a priority item } // Similar If Statements to set & unset other elements go here }); HTML <div> <label>To Increase - 1rst Priority <select name="modify_increase_1rst[]" class="increase_priority1" multiple> </select></label> </div> <div> <span class="complaint"> <label>Shoulders</label> <select name=Shoulders> <option value="null">Select</option><option value="Too_small">Too Small</option><option value="Too_big">Too Big</option><option value="Too_expensive">Too expensive</option> </select> </span> <label>Ranking</label> <select name="importance_bother_shoulders" class="ranking shoulders" data-name="Shoulders"> <option value="Null">Select</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option> <option value="5">5</option> </select> </div> <div> <span class="complaint"> <label>Waist</label> <select name=Waist> <option value="null">Select</option><option value="Too_small">Too Small</option><option value="Too_big">Too Big</option><option value="Too_expensive">Too expensive</option> </select> </span> <label>Ranking</label> <select name="importance_bother_waist" class="ranking waist" data-name="Waist"> <option value="Null">Select</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option> <option value="5">5</option> </select> </div>

    Read the article

  • Check for element equality in an animation function.

    - by Zardoz
    I have the the below code and would expect that in the first pass of the fadeTo function "yes" would be printed as those first two console logs tell me it is the same element. But it doesn't recognize them as equal. What do I miss here? var tds = self.element.find("td:nth-child(" + (columnIndex + 1) + ")"); tds.fadeTo(options.columnFadeOutTime, 0, function() { window.console.log(tds.first()); window.console.log($(this)); if ($(this) == tds.first()) { window.console.log("yes"); } else { window.console.log("no"); } }

    Read the article

  • A Linker Resolution Problem in a C++ Program

    - by Vlad
    We have two source files, a.cpp and b.cpp and a header file named constructions.h. We define a simple C++ class with the same name (class M, for instance) in each source file, respectively. The file a.cpp looks like this: #include "iostream" #include "constructions.h" class M { int i; public: M(): i( -1 ) { cout << "M() from a.cpp" << endl; } M( int a ) : i( a ) { cout << "M(int) from a.cpp, i: " << i << endl; } M( const M& b ) { i = b.i; cout << "M(M&) from a.cpp, i: " << i << endl; } M& operator = ( M& b ) { i = b.i; cout << "M::operator =(), i: " << i << endl; return *this; } virtual ~M(){ cout << "M::~M() from a.cpp" << endl; } operator int() { cout << "M::operator int() from a.cpp" << endl; return i; } }; void test1() { cout << endl << "Example 1" << endl; M b1; cout << "b1: " << b1 << endl; cout << endl << "Example 2" << endl; M b2 = 5; cout << "b2: " << b2 << endl; cout << endl << "Example 3" << endl; M b3(6); cout << "b3: " << b3 << endl; cout << endl << "Example 4" << endl; M b4 = b1; cout << "b4: " << b4 << endl; cout << endl << "Example 5" << endl; M b5; b5 = b2; cout << "b5: " << b5 << endl; } int main(int argc, char* argv[]) { test1(); test2(); cin.get(); return 0; } The file b.cpp looks like this: #include "iostream" #include "constructions.h" class M { public: M() { cout << "M() from b.cpp" << endl; } ~M() { cout << "M::~M() from b.cpp" << endl; } }; void test2() { M m; } Finally, the file constructions.h contains only the declaration of the function "test2()" (which is defined in "b.cpp"), so that it can be used in "a.cpp": using namespace std; void test2(); We compiled and linked these three files using either VS2005 or the GNU 4.1.0 compiler and the 2.16.91 ld linker under Suse. The results are surprising and different between the two build environments. But in both cases it looks like the linker gets confused about which definition of the class M it should use. If we comment out the definition of test2() from b.cpp and its invocation from a.cpp, then all the C++ objects created in test1() are of the type M defined in a.cpp and the program executes normally under Windows and Suse. Here is the run output under Windows: Example 1 M() from a.cpp M::operator int() from a.cpp b1: -1 Example 2 M(int) from a.cpp, i: 5 M::operator int() from a.cpp b2: 5 Example 3 M(int) from a.cpp, i: 6 M::operator int() from a.cpp b3: 6 Example 4 M(M&) from a.cpp, i: -1 M::operator int() from a.cpp b4: -1 Example 5 M() from a.cpp M::operator =(), i: 5 M::operator int() from a.cpp b5: 5 M::~M() from a.cpp M::~M() from a.cpp M::~M() from a.cpp M::~M() from a.cpp M::~M() from a.cpp If we enable the definition of test2() in "b.cpp" but comment out its invocation from main(), then the results are different. Under Suse, the C++ objects created in test1() are still of the type M defined in a.cpp and the program still seems to execute normally. The VS2005 versions behave differently in Debug or Release mode: in Debug mode, the program still seems to execute normally, but in Release mode, b1 and b5 are of the type M defined in b.cpp (as the constructor invocation proves), although the other member functions called (including the destructor), belong to M defined in a.cpp. Here is the run output for the executable built in Release mode: Example 1 M() from b.cpp M::operator int() from a.cpp b1: 4206872 Example 2 M(int) from a.cpp, i: 5 M::operator int() from a.cpp b2: 5 Example 3 M(int) from a.cpp, i: 6 M::operator int() from a.cpp b3: 6 Example 4 M(M&) from a.cpp, i: 4206872 M::operator int() from a.cpp b4: 4206872 Example 5 M() from b.cpp M::operator =(), i: 5 M::operator int() from a.cpp b5: 5 M::~M() from a.cpp M::~M() from a.cpp M::~M() from a.cpp M::~M() from a.cpp M::~M() from a.cpp Finally, if we allow the call to test2() from main, the program misbehaves in all circumstances (that is under Suse and under Windows in both Debug and Release modes). The Windows-Debug version finds a memory corruption around the variable m, defined in test2(). Here is the Windows output in Release mode (test2() seems to have created an instance of M defined in b.cpp): Example 1 M() from b.cpp M::operator int() from a.cpp b1: 4206872 Example 2 M(int) from a.cpp, i: 5 M::operator int() from a.cpp b2: 5 Example 3 M(int) from a.cpp, i: 6 M::operator int() from a.cpp b3: 6 Example 4 M(M&) from a.cpp, i: 4206872 M::operator int() from a.cpp b4: 4206872 Example 5 M() from b.cpp M::operator =(), i: 5 M::operator int() from a.cpp b5: 5 M::~M() from a.cpp M::~M() from a.cpp M::~M() from a.cpp M::~M() from a.cpp M::~M() from a.cpp M() from b.cpp M::~M() from b.cpp And here is the Suse output. The objects created in test1() are of the type M defined in a.cpp but the object created in test2() is also of the type M defined in a.cpp, unlike the object created under Windows which is of the type M defined in b.cpp. The program crashed in the end: Example 1 M() from a.cpp M::operator int() from a.cpp b1: -1 Example 2 M(int) from a.cpp, i: 5 M::operator int() from a.cpp b2: 5 Example 3 M(int) from a.cpp, i: 6 M::operator int() from a.cpp b3: 6 Example 4 M(M&) from a.cpp, i: -1 M::operator int() from a.cpp b4: -1 Example 5 M() from a.cpp M::operator =(), i: 5 M::operator int() from a.cpp b5: 5 M::~M() from a.cpp M::~M() from a.cpp M::~M() from a.cpp M::~M() from a.cpp M::~M() from a.cpp M() from a.cpp M::~M() from a.cpp Segmentation fault (core dumped) I couldn't make the angle brackets appear using Markdown, so I used quotes around the header file name iostream. Otherwise, the code could be copied verbatim and tried. It is purely scholastic. The statement cin.get() at the end of main() was included just to facilitate running the program directly from VS2005 (cause it to display the output window until we could analyze the output). We are looking for a software engineer in Sunnyvale, CA and may offer that position to the programmer capable of providing an intelligent and comprehensive explanation of these anomalies. I can be contacted at [email protected].

    Read the article

  • LINQ To SQL exception: Local sequence cannot be used in LINQ to SQL implementation of query operator

    - by pcampbell
    Consider this LINQ To SQL query. It's intention is to take a string[] of search terms and apply the terms to a bunch of different fields on the SQL table: string[] searchTerms = new string[] {"hello","world","foo"}; List<Cust> = db.Custs.Where(c => searchTerms.Any(st => st.Equals(c.Email)) || searchTerms.Any(st => st.Equals(c.FirstName)) || searchTerms.Any(st => st.Equals(c.LastName)) || searchTerms.Any(st => st.Equals(c.City)) || searchTerms.Any(st => st.Equals(c.Postal)) || searchTerms.Any(st => st.Equals(c.Phone)) || searchTerms.Any(st => c.AddressLine1.Contains(st)) ) .ToList(); An exception is raised: Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator Question: Why is this exception raised, and how can the query be rewritten to avoid this exception?

    Read the article

  • Generated SQL with PredicateBuilder, LINQPad and operator ANY

    - by Sig. Tolleranza
    I previously asked a question about chaining conditions in Linq To Entities. Now I use LinqKit and everything works fine. I want to see the generated SQL and after reading this answer, I use LinqPad. This is my statement: var predProduct = PredicateBuilder.True<Product>(); var predColorLanguage = PredicateBuilder.True<ColorLanguage>(); predProduct = predProduct.And(p => p.IsComplete); predColorLanguage = predColorLanguage.And(c => c.IdColorEntity.Products.AsQueryable().Any(expr)); ColorLanguages.Where(predColorLanguage).Dump(); The code works in VS2008, compile and produce the correct result set, but in LinqPad, I've the following error: NotSupportedException: The overload query operator 'Any' used is not Supported. How can I see the generated SQL if LINQPad fails?

    Read the article

  • operator not defined for System.Data.SqlClient.SqlConnection and System.Data.SqlClient.SqlConnection

    - by Beta033
    i hope i'm just doing something wrong here. Ideally i'm trying to open the connection, open a transaction execute a ton of prebuilt sqlstatements (with parameters) against this connection then close the connection. ideally all in the same batch. It's easy enough to wrap this all in a for loop, however i'd like to use the forEach function of the list generic to set the connection as it'll probably be faster than my implementation of calling List.Item(i) in the loop but i get some strange errors. Dim sqlStatements As List(Of SqlCommand) = New List(Of SqlCommand) Dim conn As SqlClient.SqlConnection = New SqlConnection("...") sqlStatements.Item(0).Connection = conn 'Works sqlStatements.ForEach(Function(ByRef cmd As SqlCommand) cmd.Connection = conn) 'ERROR: Operator '=' is not defined for types 'System.Data.SqlClient.SqlConnection' 'and 'System.Data.SqlClient.SqlConnection What does this error really mean?

    Read the article

  • C# LINQ to SQL Except Operator

    - by kb
    Hi i have a list of event Ids that i want to be excluded from my select statement, but no sure how to implement this: this is what stores my list of event Ids List<int> ExcludedEvents; and this is my select statement (from an XML feed) var allEvents = from eventsList in xmlDoc.Elements("shows").Elements("Show") select new EventFeed() { EventName = eventsList.Attribute("Name").Value, EventSummary = eventsList.Attribute("ShortDesc").Value, EventDetails = eventsList.Attribute("LongDesc").Value, EventShowCode = eventsList.Attribute("Code").Value }; i want to select all events except for the events that have their eventId matching the EventShowCode value i have looked at the except operator, but not sure how to implement it thanks

    Read the article

  • Perl file test operator help

    - by Aaron Moodie
    This is a really basic issue, but I'm new to perl and cannot work out what the issue is. I'm just trying to isolate the files in a directory, but the -d operator keeps treating all the folder contents as files ... @contents is my array, and when I run this: foreach $item(@contents) { if (-d $item) { next; } print"$item is a file\n"; } I keep getting both folders and files. Alternatively, if I use -f, I get nothing. edit: this is the output - file01.txt is a file folder 01 is a file folder 02 is a file Screen shot 2010-04-18 at 1.26.17 PM.png is a file I'm running this on OSX

    Read the article

  • Prototype Library use of !! operator

    - by Rajat
    Here is a snippet from Prototype Javascript Library : Browser: (function(){ var ua = navigator.userAgent; var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]'; return { IE: !!window.attachEvent && !isOpera, Opera: isOpera, WebKit: ua.indexOf('AppleWebKit/') > -1, Gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1, MobileSafari: /Apple.*Mobile/.test(ua) } })(), This is all good and i understand the objective of creating a browser object. One thing that caught my eye and I haven't been able to figure out is the use of double not operator !! in the IE property. If you read through the code you will find it at many other places. I dont understand whats the difference between !!window.attachEvent and using just window.attachEvent. Is it just a convention or is there more to it that's not obvious?

    Read the article

  • std::string == operator not working

    - by Paul
    Hello, I've been using std::string's == operator for years on windows and linux. Now I am compiling one of my libraries on linux, it uses == heavily. On linux the following function fails, because the == returns false even when the strings are equal (case sensitive wise equal) const Data* DataBase::getDataByName( const std::string& name ) const { for ( unsigned int i = 0 ; i < m_dataList.getNum() ; i++ ) { if ( m_dataList.get(i)->getName() == name ) { return m_dataList.get(i); } } return NULL; } The getName() method is declared as follows virtual const std::string& getName() const; I am building with gcc 4.4.1 and libstdc++44-4.4.1. Any ideas? it looks perfectly valid to me. Paul

    Read the article

  • What's the purpose of having a separate "operator new[]" ?

    - by sharptooth
    Looks like operator new and operator new[] have exactly the same signature: void* operator new( size_t size ); void* operator new[]( size_t size ); and do exactly the same: either return a pointer to a big enough block of raw (not initialized in any way) memory or throw an exception. Also operator new is called internally when I create an object with new and operator new[] - when I create an array of objects with new[]. Still the above two special functions are called by C++ internally in exactly the same manner and I don't se how the two calls can have different meanings. What's the purpose of having two different functions with exactly the same signatures and exactly the same behavior?

    Read the article

  • Parallel Assignment operator in Ruby

    - by Bragaadeesh
    Hi, I was going through an example from Programming in Ruby book. This is that example def fib_up_to(max) i1, i2 = 1, 1 # parallel assignment (i1 = 1 and i2 = 1) while i1 <= max yield i1 i1, i2 = i2, i1+i2 end end fib_up_to(100) {|f| print f, " " } The above program simply prints the fibonacci numbers upto 100. Thats fine. My question here is when i replace the parallel assignment with something like this, i1 = i2 i2 = i1+i2 I am not getting the desired output. My question here is, is it advisable to use parallel assignments? (I come from Java background and it feels really wierd to see this type of assignment) One more doubt is : Is parallel assignment an operator?? Thanks

    Read the article

  • The data types text and nvarchar are incompatible in the equal to operator

    - by metro
    Hi there. this is my code ProductController.cs public ActionResult Details(string id) { product productx = productDB.products.Single(pr => pr.Product1 == id); return View(productx); } Details.aspx <td> <%-- : Html.ActionLink("Edit", "Edit", new { id=item.Id }) % --> <%: Html.ActionLink("Details", "Details", new { id = item.Product1 })%> </td> this is what im using to list some products from a sql database, each product have a link to a Details page to show more informations about it what Im trying is to only put the product label in that link to let it show something like www.mysite.com\products\battery (not the id) I've imagined this should work, but it throw an The data types text and nvarchar are incompatible in the equal to operator. error and neither (pr => pr.Product1.Equals(id)); works the error is clear and Im asking how should I do to make it work this way ? thanks

    Read the article

  • regarding like query operator

    - by stackoverflowuser
    Hi For the below data (well..there are many more nodes in the team foundation server table which i need to refer to..below is just a sample) Nodes ------------------------ \node1\node2\node3\ \node1\node2\node5\ \node1\node2\node3\node4 I was wondering if i can apply something like (below query does not give the required results) select * from table_a where nodes like '\node1\node2\%\' to get the below data \node1\node2\node3\ \node1\node2\node5\ and something like (below does not give the required results) select * from table_a where nodes like '\node1\node2\%\%\' to get \node1\node2\node3\ \node1\node2\node5\ \node1\node2\node3\node4 Can the above be done with like operator? Pls. suggest. Thanks

    Read the article

  • Overriding rubies spaceship operator <=>

    - by ericsteen1
    I am trying to override rubies <= (spaceship) operator to sort apples and oranges so that apples come first sorted by weight, and oranges second, sorted by sweetness. Like so: module Fruity attr_accessor :weight, :sweetness def <=>(other) # use Array#<=> to compare the attributes [self.weight, self.sweetness] <=> [other.weight, other.sweetness] end include Comparable end class Apple include Fruity def initialize(w) self.weight = w end end class Orange include Fruity def initialize(s) self.sweetness = s end end fruits = [Apple.new(2),Orange.new(4),Apple.new(6),Orange.new(9),Apple.new(1),Orange.new(22)] p fruits #should work? p fruits.sort But this does not work, can someone tell what I am doing wrong here, or a better way to do this?

    Read the article

  • Does replacing statements by expressions using the C++ comma operator could allow more compiler opti

    - by Gabriel Cuvillier
    The C++ comma operator is used to chain individual expressions, yielding the value of the last executed expression as the result. For example the skeleton code (6 statements, 6 expressions): step1; step2; if (condition) step3; return step4; else return step5; May be rewritten to: (1 statement, 6 expressions) return step1, step2, condition? step3, step4 : step5; I noticed that it is not possible to perform step-by-step debugging of such code, as the expression chain seems to be executed as a whole. Does it means that the compiler is able to perform special optimizations which are not possible with the traditional statement approach (specially if the steps are const or inline)? Note: I'm not talking about the coding style merit of that way of expressing sequence of expressions! Just about the possible optimisations allowed by replacing statements by expressions.

    Read the article

< Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >