Search Results

Search found 3340 results on 134 pages for 'comma operator'.

Page 6/134 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • 3x3 Sobel operator and gradient features

    - by pithyless
    Reading a paper, I'm having difficulty understanding the algorithm described: Given a black and white digital image of a handwriting sample, cut out a single character to analyze. Since this can be any size, the algorithm needs to take this into account (if it will be easier, we can assume the size is 2^n x 2^m). Now, the description states given this image we will convert it to a 512-bit feature (a 512-bit hash) as follows: (192 bits) computes the gradient of the image by convolving it with a 3x3 Sobel operator. The direction of the gradient at every edge is quantized to 12 directions. (192 bits) The structural feature generator takes the gradient map and looks in a neighborhood for certain combinations of gradient values. (used to compute 8 distinct features that represent lines and corners in the image) (128 bits) Concavity generator uses an 8-point star operator to find coarse concavities in 4 directions, holes, and lagrge-scale strokes. The image feature maps are normalized with a 4x4 grid. I'm for now struggling with how to take an arbitrary image, split into 16 sections, and using a 3x3 Sobel operator to come up with 12 bits for each section. (But if you have some insight into the other parts, feel free to comment :)

    Read the article

  • operator<< overload,

    - by mr.low
    //using namespace std; using std::ifstream; using std::ofstream; using std::cout; class Dog { friend ostream& operator<< (ostream&, const Dog&); public: char* name; char* breed; char* gender; Dog(); ~Dog(); }; im trying to overload the << operator. I'm also trying to practice good coding. But my code wont compile unless i uncomment the using namespace std. i keep getting this error and i dont know. im using g++ compiler. Dog.h:20: error: ISO C++ forbids declaration of ‘ostream’ with no type Dog.h:20: error: ‘ostream’ is neither function nor member function; cannot be declared friend. if i add line using std::cout; then i get this error. Dog.h:21: error: ISO C++ forbids declaration of ‘ostream’ with no type. Can somebody tell me the correct way to overload the << operator with out using namespace std;

    Read the article

  • How to overload operator<< for qDebug

    - by iyo
    Hi, I'm trying to create more useful debug messages for my class where store data. My code is looking something like this #include <QAbstractTableModel> #include <QDebug> /** * Model for storing data. */ class DataModel : public QAbstractTableModel { // for debugging purposes friend QDebug & operator<< (const QDebug &d, DataModel model); //other stuff }; /** * Overloading operator for debugging purposes */ QDebug & operator<< (QDebug &d, DataModel model) { d << "Hello world!"; return d; } I expect qDebug() << model will print "Hello world!". However, there is alway something like "QAbstractTableModel(0x1c7e520)" on the output. Do you have any idea what's wrong?

    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

  • How operator oveloading works

    - by Rasmi Ranjan Nayak
    I have below code class rectangle { ..... .....//Some code int operator+(rectangle r1) { return(r1.length+length); } }; In main fun. int main() { rectangle r1(10,20); rectangle r2(40,60); rectangle r3(30,60); int len = r1+r3; } Here if we will see in operator+(), we are doing r1.length + length. How the compiler comes to know that the 2nd length in return statement belong to object r3 not to r1 or r2? I think answer may be in main() we have writeen int len = r1+r3; If that is the case then why do we need to write in operator+(....) { r1.lenth + lenth; //Why not length + length? } Why not length + length? Bcause compiler already knows from main() that the first length belong to object r1 and 2nd to object r3.

    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

  • Recursion problem overloading an operator

    - by Tronfi
    I have this: typedef string domanin_name; And then, I try to overload the operator< in this way: bool operator<(const domain_name & left, const domain_name & right){ int pos_label_left = left.find_last_of('.'); int pos_label_right = right.find_last_of('.'); string label_left = left.substr(pos_label_left); string label_right = right.substr(pos_label_right); int last_pos_label_left=0, last_pos_label_right=0; while(pos_label_left!=string::npos && pos_label_right!=string::npos){ if(label_left<label_right) return true; else if(label_left>label_right) return false; else{ last_pos_label_left = pos_label_left; last_pos_label_right = pos_label_right; pos_label_left = left.find_last_of('.', last_pos_label_left); pos_label_right = right.find_last_of('.', last_pos_label_left); label_left = left.substr(pos_label_left, last_pos_label_left); label_right = right.substr(pos_label_right, last_pos_label_right); } } } I know it's a strange way to overload the operator <, but I have to do it this way. It should do what I want. That's not the point. The problem is that it enter in an infinite loop right in this line: if(label_left<label_right) return true; It seems like it's trying to use this overloading function itself to do the comparision, but label_left is a string, not a domain name! Any suggestion?

    Read the article

  • overload == (and != , of course) operator, can I bypass == to determine whether the object is null

    - by LLS
    Hello, when I try to overload operator == and != in C#, and override Equal as recommended, I found I have no way to distinguish a normal object and null. For example, I defined a class Complex. public static bool operator ==(Complex lhs, Complex rhs) { return lhs.Equals(rhs); } public static bool operator !=(Complex lhs, Complex rhs) { return !lhs.Equals(rhs); } public override bool Equals(object obj) { if (obj is Complex) { return (((Complex)obj).Real == this.Real && ((Complex)obj).Imaginary == this.Imaginary); } else { return false; } } But when I want to use if (temp == null) When temp is really null, some exception happens. And I can't use == to determine whether the lhs is null, which will cause infinite loop. What should I do in this situation. One way I can think of is to us some thing like Class.Equal(object, object) (if it exists) to bypass the == when I do the check. What is the normal way to solve the problem?

    Read the article

  • Operator Overloading << in c++

    - by thlgood
    I'm a fresh man in C++. I write this simple program to practice Overlaoding. This is my code: #include <iostream> #include <string> using namespace std; class sex_t { private: char __sex__; public: sex_t(char sex_v = 'M'):__sex__(sex_v) { if (sex_v != 'M' && sex_v != 'F') { cerr << "Sex type error!" << sex_v << endl; __sex__ = 'M'; } } const ostream& operator << (const ostream& stream) { if (__sex__ == 'M') cout << "Male"; else cout << "Female"; return stream; } }; int main(int argc, char *argv[]) { sex_t me('M'); cout << me << endl; return 0; } When I compiler it, It print a lots of error message: The error message was in a mess. It's too hard for me to found useful message sex.cpp: ???‘int main(int, char**)’?: sex.cpp:32:10: ??: ‘operator<<’?‘std::cout << me’????? sex.cpp:32:10: ??: ???: /usr/include/c++/4.6/ostream:110:7: ??: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostre

    Read the article

  • Class Assignment Operators

    - by Maxpm
    I made the following operator overloading test: #include <iostream> #include <string> using namespace std; class TestClass { string ClassName; public: TestClass(string Name) { ClassName = Name; cout << ClassName << " constructed." << endl; } ~TestClass() { cout << ClassName << " destructed." << endl; } void operator=(TestClass Other) { cout << ClassName << " in operator=" << endl; cout << "The address of the other class is " << &Other << "." << endl; } }; int main() { TestClass FirstInstance("FirstInstance"); TestClass SecondInstance("SecondInstance"); FirstInstance = SecondInstance; SecondInstance = FirstInstance; return 0; } The assignment operator behaves as-expected, outputting the address of the other class. Now, how would I actually assign something from the other class? For example, something like this: void operator=(TestClass Other) { ClassName = Other.ClassName; }

    Read the article

  • Why overload true and false instead of defining bool operator?

    - by Joe Enos
    I've been reading about overloading true and false in C#, and I think I understand the basic difference between this and defining a bool operator. The example I see around is something like: public static bool operator true(Foo foo) { return (foo.PropA > 0); } public static bool operator false(Foo foo) { return (foo.PropA <= 0); } To me, this is the same as saying: public static implicit operator bool(Foo foo) { return (foo.PropA > 0); } The difference, as far as I can tell, is that by defining true and false separately, you can have an object that is both true and false, or neither true nor false: public static bool operator true(Foo foo) { return true; } public static bool operator false(Foo foo) { return true; } //or public static bool operator true(Foo foo) { return false; } public static bool operator false(Foo foo) { return false; } I'm sure there's a reason this is allowed, but I just can't think of what it is. To me, if you want an object to be able to be converted to true or false, a single bool operator makes the most sense. Can anyone give me a scenario where it makes sense to do it the other way? Thanks

    Read the article

  • Comma Seperated Values Insertion In SQL server 2005

    - by Asim Sajjad
    How can I insert Values from the comma separated input paramater to the Store prodcedure ? Example is exec StopreProcedure Name 17,'127,204,110,198',7,'162,170,163,170' you can see that I have two Comma Separated Values in the parameter list , both will have same number of values if first have 5 comma seperated value then second one also has 5 comma separated values you can says 127 and 162 are related 204 and 170 are related and same for other how can I insert these two values in ? One comma Sepated value is inserted but how to insert two ?

    Read the article

  • operator for enums

    - by Veer
    Hi all, Just out of curiosity, asking this Like the expression one below a = (condition) ? x : y; // two outputs why can't we have an operator for enums? say, myValue = f ??? fnApple() : fnMango() : fnOrange(); // no. of outputs specified in the enum definition instead of switch statements (eventhough refractoring is possible) enum Fruit { apple, mango, orange }; Fruit f = Fruit.apple; Or is it some kind of useless operator?

    Read the article

  • Operator overloading outside class

    - by bobobobo
    There are two ways to overload operators for a C++ class: Inside class class Vector2 { public: float x, y ; Vector2 operator+( const Vector2 & other ) { Vector2 ans ; ans.x = x + other.x ; ans.y = y + other.y ; return ans ; } } ; Outside class class Vector2 { public: float x, y ; } ; Vector2 operator+( const Vector2& v1, const Vector2& v2 ) { Vector2 ans ; ans.x = v1.x + v2.x ; ans.y = v1.y + v2.y ; return ans ; } (Apparently in C# you can only use the "outside class" method.) In C++, which way is more correct? Which is preferable?

    Read the article

  • Java operator overload

    - by rengolin
    Coming from C++ to Java, the obvious unanswered question is why not operator overload. On the web some go about: "it's clearly obfuscated and complicate maintenance" but no one really elaborates that further (I completely disagree, actually). Other people pointed out that some objects do have an overload (like String operator +) but that is not extended to other objects nor is extensible to the programmer's decision. I've heard that they're considering extending the favour to BigInt and similar, but why not open that for our decisions? How exactly if complicates maintenance and where on earth does this obfuscate code? Isn't : Complex a, b, c; a = b + c; much simpler than: Complex a, b, c; a.equals( b.add(c) ); ??? Or is it just habit?

    Read the article

  • null coalescing operator for javascript?

    - by Daniel Schaffer
    I assumed this question has already been asked here, but I couldn't find any, so here it goes: Is there a null coalescing operator in Javascript? For example, in C#, I can do this: String someString = null; var whatIWant = someString ?? "Cookies!"; The best approximation I can figure out for Javascript is using the conditional operator: var someString = null; var whatIWant = someString ? someString : 'Cookies!'; Which is sorta icky IMHO. Can I do better?

    Read the article

  • Operator overloading C++ outside class

    - by bobobobo
    Well, so there are 2 ways to overload operators for a C++ class INSIDE CLASS class Vector2 { public: float x, y ; Vector2 operator+( const Vector2 & other ) { Vector2 ans ; ans.x = x + other.x ; ans.y = y + other.y ; return ans ; } } ; OUTSIDE CLASS class Vector2 { public: float x, y ; } ; Vector2 operator+( const Vector2& v1, const Vector2& v2 ) { Vector2 ans ; ans.x = v1.x + v2.x ; ans.y = v1.y + v2.y ; return ans ; } In C# apparently you can only use the OUTSIDE class method The question is, in C++, which is "morer-correcter?" Which is preferable? When is one way better than another?

    Read the article

  • no match for operator= using a std::vector

    - by Max
    I've got a class declared like this: class Level { private: std::vector<mapObject::MapObject> features; (...) }; and in one of its member functions I try to iterate through that vector like this: vector<mapObject::MapObject::iterator it; for(it=features.begin(); it<features.end(); it++) { /* loop code */ } This seems straightforward to me, but g++ gives me this error: src/Level.cpp:402: error: no match for ‘operator=’ in ‘it = ((const yarl::level::Level*)this)-yarl::level::Level::features.std::vector<_Tp, _Alloc::begin [with _Tp = yarl::mapObject::MapObject, _Alloc = std::allocator<yarl::mapObject::MapObject>]()’ /usr/include/c++/4.4/bits/stl_iterator.h:669: note: candidates are: __gnu_cxx::__normal_iterator<yarl::mapObject::MapObject*,std::vector & __gnu_cxx::__normal_iterator<yarl::mapObject::MapObject*,std::vector >::operator=(const __gnu_cxx::__normal_iterator<yarl::mapObject::MapObject*, ``std::vector<yarl::mapObject::MapObject, std::allocator<yarl::mapObject::MapObject> > >&) Anyone know why this is happening?

    Read the article

  • Problem with operator ==

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

    Read the article

  • C# String Operator Overloading

    - by ScottSEA
    G'Day Mates - What is the right way (excluding the argument of whether it is advisable) to overload the string operators <, , <= and = ? I've tried it five ways to Sunday and I get various errors - my best shot was declaring a partial class and overloading from there, but it won't work for some reason. namespace System { public partial class String { public static Boolean operator <(String a, String b) { return a.CompareTo(b) < 0; } public static Boolean operator >(String a, String b) { return a.CompareTo(b) > 0; } } }

    Read the article

  • An operator == whose parameters are non-const references

    - by Eduardo León
    I this post, I've seen this: class MonitorObjectString: public MonitorObject { // some other declarations friend inline bool operator==(/*const*/ MonitorObjectString& lhs, /*const*/ MonitorObjectString& rhs) { return lhs.fVal==rhs.fVal; } } Before we can continue, THIS IS VERY IMPORTANT: I am not questioning anyone's ability to code. I am just wondering why someone would need non-const references in a comparison. The poster of that question did not write that code. This was just in case. This is important too: I added both /*const*/s and reformatted the code. Now, we get back to the topic: I can't think of a sane use of the equality operator that lets you modify its by-ref arguments. Do you?

    Read the article

  • Dynamic Operator Overloading on dict classes in Python

    - by Ishpeck
    I have a class that dynamically overloads basic arithmetic operators like so... import operator class IshyNum: def __init__(self, n): self.num=n self.buildArith() def arithmetic(self, other, o): return o(self.num, other) def buildArith(self): map(lambda o: setattr(self, "__%s__"%o,lambda f: self.arithmetic(f, getattr(operator, o))), ["add", "sub", "mul", "div"]) if __name__=="__main__": number=IshyNum(5) print number+5 print number/2 print number*3 print number-3 But if I change the class to inherit from the dictionary (class IshyNum(dict):) it doesn't work. I need to explicitly def __add__(self, other) or whatever in order for this to work. Why?

    Read the article

  • Scala :: operator, how it works?

    - by Felix
    Hello Guys, in Scala, I can make a caseclass case class Foo(x:Int) and then put it in a list like so: List(Foo(42)) Now, nothing strange here. The following is strange to me. The operator :: is a function on a list, right? With any function with 1 argument in Scala, I can call it with infix notation. An example is 1 + 2 is a function (+) on the object Int. The class Foo I just defined does not have the :: operator, so how is the following possible: Foo(40) :: List(Foo(2)) ? In scala 2.8 rc1, I get the following output from the interactive prompt: scala> case class Foo(x:Int) defined class Foo scala> Foo(40) :: List(Foo(2)) res2: List[Foo] = List(Foo(40), Foo(2)) scala> I can go on and use it, but if someone can explain it I will be glad :)

    Read the article

  • Passing operator as a parameter

    - by nacho4d
    Hi, I want to have a function that evaluates 2 bool vars (like a truth table) for example: since T | F : T then myfunc('t', 'f', ||); /*defined as: bool myfunc(char lv, char rv, ????)*/ should return true; how can I pass the third parameter? (I know is possible to pass it as a char* but then I will have to have another table to compare operator string and then do the operation which is something I would like to avoid) Is it possible to pass an operator like ^(XOR) or ||(OR) or &&(AND), etc in a function/method? Thanks in advance

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >