|
Naveen, You help me a lot .
i am Very Very Thankful to you.
May I get your personal email id, if you do not mind.
|
|
|
|
|
Another crappy Indian programmer who cant work it out for themselves!
Morality is indistinguishable from social proscription
|
|
|
|
|
Hello everyone,
Why it is useless for any inheritance in Pimpl idiom? Here is the source, but no detailed reasons are provided.
http://www.gotw.ca/gotw/024.htm
--------------------
- make XImpl entirely the class that X would have been, and write X as only the public interface made up entirely of simple forwarding functions (a handle/body variant).
This is useful in a few restricted cases, and has the benefit of avoiding a back pointer since all services are available in the pimpl class. The chief drawback is that it normally makes the visible class useless for any inheritance, as either a base or a derived class.
--------------------
thanks in advance,
George
|
|
|
|
|
I can reply this. But please wait for me to type because I can not copy-and-paste.
Maxwell Chen
|
|
|
|
|
Can you provide a link, Maxwell? I can look up by myself.
regards,
George
|
|
|
|
|
The below is the original Pimpl model. The opaque pointer is the private member.
To test this with Visual C++ (2005), you need to put the declarations of class X and class X::XImpl with their member function prototypes in individual .h files, and put the implementations of member functions in individual .cpp files.
class X
{
private:
class XImpl;
XImpl* pimpl_;
public:
bool Foo(long);
protected:
int Bar(short);
};
class X::XImpl
{
public:
bool Function();
};
bool X::Foo(long v)
{
return pimpl_->Function();
}
bool X::XImpl::Function()
{
return true;
}
What does it mean To make XImpl entirely the class X would have been?
That is, you move X::Foo and X::Bar into class X::XImpl .
Code snippet below.
class X2
{
private:
class XImpl;
XImpl* pimpl_;
public:
bool Foo(long);
};
class X2::XImpl
{
public:
bool Function();
protected:
int Bar(short);
};
How will we use this revision? Still the same.
X2 obj;
if(obj.Foo() ) {
}
So now we talk about the inheritance. See the comments in the code snippet below.
class Y : public X2
{
public:
bool Test() {
return false;
}
};
Maxwell Chen
modified on Tuesday, March 18, 2008 4:04 AM
|
|
|
|
|
Thanks for providing a comprehensive sample, Maxwell!
1.
One question, why do you want to call Bar and Pimpl in method Test of class Y? If we put something (like Bar) in Pimpl part, it means it is not visible. So, I think it does not make senses to access Bar if it is in Pimpl part. Any comments?
2.
I think you can still access Foo in class Y, right?
regards,
George
|
|
|
|
|
George_George wrote: why do you want to call Bar and Pimpl in method Test of class Y? If we put something (like Bar) in Pimpl part, it means it is not visible. So, I think it does not make senses to access Bar if it is in Pimpl part. Any comments?
My code sample was just sort of excerpt. After all, you have to deal with class X or class Y in real life.
Let's take CDialog::OnInitDialog() of MFC for example. You created a dialog based project, so you have the below code.
In function implementation of CTestDlg::OnInitDialog , you need to do many things. For example: calling the base's member function CWnd::GetSystemMenu() to manipulate the title-box menu; calling CWnd::SetIcon to manipulate icons, etc.
class CTestDlg : public CDialog
{
protected:
virtual BOOL OnInitDialog(void);
};
BOOL CTestDlg::OnInitDialog()
{
CMenu* pMenu = GetSystemMenu(FALSE);
}
The article and I are not talking it making sense or not to access Bar if it is moved into Pimpl; We are talking about: Sometimes a certain design paradigm will shoot your own feet.
George_George wrote: I think you can still access Foo in class Y, right?
See my answer to (1) as the above.
My questions to you:
1) George, are you still at school or are you working at some company?
2) After you have been asking various beginner ~ expert level questions, do you really feel you are getting better in C++?
3) Are the questions you have asked here really useful to your homework or your real-world job?
Maxwell Chen
|
|
|
|
|
Thanks Maxwell,
I have read and understand the sample. Do you mean the pattern of MFC dialog is good or not? Does it relates to my original question?
My answers to your 3 questions,
1) private
2) sure, expecially from you;
3) some from books, some from the comments from you.
regards,
George
|
|
|
|
|
George_George wrote: Do you mean the pattern of MFC dialog is good or not?
I am not a MFC pro. Nor am I so much picky.
Things working smoothly will do. As cats being able to catch mice are considered good cats.
And I sometimes branch the patterns to what I want. (I am evil.)
George_George wrote: Does it relates to my original question?
Yes it does dedicate to asnwering your original question, regarding class X and the derived Y.
Maxwell Chen
|
|
|
|
|
Thanks Maxwell,
I read the MFC dialog sample and compare with my original question again.
1. The MFC sample as you mentioned, is good sample, flexible without any restriction to mesh-up base class parts and derived class parts into a function. And it provides flexible inheritance architecture in this way.
2. What I am asking in the original question, is about the limitation of the handle/body pattern when doing inheritance.
So, your sample (1) provides flexible way and the question I am asking is about limitations and uselessness (2), do they related? I am confused.
It is appreciated if you could provide more description.
regards,
George
|
|
|
|
|
Hi All,
I am trying to use CopyFile API for long file names (file name > 256)
When I specify
src: Normal path
dest: Long path
It works !
But when I specify
src: Long path
dest: Normal path
It fails saying "File Name or ext is too long"
Anybody knows the reason?
|
|
|
|
|
From the documentation[^]:In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File[^].
|
|
|
|
|
Thanks a lot for your quick soln.
|
|
|
|
|
I want to open the MIDI port at startup of the application and close it when the application is shutting down.
I am thinking of opening the port in InitInstance() function.
Which function should I use to close the port?
Thanks,
Suman
|
|
|
|
|
It is ExitInstance() function.
Thanks,
Suman
|
|
|
|
|
Its seems you know the answer when posted the question (only 4 min difference)
|
|
|
|
|
Rajkumar R wrote: Its seems you know the answer when posted the question (only 4 min difference)
Hi, not like that, after I have posted question, I was searching index help in vc++ IDE, got the function in "members" link. I might have saw it before posting it. I thought of deleting the question, but it may be useful for some other user, or atleast I will not ask it again.
Thanks for your comment.
Best Regards,
Suman
|
|
|
|
|
I'm sorry to post this question twice! But I realy need it...
My question is how can I change writing direction in an edit box in
RUN-TIME? (Right/Left Alignment)
|
|
|
|
|
See here.
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
|
|
|
|
|
Usef Marzbani wrote: I'm sorry to post this question twice! But I realy need it...
But you already got it.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: But you already got it.
Maybe he can't understand your reply because you wrote it Left to Right.
led mike
|
|
|
|
|
i need to create a function that can stop a process which takes long time.
i mean the user can stop the process while it is processing(just like a cancel buton). can i do this by using "backgroung worker"? i found some example code and information in C# but i couldnt in C++.
do i have to use multithreading?
|
|
|
|
|
strictly speaking you don't have to. but the alternatives can be pretty ugly, and even more trouble than using a worker thread.
use a worker thread.
|
|
|
|
|
Well unless your code is doing the processing you can't stop it without terminating the worker thread waiting on the process, which is not recommended.
led mike
|
|
|
|