TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   Comparison of two classes (http://forums.techarena.in/software-development/1257534.htm)

Chrisch 12-10-2009 11:26 AM

Comparison of two classes
 
My problem is quite hard to explain but I'll try to ask my question clearly:
I have a class with an attribute PluginWidget type QWidget *
I try to reimplement the == operator so that we can compare a QWidget * A PluginWidget (_widget is the attribute of PluginWidget) :

PluginWidget bool:: operator == (nWidget QWidget *) (return _widget == nWidget)


I then one of PluginWidget @ list, but when I do an @ list:: indexOf (const T & value, int from = 0), I get error... Is that necessary to declare object in class from which they derived.

Zecho 12-10-2009 11:28 AM

Re: Comparison of two classes
 
The error because the same type for the argument of indexOf that used for the list. On top of that, you have a list filled with PluginWidget you want to compare with QWidget *, you compare pointers and objects.
Code:

int * a = new int;
* a = 5;
b = 5;

if (a == b) ()

it makes no sense You should at least be compare addresses (ie retrieve the addresses that are stored in your @ list) or compare objects and therefore not give a pointer in indexOf.

Walby 12-10-2009 11:31 AM

Re: Comparison of two classes
 
Difference Between Class & Objects : A class is a definition of an object. It's a type just like int. if once the class is created it remains till the end of the program, we can't made another class with the same name of the previous class.

Aberto 12-10-2009 11:33 AM

Re: Comparison of two classes
 
Class is a userdefined datatype with data members and member functions which can be public or privately accessed depending on access specifiers.Class is static. The attributes of a class always remain unchanged. Class and object both are related to each other, without class, object is of no use and without object, class is useless.
Example :
Code:

struct D
{
  int b;
  double C;
};
 
struct E
{
  int b;
  double c;
  C c;
};
 
// initialize an object of type C with an initializer-list
C c = { 1, 2 };
 
// D has a sub-aggregate of type C. In such cases initializer-clauses can be nested
D d = { 10, 20, { 1, 2 } };



All times are GMT +5.5. The time now is 05:26 PM.