Search Results

Search found 4088 results on 164 pages for 'params keyword'.

Page 22/164 | < Previous Page | 18 19 20 21 22 23 24 25 26 27 28 29  | Next Page >

  • C# Dynamic Keyword exception handling

    - by user972255
    The below code throws an exception when executing this line (i.e. something.Add(name)). I want to catch the actual exception when executing this. I mean I don't want to use catch(Exception ex) instead of that I want to know what is the correct exception thrown here. try { dynamic name= "test"; var something = new List<decimal>(); something.Add(name); } catch(Exception ex) { throw ex; } Thanks in advance.

    Read the article

  • can this keyword be used in an abstract class in java

    - by Reddy
    I tried with below example, it is working fine. I expected it to pick sub-class's value since object won't be created for super class (as it is abstract). But it is picking up super class's field value only. Please help me understand what is the concepts behind this? abstract class SuperAbstract { private int a=2; public void funA() { System.out.println("In SuperAbstract: this.a "+a); } } class SubClass extends SuperAbstract { private int a=34; } I am calling new SubClass.funA(); I am expecting it to print 34, but it is printing 2.

    Read the article

  • Keyword sorting algorithm

    - by Nai
    I have over 1000 surveys, many of which contains open-ended replies. I would like to be able to 'parse' in all the words and get a ranking of the most used words (disregarding common words) to spot a trend. How can I do this? Is there a program I can use? EDIT If a 3rd party solution is not available, it would be great if we can keep the discussion to microsoft technologies only. Cheers.

    Read the article

  • can the keyword 'this' be used in an abstract class in java

    - by Reddy
    I tried with below example, it is working fine. I expected it to pick sub-class's value since object won't be created for super class (as it is abstract). But it is picking up super class's field value only. Please help me understand what is the concepts behind this? abstract class SuperAbstract { private int a=2; public void funA() { System.out.println("In SuperAbstract: this.a "+a); } } class SubClass extends SuperAbstract { private int a=34; } I am calling new SubClass.funA(); I am expecting it to print 34, but it is printing 2.

    Read the article

  • Use a function in a conditions hash

    - by Pierre
    Hi, I'm building a conditions hash to run a query but I'm having a problem with one specific case: conditions2 = ['extract(year from signature_date) = ?', params[:year].to_i] unless params[:year].blank? conditions[:country_id] = COUNTRIES.select{|c| c.geography_id == params[:geographies]} unless params[:geographies].blank? conditions[:category_id] = CATEGORY_CHILDREN[params[:categories].to_i] unless params[:categories].blank? conditions[:country_id] = params[:countries] unless params[:countries].blank? conditions['extract(year from signature_date)'] = params[:year].to_i unless params[:year].blank? But the last line breaks everything, as it gets interpreted as follows: AND ("negotiations"."extract(year from signature_date)" = 2010 Is there a way to avoid that "negotiations"." is prepended to my condition? thank you, P.

    Read the article

  • Volatile keyword

    - by Tiyoal
    Say I have two threads and an object. One thread assigns the object: public void assign(MyObject o) { myObject = o; } Another thread uses the object: public void use() { myObject.use(); } Does the variable myObject have to be declared as volatile? I am trying to understand when to use volatile and when not, and this is puzzling me. Is it possible that the second thread keeps a reference to an old object in its local memory cache? If not, why not? Thanks a lot.

    Read the article

  • const keyword in Objective-c

    - by user392412
    int main(int argc, char *argv[]) { @autoreleasepool { const int x = 1; const NSMutableArray *array1 = [NSMutableArray array]; const NSMutableString *str1 = @"1"; NSString * const str2 = @"2"; // x = 2; compile error [array1 addObject:@"2"]; // ok // [str1 appendString:@"2"]; // runtime error // Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with appendString:' // str2 = @"3"; compile error } } my Question is Why array1 addObject is legal and why str1 appendString is forbidden?

    Read the article

  • the use of private keyword

    - by LAT
    Hi everyone I am new to programming. I am learning Java now, there is something I am not really sure, that the use of private. Why programmer set the variable as private then write , getter and setter to access it. Why not put everything in public since we use it anyway. public class BadOO { public int size; public int weight; ... } public class ExploitBadOO { public static void main (String [] args) { BadOO b = new BadOO(); b.size = -5; // Legal but bad!! } } I found some code like this, and i saw the comment legal but bad. I don't understand why, please explain me.

    Read the article

  • Mystery in Ruby sinatra

    - by JVK
    I have the following Sinatra code: post '/bucket' do # determine if this call is coming from filling out web form is_html = request.content_type.to_s.downcase.eql?('application/x-www-form-urlencoded') # If this is a curl call, then get the params differently unless is_html params = JSON.parse(request.env["rack.input"].read) end p params[:name] end If I call this using Curl, params has values, but when this is called via a web form, then params is nil and params[:name] has nothing. I spent several hours figuring out why it happens and asked help from other people, but no one could really find out what is going on. One thing to note is, if I comment out this line: params = JSON.parse(request.env["rack.input"].read) then params has the correct value for "web-form" posting. Actually, the goal is to get the params value if this code is being called by CURL call, so I used: params = JSON.parse(request.env["rack.input"].read) but it messed up the web-form posting. Can anyone solve this mystery?

    Read the article

  • Multiple uses of "this" keyword in Java

    - by frodosamoa
    So, I have this. It compares two card decks and if they are the same the result is true. public boolean equals ( Object obj ) { boolean result = true; for (int i = 0; i < 52; i++) { if (this.cardAt(i) = this2.cardlist(i)) { result = true; } else { result = false; } } } I would like to be able to compare two random card decks, if you will. But I don't know how to compare two different ones using "this . I simply wrote "this2" to replace another instance of "this". What could I do to replace this "this2" to still be able to compare two card decks?

    Read the article

  • What does the `new` keyword do

    - by Mike
    I'm following a Java tutorial online, trying to learn the language, and it's bouncing between two semantics for using arrays. long results[] = new long[3]; results[0] = 1; results[1] = 2; results[2] = 3; and: long results[] = {1, 2, 3}; The tutorial never really mentioned why it switched back and forth between the two so I searched a little on the topic. My current understanding is that the new operator is creating an object of "array of longs" type. What I do not understand is why do I want that, and what are the ramifications of that? Are there certain "array" specific methods that won't work on an array unless it's an "array object"? Is there anything that I can't do with an "array object" that I can do with a normal array? Does the Java VM have to do clean up on objects initialized with the new operator that it wouldn't normally have to do? I'm coming from C, so my Java terminology, may not be correct here, so please ask for clarification if something's not understandable.

    Read the article

  • How to make Horde connect to mysql with UTF-8 character set?

    - by jkj
    How to tell horde 3.3.11 to use UTF-8 for it's mysql connection? The $conf['sql']['charset'] only tells horde what is expected from the database. Horde uses MDB2 to connect to mysql. Is there way to force MDB2 or mysql character_set_client from php.ini? So far I found two workarounds: Force mysql to ignore character set requested by client [mysqld] skip-character-set-client-handshake=1 default-character-set=utf8 Force mysql to run SET NAMES utf8 on every connection [mysqld] init-connect='SET NAMES utf8' Both have drawbacks on multi user mysql server. The first disables converting character sets alltogether and the second one forces every connection to produce UTF-8. [EDIT] Found the problem. The 'charset' parameter was unset the last minute before sending to SQL backend. This is probably due to mysql not being able to digest utf-8 but utf8. Mysql specific mapping is required to make it work. I just worked around it by translating utf-8 - utf8. Won't work with any other databases with this patch though. --- lib/Horde/Share/sql.php.orig 2011-07-04 17:09:33.349334890 +0300 +++ lib/Horde/Share/sql.php 2011-07-04 17:11:06.238636462 +0300 @@ -753,7 +753,13 @@ /* Connect to the sql server using the supplied parameters. */ require_once 'MDB2.php'; $params = $this->_params; - unset($params['charset']); + + if ($params['charset'] == 'utf-8') { + $params['charset'] = 'utf8'; + } else { + unset($params['charset']); + } + $this->_write_db = &MDB2::factory($params); if (is_a($this->_write_db, 'PEAR_Error')) { Horde::fatal($this->_write_db, __FILE__, __LINE__); @@ -792,7 +798,13 @@ /* Check if we need to set up the read DB connection seperately. */ if (!empty($this->_params['splitread'])) { $params = array_merge($params, $this->_params['read']); - unset($params['charset']); + + if ($params['charset'] == 'utf-8') { + $params['charset'] = 'utf8'; + } else { + unset($params['charset']); + } + $this->_db = &MDB2::singleton($params); if (is_a($this->_db, 'PEAR_Error')) { Horde::fatal($this->_db, __FILE__, __LINE__);

    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

  • 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

  • scala for yield setting a value

    - by coubeatczech
    Hi, I want to create a list of GridBagPanel.Constraints. I read it in the scala programming book, that there is a cool for-yield construction, but I probably haven't understood the way it works correctly, because my code doesn't compile. Here it is: val d = for { i <- 0 until 4 j <- 0 until 4 } yield { c = new Constraints c.gridx = j c.gridy = i } I want to generate a List[Constraints] and for every constraint set different x,y values so later, when I later add the components, they're going to be in a grid.

    Read the article

  • How to modify a given class to use const operators

    - by zsero
    I am trying to solve my question regarding using push_back in more than one level. From the comments/answers it is clear that I have to: Create a copy operator which takes a const argument Modify all my operators to const But because this header file is given to me there is an operator what I cannot make into const. It is a simple: float & operator [] (int i) { return _item[i]; } In the given program, this operator is used to get and set data. My problem is that because I need to have this operator in the header file, I cannot turn all the other operators to const, what means I cannot insert a copy operator. How can I make all my operators into const, while preserving the functionality of the already written program? Here is the full declaration of the class: class Vector3f { float _item[3]; public: float & operator [] (int i) { return _item[i]; } Vector3f(float x, float y, float z) { _item[0] = x ; _item[1] = y ; _item[2] = z; }; Vector3f() {}; Vector3f & operator = ( const Vector3f& obj) { _item[0] = obj[0]; _item[1] = obj[1]; _item[2] = obj[2]; return *this; }; Vector3f & operator += ( const Vector3f & obj) { _item[0] += obj[0]; _item[1] += obj[1]; _item[2] += obj[2]; return *this; }; bool operator ==( const Vector3f & obj) { bool x = (_item[0] == obj[0]) && (_item[1] == obj[1]) && (_item[2] == obj[2]); return x; } // my copy operator Vector3f(const Vector3f& obj) { _item[0] += obj[0]; _item[1] += obj[1]; _item[2] += obj[2]; return this; } };

    Read the article

  • Can operator<< in derived class call another operator<< in base class in c++?

    - by ivory
    In my code, Manager is derived from Employee and each of them have an operator<< override. class Employee{ protected: int salary; int rank; public: int getSalary()const{return salary;} int getRank()const{return rank;} Employee(int s, int r):salary(s), rank(r){}; }; ostream& operator<< (ostream& out, Employee& e){ out << "Salary: " << e.getSalary() << " Rank: " << e.getRank() << endl; return out; } class Manager: public Employee{ public: Manager(int s, int r): Employee(s, r){}; }; ostream& operator<< (ostream& out, Manager& m){ out << "Manager: "; cout << (Employee)m << endl; //can not compile, how to call function of Employee? return out; } I hoped cout << (Employee)m << endl; would call ostream& operator<< (ostream& out, Employee& e), but it failed.

    Read the article

  • How to define a static operator<<?

    - by Pietro M
    Is it possible to define a static insertion operator which operates on the static members of a class only? Something like: class MyClass { public: static std::string msg; static MyClass& operator<< (const std::string& token) { msg.append(token); return *this; // error, static } }; alternatively: static MyClass& operator<< (MyClass&, const std::string &token) { MyClass::msg.append(token); return ?; } This is how I would like to use it: MyClass << "message1" << "message2"; Thank you!

    Read the article

  • Providing less than operator for one element of a pair

    - by Koszalek Opalek
    What would be the most elegant way too fix the following code: #include <vector> #include <map> #include <set> using namespace std; typedef map< int, int > row_t; typedef vector< row_t > board_t; typedef row_t::iterator area_t; bool operator< ( area_t const& a, area_t const& b ) { return( a->first < b->first ); }; int main( int argc, char* argv[] ) { int row_num; area_t it; set< pair< int, area_t > > queue; queue.insert( make_pair( row_num, it ) ); // does not compile }; One way to fix it is moving the definition of less< to namespace std (I know, you are not supposed to do it.) namespace std { bool operator< ( area_t const& a, area_t const& b ) { return( a->first < b->first ); }; }; Another obvious solution is defining less than< for pair< int, area_t but I'd like to avoid that and be able to define the operator only for the one element of the pair where it is not defined.

    Read the article

  • dynamic, How to test if a property is available

    - by Miau
    Scenario is very simple somewhere in the code I have this dynamic myVariable = GetDataThatLooksVerySimilarButNotTheSame(); //how to do this? if (myVariable.MyProperty.Exists) //Do stuff So basically the question is how to check (avoiding exceptions) that a certain property is available in my dynamic variable. I could do GetType() but I d rather avoid that, I dont actually want to know the type of the object I want to know if a property (or method if that makes life easier) is available Any pointers? Cheers

    Read the article

  • Operator Overloading in C++ as int + obj

    - by Azher
    Hi Guys, I have following class:- class myclass { size_t st; myclass(size_t pst) { st=pst; } operator int() { return (int)st; } int operator+(int intojb) { return int(st) + intobj; } }; this works fine as long as I use it like this:- char* src="This is test string"; int i= myclass(strlen(src)) + 100; but I am unable to do this:- int i= 100+ myclass(strlen(src)); Any idea, how can I achieve this?? Thanks in advance. Regards,

    Read the article

  • perl - universal operator overload

    - by Todd Freed
    I have an idea for perl, and I'm trying to figure out the best way to implement it. The idea is to have new versions of every operator which consider the undefined value as the identity of that operation. For example: $a = undef + 5; # undef treated as 0, so $a = 5 $a = undef . "foo"; # undef treated as '', so $a = foo $a = undef && 1; # undef treated as false, $a = true and so forth. ideally, this would be in the language as a pragma, or something. use operators::awesome; However, I would be satisfied if I could implement this special logic myself, and then invoke it where needed: use My::Operators; The problem is that if I say "use overload" inside My::Operators only affects objects blessed into My::Operators. So the question is: is there a way (with "use overoad" or otherwise) to do a "universal operator overload" - which would be called for all operations, not just operations on blessed scalars. If not - who thinks this would be a great idea !? It would save me a TON of this kind of code if($object && $object{value} && $object{value} == 15) replace with if($object{value} == 15) ## the special "is-equal-to" operator

    Read the article

  • C++ segmentation error when first parameter is null in comparison operator overload

    - by user1774515
    I am writing a class called Word, that handles a c string and overloads the <, , <=, = operators. word.h: friend bool operator<(const Word &a, const Word &b); word.cc: bool operator<(const Word &a, const Word &b) { if(a == NULL && b == NULL) return false; if(a == NULL) return true; if(b == NULL) return false; return a.wd < b.wd; //wd is a valid c string } main: char* temp = NULL; //EDIT: i was mistaken, temp is a char pointer Word a("blah"); //a.wd = [b,l,a,h] cout << (temp<a); i get a segmentation error before the first line of the operator< method after the last line in the main. I can correct the problem by writing cout << (a>temp); where the operator> is similarly defined and i get no errors. but my assignment requires (temp < a) to work so this is where i ask for help. EDIT: i made a mistake the first time and i said temp was of type Word, but it is actually of type char*. so i assume that the compiler converts temp to a Word using one of my constructors. i dont know which one it would use and why this would work since the first parameter is not Word. here is the constructor i think is being used to make the Word using temp: Word::Word(char* c, char* delimeters=NULL) { char *temporary = "\0"; if(c == NULL) c = temporary; check(stoppers!=NULL, "(Word(char*,char*))NULL pointer"); //exits the program if the expression is false if(strlen(c) == 0) size = DEFAULT_SIZE; //10 else size = strlen(c) + 1 + DEFAULT_SIZE; wd = new char[size]; check(wd!=NULL, "Word(char*,char*))heap overflow"); delimiters = new char[strlen(stoppers) + 1]; //EDIT: changed to [] check(delimiters!=NULL,"Word(char*,char*))heap overflow"); strcpy(wd,c); strcpy(delimiters,stoppers); count = strlen(wd); } wd is of type char* thanks for looking at this big question and trying to help. let me know if you need more code to look at

    Read the article

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