|
VuNic wrote: For example..
If you do weird things in the = operator (re-)definition, for instance, i.e. if you write it (implicitely) assuming it will be never used to do self-assignment. Have a look at the following code
(please note, it is silly, written just to spot the point; moreover no check is done on memory allocation, for brevity)
class Foo
{
static const int N = 10;
char * _buf;
public:
Foo(char c){_buf = new char [N]; memset(_buf, c, N);}
Foo & operator=(const Foo & foo)
{
if ( _buf )
{
delete _buf;
_buf = new char[N];
}
memcpy(_buf, foo._buf, N);
return *this;
}
Foo(const Foo & foo){...}
};
void main()
{
Foo f('A');
f = f;
}
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
[My articles]
|
|
|
|
|
CPallini wrote: i.e. if you write it (implicitely) assuming it will be never used to do self-assignment.
And why would someone do that? Isn't that considered Best Practice? Or is this question about something entirely different than what I have been able to interpret?
It seems to me that it is about this subject[^]
|
|
|
|
|
led mike wrote: And why would someone do that?
Exactly that? Just CPallini...
led mike wrote: Isn't that considered Best Practice?
Nope, anyway it's a good candidate to be inserted into the WPF (Worst Practice Foundation).
led mike wrote: Or is this question about something entirely different than what I have been able to interpret?
led mike wrote: And why would someone do that? Isn't that considered Best Practice? Or is this question about something entirely different than what I have been able to interpret?
It seems to me that it is about this subject[^]
Nope, you understand it correctly and, damn... If you recalled that page before my post I hadn't to put the weird code therein.
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
[My articles]
|
|
|
|
|
CPallini wrote: Nope, anyway it's a good candidate to be inserted into the WPF (Worst Practice Foundation).
It's not considered best practice to implement an assignment operator the way it is shown in the parashift FAQ Lite to exclude self assignment?
|
|
|
|
|
Nope. I was talking about my code sample (supposing your sentence ironical). Sorry for the misunderstanding.
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
[My articles]
|
|
|
|
|
CPallini wrote: Sorry for the misunderstanding.
LMAO Some times texting is a a BEE-ATCH!
Using the IPhone would have solved all this ![Big Grin | :-D](https://www.codeproject.com/script/Forums/Images/smiley_biggrin.gif)
|
|
|
|
|
Thanx for the adjective used for me(Worst Practice Foundation user).
Any way, my question was what are the problems associated with self assignment of an object to itself?
Ppl gave me all the comments and on my programming as well rather to answer my question, but yes, i got the answer, please refer the following link:
http://faqs.cs.uu.nl/na-dir/C++-faq/part06.html
Refer: SECTION [12]: Assignment operators(in the link above)
Thanx & Regards
|
|
|
|
|
dubeypankaj wrote: Thanx for the adjective used for me(Worst Practice Foundation user).
It wasn't used for you, it was for my sample code (see [^])... In a bad mood today?
I just wanted to make Vunic aware that, yes, there might be problems with self-assignment. Of course the link provided by led mike spots the point far better than I did.
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
[My articles]
|
|
|
|
|
dubeypankaj wrote: What are the problems associated with self assignment
The answer is, whatever problems were introduced in the class being used in the self assignment.
Keep studying. ![Beer | [beer]](https://www.codeproject.com/script/Forums/Images/beer.gif)
|
|
|
|
|
If local-time and time-zone are correctly set,
does the function ::GetSystemTime(...) (UTC) return same time value in its parameter in all (different) time-zones?
|
|
|
|
|
includeh10 wrote: does the function ::GetSystemTime(...) (UTC) return same time value in its parameter in all (different) time-zones?
I suppose it depends on when the function is called...
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
[My articles]
|
|
|
|
|
hallo,
in the file: mainfrm.cpp i need to access the function CEditView::OnFilePrint ()
but i got error C2248 'member' : cannot access 'access' member declared in class 'class',
how can i solve this problem, thanks.
|
|
|
|
|
Did you try GetActiveView()?
|
|
|
|
|
what about GetActiveView()? i did not find it.
|
|
|
|
|
What are you trying to do ?
You cannot access a function from a class without having an instance of this class unless this is a static method. I think you'll need some deeper knowledge of the way to work with classes in C++. Remember that the MFC generated classes (the view, the main frame, the document, ...) are still classes.
|
|
|
|
|
i have SDI application that divided to two windows with an instance of CSplitterWnd, so the upper and the lower window thier content need to be printed separately from each other, i put a function in the mainfrm.cpp that calls OnFilePrint (), but OnFilePrint () is a protected function of CView, i tried to make mainfrm class a friend of CEditView but it did not work.
|
|
|
|
|
You could simply add a public member function in your CView-derived class which simply calls OnFilePrint.
I don't know if you are allowed to call OnFilePrint (I don't have a lot of experience with printing), but if you can then that's probably the easiest.
|
|
|
|
|
i derived a class from CView and declared a publich function in it in this function i called OnFilePrint() by an CEdit Object, but i got the same error C2248.
|
|
|
|
|
susanne1 wrote: in this function i called OnFilePrint() by an CEdit Object
I don't understand what you mean... What is this CEdit object doing here ? Please, be specific in your reply, and maybe post some useful code so that we can see what you are doing exactly.
|
|
|
|
|
how to make application for windows mobile. I need all details to build application for windows mobile
Trioum
|
|
|
|
|
For instance, choosing the right forum to post to [^] would be a nice start.
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
[My articles]
|
|
|
|
|
In addition to our pal-lini's link, here's a link to the other world[^]
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
Hi poeple,
I have been set this assignment and i just dont know how to start it or even think how to do it i was wondering if anyone could shed some light on it for me?.
The program is required to store information on a variable number of members of staff in a company. It will use 6 vectors to record the following information.
Staff Number - a 3 digit number in the range 100- 999.
Basic pay rate
Overtime pay rate
Day of birth
Month of birth
Year of birth
For example, if there were 7 staff members the vectors could look as follows:-
staff number 211 302 511 123 145 303 476
basic pay 7.50 7.50 9.00 7.50 8.00 9.00 12.00
OT pay 10.00 10.00 13.00 10.00 12.00 13.00 18.00
day of birth 12 15 25 27 9 6 1
month of birth 8 9 12 10 12 1 1
year of birth 1990 1990 1983 1987 1985 1980 1976
The program should allow the user to specify the number of staff and then enter the data. Once the data have been entered the user should be presented with the following text menu.
1. Print staff details
2. Quit
If the user selects option 1 they should be asked for the staff number (e.g. 511 in the example above). It will be necessary to find the staff number in the first vector and then print out the following information.
Basic pay
Overtime pay
Age
Age should be calculated by using a function, it will be necessary to ask the user to input today’s date. You will need to decide whether to ask for today’s date in the main program and pass it to the function or to ask for it within the function.
After the information has been displayed the menu should be displayed again and this process repeated until the user chooses option 2.
To gain additional marks the menu should be modified as follows:-
1. Print staff details
2. Add member of staff
3. Quit
Option 2 should now give the user the opportunity of adding an additional member of staff.
Cheers guys
|
|
|
|
|
Neal beavis wrote: It will use 6 vectors to record the following information.
Staff Number - a 3 digit number in the range 100- 999.
Basic pay rate
Overtime pay rate
Day of birth
Month of birth
Year of birth
Is this a requirement? I think it would be better using a vector of struct s...
It looks a quite strightforward task, what are your troubles with it?
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
[My articles]
|
|
|
|
|
i genrally dont know how to start this assignment? i dont really know how to use the vectors within this ssignment.
you help would be much appreciated!
|
|
|
|