Search Results

Search found 2508 results on 101 pages for 'ternary operator'.

Page 26/101 | < Previous Page | 22 23 24 25 26 27 28 29 30 31 32 33  | Next Page >

  • C++ operator[ ] on integer litteral

    - by gregseth
    I found this piece of code: char a = 1["ABC"]; A few quick test led me to the fact it was the same than writing: char a = "ABC"[1]; Which seems far more logical to me. So my questions: Why is this notation valid? Is there any reason to write something that way?

    Read the article

  • INSERT INTO ...SELECT syntax error in join operator

    - by user1477356
    I'm trying to write a shopping basket into a order + orderline in a sql database from C# asp.net. the orderline will contain a ordernumber, total price, productid, quantity etc. for every item in the basket. The order itself will contain the ordernumber as primary key and will be linked to the different lines through it. Everything worked fine yesterday, but now as i tried to use a SELECT command in the insert into statement to get things more dynamic i'm getting the above described syntax error. Does anybody know what's wrong with this statement: INSERT INTO [order] (klant_id,totaalprijs,btw,subtotaal,verzendkosten) SELECT klant.id , SUM(orderregel.totaalprijs) , SUM(orderregel.btw) , SUM(orderregel.totaalprijs) - SUM(orderregel.btw) , 7.50 FROM orderregel INNER JOIN klant ON [order].klant_id = klant.id WHERE klant.username = 'jerry' GROUP BY id; the ordernumber in the "order" table is on autonumber, in the asp codebehind there is a for each which handles the lines being written for every product, there's an index set on 0 outside of this loop and is heightened with 1 every end of it. The executenonquery of the order is only executed once at the beginning of the first loop and the lines are added after with MAX(ordernumber) as ordernumber. I hope i have provided enough information and somebody is capable of helping me. Thanks in advance!

    Read the article

  • Assignment in conditional operator

    - by DuoSRX
    I've seen a lot this kind of code recently : if ($foo = $bar->getFoo()) { baz($foo); } Is this considered good or bad practice ? For example, Netbeans IDE give a notice if you use this kind of code : Possible accidental assignment, assignments in conditions should be avoided What do you think ?

    Read the article

  • Is tertiary operator possible here?

    - by silow
    I'm trying to set $value1, $value2, $value3 entirely using tertiary operators. This is what it looks like without tertiary if ($chk1 == 20) { $value1 = true; if ($chk2 == 40) { $value2 = 100 ; $value3 = 300; } else { $value2 = 200 ; $value3 = 400; } } else { $value1 = false; } I can set $value2 and $value3, but not sure how to set $value1. Can it be done? if ($chk1 == 20) { $value1 = true; $value2 = ($chk2 == 40) ? 100 : 200; $value3 = ($chk2 == 40) ? 300 : 400; } else { $value1 = false; }

    Read the article

  • Operator & and * at function prototype in class

    - by Puyover
    I'm having a problem with a class like this: class Sprite { ... bool checkCollision(Sprite &spr); ... }; So, if I have that class, I can do this: ball.checkCollision(bar1); But if I change the class to this: class Sprite { ... bool checkCollision(Sprite* spr); ... }; I have to do this: ball.checkCollision(&bar1); So, what's the difference?? It's better a way instead other? Thank you.

    Read the article

  • Factory Method Using Is/As Operator

    - by Swim
    I have factory that looks something like the following snippet. Foo is a wrapper class for Bar and in most cases (but not all), there is a 1:1 mapping. As a rule, Bar cannot know anything about Foo, yet Foo takes an instance of Bar. Is there a better/cleaner approach to doing this? public Foo Make( Bar obj ) { if( obj is Bar1 ) return new Foo1( obj as Bar1 ); if( obj is Bar2 ) return new Foo2( obj as Bar2 ); if( obj is Bar3 ) return new Foo3( obj as Bar3 ); if( obj is Bar4 ) return new Foo3( obj as Bar4 ); // same wrapper as Bar3 throw new ArgumentException(); } At first glance, this question might look like a duplicate (maybe it is), but I haven't seen one exactly like it. Here is one that is close, but not quite: http://stackoverflow.com/questions/242097/factory-based-on-typeof-or-is-a

    Read the article

  • Java print binary number using bit-wise operator

    - by user69514
    Hi I am creating a method that will take a number and print it along with its binary representation. The problems is that my method prints all 0's for any positive number, and all 1's for any negative number private static void display( int number ){ System.out.print(number + "\t"); int mask = 1 << 31; for(int i=1; i<=32; i++) { if( (mask & number) != 0 ) System.out.print(1); else System.out.print(0); if( (i % 4) == 0 ) System.out.print(" "); } }

    Read the article

  • Perl need the right grep operator to match value of variable

    - by iaintunderstand
    I want to see if I have repeated items in my array, there are over 16.000 so will automate it There may be other ways but I started with this and, well, would like to finish it unless there is a straightforward command. What I am doing is shifting and pushing from one array into another and this way, check the destination array to see if it is "in array" (like there is such a command in PHP). So, I got this sub routine and it works with literals, but it doesn't with variables. It is because of the 'eq' or whatever I should need. The 'sourcefile' will contain one or more of the words of the destination array. my @destination = ('hi', 'bye'); sub in_array { my ($destination,$search_for) = @_; return grep {$search_for eq $_} @$destination; } for($i = 0; $i <=100; $i ++) { $elemento = shift @sourcefile; if(in_array(\@destination, $elemento)) { print "it is"; } else { print "it aint there"; } } Well, if instead of including the $elemento in there I put a 'hi' it does work and also I have printed the value of $elemento which is also 'hi', but when I put the variable, it does not work, and that is because of the 'eq', but I don't know what else to put. If I put == it complains that 'hi' is not a numeric value.

    Read the article

  • Is there a %in% operator accros multiple columns

    - by RobinLovelace
    Imagine you have two data frames df1 <- data.frame(V1 = c(1, 2, 3), v2 = c("a", "b", "c")) df2 <- data.frame(V1 = c(1, 2, 2), v2 = c("b", "b", "c")) Here's what they look like, side by side: > cbind(df1, df2) V1 v2 V1 v2 1 1 a 1 b 2 2 b 2 b 3 3 c 2 c You want to know which observations are duplicates, across all variables. This can be done by pasting the cols together and then using %in%: df1Vec <- apply(df1, 1, paste, collapse= "") df2Vec <- apply(df2, 1, paste, collapse= "") df2Vec %in% df1Vec [1] FALSE TRUE FALSE The second observation is thus the only one in df2 and also in df1. Is there no faster way of generating this output - something like %IN%, which is %in% across multiple variables, or should we just be content with the apply(paste) solution?

    Read the article

  • '<=' operator is not working in sql server 2000

    - by Lalit
    Hello, Scenario is, database is in the maintenance phase. this database is not developed by ours developer. it is an existing database developed by the 'xyz' company in sql server 2000. This is real time database, where i am working now. I wanted to write the stored procedure which will retrieve me the records From date1 to date 2.so query is : Select * from MyTableName Where colDate>= '3-May-2010' and colDate<= '5-Oct-2010' and colName='xyzName' whereas my understanding I must get data including upper bound date as well as lower bound date. but somehow I am getting records from '3-May-2010' (which is fine but) to '10-Oct-2010' As i observe in table design , for ColDate, developer had used 'varchar' to store the date. i know this is wrong remedy by them. so in my stored procedure I have also used varchar parameters as @FromDate1 and @ToDate to get inputs for SP. this is giving me result which i have explained. i tried to take the parameter type as 'Datetime' but it is showing error while saving/altering the stored procedure that "@FromDate1 has invalid datatype", same for "@ToDate". situation is that, I can not change the table design at all. what i have to do here ? i know we can use user defined table in sql server 2008 , but there is version sql server 2000. which does not support the same. Please guide me for this scenario. **Edited** I am trying to write like this SP: CREATE PROCEDURE USP_Data (@Location varchar(100), @FromDate DATETIME, @ToDate DATETIME) AS SELECT * FROM dbo.TableName Where CAST(Dt AS DATETIME) >=@fromDate and CAST(Dt AS DATETIME)<=@ToDate and Location=@Location GO but getting Error: Arithmetic overflow error converting expression to data type datetime. in sql server 2000 What should be that ? is i am wrong some where ? also (202 row(s) affected) is changes every time in circular manner means first time sayin (122 row(s) affected) run again saying (80 row(s) affected) if again (202 row(s) affected) if again (122 row(s) affected) I can not understand what is going on ?

    Read the article

  • CSS: "AND" and + operator?

    - by de.vina
    I want to put a space after all the headers using CSS. Like this: if h1 = add a space after else if h1 + h2 = add a space after also but no space in between This is my HTML code <article> <h1>Title 1</h1> ... </article> <article> <h1>Title 1</h1> <h2>Title 2</h2> ... </article> For the CSS h1, h2 { padding-bottom: 20px; } The problem is, there is a space also between h1 and h2. I tried this code below but only those articles with h1 and h2 have a space after. h1 + h2 { padding-bottom: 20px;} Is there a way to do this? Or I should just use the h1 + h2 in CSS and add < br for h1 only?

    Read the article

  • Optimizing MySQL queries with IN operator

    - by Arkadiusz Kondas
    I have a MySQL database with a fairly large table where the products are. Each of them has its own id and categoryId field where there is a category id belongs to this product. Now I have a query that pulls out products from given categories such as: SELECT * FROM products WHERE categoryId IN ( 1, 2, 3, 4, 5, 34, 6, 7, 8, 9, 10, 11, 12 ) Of course, come a WHERE clause and ORDER BY sort but not in this thing. Let's say that these products is 250k and the visits are over 100k per day. Under such conditions in the table slow_log registered weight of these queries with large generation time. Do you have any ideas how to optimize the given problem? Table engine is MyISAM.

    Read the article

  • Changing the values of a class returned by the array [] operator

    - by devdept
    The question is: at the end of this code the value of ptArray[0].X is 3.33 or 1.11? Thanks. class MyPoint { public double X, Y; public MyPoint(double x, double y) { X = x; Y = y; } } MyPoint[] ptArray = new MyPoint[2]; ptArray[0] = new MyPoint(1.11, 2.22); MyPoint first = ptArray[0]; // Am I changing ptArray[0] here or not? first.X = 3.33; first.Y = 4.44;

    Read the article

  • <hash_set> equality operator doesn't work in VS2010

    - by ProgramWriter
    Sample code: std::hash_set<int> hs1; // also i try std::unorded_set<int> - same effect std::hash_set<int> hs2; hs1.insert(15); hs1.insert(20); hs2.insert(20); hs2.insert(15); assert(hs1 == hs2); hash_set doesn't stores elements in some order defined by hash function... why? Please note that this code works in VS2008 using stdext::hash_set.

    Read the article

  • Operator & and * at function prototipe in class

    - by Puyover
    I'm having a problem with a class like this: class Sprite { ... bool checkCollision(Sprite &spr); ... }; So, if I have that clase, I can do this: ball.checkCollision(bar1); But if I change the class to this: class Sprite { ... bool checkCollision(Sprite* spr); ... }; I have to do this: ball.checkCollision(&bar1); So, what's the difference?? It's better a way instead other? Thank you.

    Read the article

  • Overloading the QDataStream << and >> operators for a user-defined type

    - by Alex Wood
    I have a an object I'd like to be able to read and write to/from a QDataStream. The header is as follows: class Compound { public: Compound(QString, QPixmap*, Ui::MainWindow*); void saveCurrentInfo(); void restoreSavedInfo(QGraphicsScene*); void setImage(QPixmap*); QString getName(); private: QString name, homeNotes, addNotes, expText; Ui::MainWindow *gui; QPixmap *image; struct NMRdata { QString hnmrText, cnmrText, hn_nmrText, hn_nmrNucl, notes; int hnmrFreqIndex, cnmrFreqIndex, hn_nmrFreqIndex, hnmrSolvIndex, cnmrSolvIndex, hn_nmrSolvIndex; }*nmr_data; struct IRdata { QString uvConc, lowResMethod, irText, uvText, lowResText, highResText, highResCalc, highResFnd, highResFrmla, notes; int irSolvIndex, uvSolvIndex; }*ir_data; struct PhysicalData { QString mpEdit, bpEdit, mpParensEdit, bpParensEdit, rfEdit, phyText, optAlpha, optConc, elemText, elemFrmla, notes; int phySolvIndex, optSolvIndex; }*physical_data; }; For all intensive purposes, the class just serves as an abstraction for a handful of QStrings and a QPixmap. Ideally, I would be able to write a QList to a QDataStream but I'm not exactly sure how to go about doing this. If operator overloading is a suitable solution, would writing code like friend QDataStream& operator << (QDataStream&,Compound) { ... } be a potential solution? I'm very open to suggestions! Please let me know if any further clarification is needed.

    Read the article

  • Declaring functors for comparison ??

    - by Mr.Gando
    Hello, I have seen other people questions but found none that applied to what I'm trying to achieve here. I'm trying to sort Entities via my EntityManager class using std::sort and a std::vector<Entity *> /*Entity.h*/ class Entity { public: float x,y; }; struct compareByX{ bool operator()(const GameEntity &a, const GameEntity &b) { return (a.x < b.x); } }; /*Class EntityManager that uses Entitiy*/ typedef std::vector<Entity *> ENTITY_VECTOR; //Entity reference vector class EntityManager: public Entity { private: ENTITY_VECTOR managedEntities; public: void sortEntitiesX(); }; void EntityManager::sortEntitiesX() { /*perform sorting of the entitiesList by their X value*/ compareByX comparer; std::sort(entityList.begin(), entityList.end(), comparer); } I'm getting a dozen of errors like : error: no match for call to '(compareByX) (GameEntity* const&, GameEntity* const&)' : note: candidates are: bool compareByX::operator()(const GameEntity&, const GameEntity&) I'm not sure but ENTITY_VECTOR is std::vector<Entity *> , and I don't know if that could be the problem when using the compareByX functor ? I'm pretty new to C++, so any kind of help is welcome.

    Read the article

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