|
|
thats one of finest log file class i ever seen! even thats thread safe! how's life going hamid.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
Thanks not bad, did you have a good week.
|
|
|
|
|
yeah great week end i am expecting
|
|
|
|
|
ThatsAlok wrote: yeah great week end i am expecting
Because you are good man.
|
|
|
|
|
try searching codeproject for LogFile classes, there are load of classes available for you.. find your self best class which suited your need!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
In the program below if i try to convert derived class pointer to base with '=' operator overloaded the overloaded operator is not considered. Can somebody please explain what is wrong in the below code?
class base
{
// dummy
};
class Derived : public base
{
public:
Derived* operator= (base* aBase)
{
return (Derived*) aBase;
}
};
int main(int argc, char* argv[])
{
base* bb = new Derived;
Derived* dd = bb; // Compilation error C2440
return 0;
}
|
|
|
|
|
You can't do that. This opposite is possible (casting from a derived class to a base class).
You have to use a dynamic_cast:
Derived* dd = dynamic_cast(base*)<bb>;
Not sure why you would like to do that in this context though.
|
|
|
|
|
I understand that you shouldn't convert. But in derived class i have overloaded '=' operator which takes base pointer as argument and explicitly converts it to derived pointer. Still the compiler is throwing an error. Is anything wrong in the overloaded operator?
Actually i am trying to write a linked list to store any data type in one list. So i have a data class (a template class) which is derived from a dummy base class. Each node has a pointer of base class storing derived class object. So while retreiving i will cast base class pointer to detived with template argument(e.g derived<t>*) by overloading = operator in derived class.
|
|
|
|
|
What about a good book on OOP , focusing the reading on polymorphism?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
The c++ operator oveloading will work only one object. The operator you wrote will work in the below case only
base* bb = new Derived;<br />
Derived dd;<br />
dd = bb;
|
|
|
|
|
No. Before posting i tried that. It doesn't work. Actuallu what you have written should be modified as
Derived* dd = NULL;
dd = bb;
|
|
|
|
|
C.P.Rajesh wrote: Actuallu what you have written should be modified as
What I mean is if you want the =operator to, you should code in that way.
C.P.Rajesh wrote: Derived* dd = NULL;
dd = bb;
This is just an pointer assigment statement. That is bb is assigned to a pointer of Derived not to an object of class Derived. The operator functions you written on the class will work only for object of that class. not for a pointer of it...
|
|
|
|
|
The above code will not work.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: The above code will not work
And can you tell me why? Since he have overlaoded the operator= (base* aBase), it should definitly work.. I coudnt find any problem...
|
|
|
|
|
Naveen wrote:
And can you tell me why?
Of course:
It's class have an assignment operator returning a pointer to Derived not a reference to.
(his design is a bit weird...).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Yes yes
I just changed the code so that the operator =() will get called. Forget to change the operator =() function
|
|
|
|
|
C.P.Rajesh wrote: what is wrong in the below code?
Your operator is defined for a hinstance of the object, not for a pointer, the following code will work
base* bb = new Derived;
Derived ddHelper;
Derived* dd = (ddHelper=bb);
Anyway your design is ugly: overloading the assignemnt operator such a way is misleading.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I didn't understand your reply. My requirement is i need a linked list which stores multiple type of objects in a single list. So i have a data class (a template class) like below
template <class T> class data : public base
{
T myData;
public:
T& getData () {return myData;}
bool putData (const T& aData) {myData = aData; return true;}
// Overloaded operator which takes base class pointer
data<T>* operator= (base* aBase)
{
return (data<T>*)aBase;
}
};
Each node has a base class pointer which stores derived class object. So while retrieving the data from linked list i use this overloaded operator. The advantage is if i use data<wrongdatatype> on left handside of = operation it will give compilation error.
If you have any other suggestion for the problem i will be happy to hear.
modified on Friday, April 18, 2008 4:02 AM
<div class="ForumMod">modified on Friday, April 18, 2008 4:03 AM</div>
|
|
|
|
|
C.P.Rajesh wrote: If you have any other suggestion for the problem i will be happy to hear.
Two suggestions:
(1) Use standard library containers.
(2) Exploit polymorphism (i.e. on a well designed class hierarchy, ususally you haven't to bother about the real nature of the pointer, taht is Base* or Derived* ,instead, you just call methods on it and all will go on fine).
(2.bis) If you really need the exact nature of the pointer, use dynamic_cast .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thank you very much for your suggestion.
I have a doubt in the first one. Is there any standard library container which stores different data types in one list, i mean first object is 'int', second is some user defined and so on?
In the second suggestion by saying 'Exploit polymorphism' i beleve you are talking about run time polymorphism i.e using virtual functions. But i am afraid i can't do that because the base class doesn't know about the object type to do any manipulation. If i make it a template class then i cannot have a base pointer in node to point to any data type.
Thank you once again for your time and effort.
|
|
|
|
|
C.P.Rajesh wrote: Is there any standard library container which stores different data types in one list, i mean first object is 'int', second is some user defined and so on?
No. But you could save yourself the complete container hassle, and focus on the conversion.
Or, you could use STL container with boost::any[^]
Boost is quite renowned for their rigid code review and their focus on well thought out concepts.
Its founder list is a who-is-who of the c++-world.
A number of classes from that web site will be part of the next C++ standard library.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
hi,
I am developing SDI application ,inherits from FomView.
It is required that i have to use TTF font type(which i downloaded from Ineternet) on button in run time.
Thank u....
|
|
|
|
|
You can use of CFont::Create and use of SetFont.
|
|
|
|
|
Mira wey, necesitas poner:
CMyView : public CFormView{
CFont fontButton;
//
};
CMyView::OnInitialUpdate(){
LOGFONT lf;
memset(&lf,0,sizeof(lf));
lf.lfHeight=(int)(33);
lf.lfWeight=FW_BOLD;
strcpy(lf.lfFaceName,"Arial");
m_fontButton.CreateFontIndirect(&lf);
GetDlgItem(IDC_MYBUTTON)->SetFont(&fontButton);
}
|
|
|
|