|
|
Hello guys!
there is a class named CMyClass as follow
CMyclass:CObject
{
public:
int m_iCount,m_iIndex;
CMyclass();
void ~CMyclass();
}
and definations: CMyclass ma,mb;
and statements: ma.m_iCount=3;
ma.m_iIndex=2;
How can I use "mb=ma;"?
Should I overide operator= ? and how?
Any suggestion is appreciable .
I'm learning learning and learning.
|
|
|
|
|
I just wrote a non-MFC code (actually a console one) to demonstrate operator overloading for you ...
#include <iostreamᡊe9ac73-238b-46be-991d-0f050c37248d
using namespace std;
class Base
{
protected:
static int _iIndex;
static Base* _pAddress;
int _iId;
Base* _pPrev;
public:
Base() {
_iId = ++_iIndex;
_pPrev = _pAddress;
_pAddress = this;
}
Base& operator==(Base& ref) {
ref._pPrev = this;
return *this;
}
int Bomb() {
cout << _iId << " -> ";
_sleep(500);
if(!_pPrev) {
cout << "\nChain broken!\n";
return 1;
}
return _pPrev->Bomb();
}
};
int Base::_iIndex = 0;
Base* Base::_pAddress = 0;
int main()
{
Base a[20];
a[19] == a[0];
return a[19].Bomb();
}
Maxwell Chen
People say "No news is good news". Then, no code is good code!?
|
|
|
|
|
You don't need to overload operator =, because you'll get one for free - you only want to copy integral types (int).
Is you want to overload it, then by all means do so, like this
CMyclass & CMyclass::operator=(const CMyclass & toCopy)
{
m_iCount = toCopy.m_iCount;
m_iIndex = toCopy.m_iIndex;
return *this;
}
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Use copy constructor.
Maxwell Chen
People say "No news is good news". Then, no code is good code!?
|
|
|
|
|
This is actually a trivial class, where you don't really need to overload operator=, since members are copied by default. If, however, your class contains pointers or references to objects, then you will need to overload the operator. This operator should always look for, and avoid, self assignments:
CMyclass & CMyclass::operator=(const CMyclass & toCopy)
{
if (this != &toCopy)
{
m_iCount = toCopy.m_iCount;
m_iIndex = toCopy.m_iIndex;
}
return *this;
}
|
|
|
|
|
And for copy constructor issue:
#include <iostreamᡊe9ac73-238b-46be-991d-0f050c37248d
using namespace std;
class Base
{
public:
Base() { }
int a;
Base(const Base& ref)
{
this->a = ref.a;
}
};
void main()
{
Base a;
Base b;
a.a = 3;
b = a;
cout << b.a << endl;
}
Maxwell Chen
People say "No news is good news". Then, no code is good code!?
|
|
|
|
|
Thank you ,Maxwell Chen and Christian Graus !
I overloaded operator= ,and it's ok with my program now.
|
|
|
|
|
You are welcome.
Maxwell Chen
People say "No news is good news". Then, no code is good code!?
|
|
|
|
|
Hi,
As it is possible to hide or disable the PropertyPage in the PropertySheet!
How do it!?
Best regards,
Eugene Pustovoyt
|
|
|
|
|
I cover this in a demo in my MFC book (see sig). It's a fairly involved process, but here are the basic steps. Let me know if you need any additional help and I'll send you a demo app.
(All of these steps pertain to the property sheet class)
- Create a member variable to store the current tab index.
- Create an array member variable to hold all of the index values for the currently disabled tabs.
- Handle the
TCN_SELCHANGING notification message to set the current tab index.
- Handle the
TCN_SELCHANGED notification message to decide if you want to enable the tab to be activated. If you don’t, you must post a PSM_SETCURSEL message. In this message, the last active tab index is specified.
Cheers,
Tom Archer
Author - Inside C#, Visual C++.NET Bible
|
|
|
|
|
You could not, to told above, at once to send demo (VC5.0 or VC6.0) to me that I could understand better with the specified steps.
I still have questions be relative CPropertySheet , and I hope to find on them answers
Best regards,
Eugene Pustovoyt
pustovoyt@inbox.ru
|
|
|
|
|
|
Thank you!
But these projects are written probably under VC.NET, and I have a VC ++ 6.0. Whether I can read them (are absent .dsp and .dsw). If yes, then how?
Best regards,
Eugene Pustovoyt
|
|
|
|
|
Did you try opening the project file instead of the solution? If that doesn't work, let me know and I'll send you the demo steps (including the code to type in) straight from the chapter.
Cheers,
Tom Archer
Author - Inside C#, Visual C++.NET Bible
|
|
|
|
|
As I can open the project not having files *.dsp or *.dsw!?
Or you has in view of to look through files separately, instead of the general project?
Eugene Pustovoyt
|
|
|
|
|
The project file is the .dsp and I believe you can open it in VC6.
In addition, you can also just open the CFindSheet file of the ModelDemo project.
Cheers,
Tom Archer
Author - Inside C#, Visual C++.NET Bible
|
|
|
|
|
Excuse for my English, but any of the projects sent by you, have not files *.dsp or *.dsw
Eugene Pustovoyt
|
|
|
|
|
|
Hi Tom,
Thanks for examples! I have understood how to disable tab!
I have some more questions if I yet have not bothered with the questions answer them please!
1. Whether it is possible to hide tab.
2. At me with application PSheetWithinADialog
I have a more tabs derivatives from one template, but with different labels.
Code of realization in OnInitDialog() the following.
m_sheet.AddPage(&m_pageMyPage1);
m_sheet.AddPage(&m_pageMyPage2);
m_sheet.AddPage(&m_pageMyPage3);
m_sheet.AddPage(&m_pageMyPage4);
m_sheet.AddPage(&m_pageMyPage5);
m_sheet.AddPage(&m_pageMyPage6);
m_sheet.AddPage(&m_pageMyPage7);
m_sheet.Create(this, WS_CHILD | WS_VISIBLE);
m_sheet.ModifyStyleEx (0, WS_EX_CONTROLPARENT);
TC_ITEM item;
item.mask = TCIF_TEXT;
TCHAR szText [100];
CString sTitle;
for (int i = 0; i < 7; i++)
{
sTitle.Format(_T("Long label %d"), i);
lstrcpy(szText, sTitle);
item.pszText = szText;
m_sheet.GetTabControl ()->SetItem (i, &item);
}
RECT rect;
HWND hwnd;
GetDlgItem(IDC_PROPSHEET_WINDOW, &hwnd);
ASSERT(hwnd);
if (hwnd)
{
::GetWindowRect(hwnd, &rect);
ScreenToClient(&rect);
m_sheet.SetWindowPos(NULL, rect.left, rect.top, 0, 0,
SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
}
Tabs begin it is deduced in two or three lines and it is wrong draw.
How of it to get rid?
Best regards,
Eugene Pustovoyt
|
|
|
|
|
see CPropertySheet::GetTabControl
and operate on the Tab- Ctrl
|
|
|
|
|
And how can I hide or disable the tab???
Eugene Pustovoyt
|
|
|
|
|
Hi,
Any one can explain the difference between break and continue?
Regard
Best regard.
I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.
|
|
|
|
|
NicholasCougar wrote:
Any one can explain the difference between break and continue?
break gets out of the loop immediately.
continue will break out of the current iteration.
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
Hi,
the difference between loop and iteration?
Regard
Best regard.
I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.
|
|
|
|