|
Zac Howland wrote: It is more like copying every member of the base class into the child class, but putting it all under the private keyword. The child class can see (that is call) the base class' methods, but any outsiders would only be able to call the child class' public methods.
Not really. OP got it right, just used protected in his sample.
|
|
|
|
|
Nemanja Trifunovic wrote: Not really. OP got it right, just used protected in his sample.
Check again (he copied the example from the C++ FAQ):
lass Wilma {
protected:
void fredCallsWilma()
{
std::cout << "Wilma::fredCallsWilma()\n";
wilmaCallsFred();
}
virtual void wilmaCallsFred() = 0;
};
class Fred : private Wilma {
public:
void barney()
{
std::cout << "Fred::barney()\n";
Wilma::fredCallsWilma();
}
protected:
virtual void wilmaCallsFred()
{
std::cout << "Fred::wilmaCallsFred()\n";
}
};
also
class D_prot : protected B {
public:
using B::f;
}
For more information, check out this: http://www.gotw.ca/publications/mill06.htm[^]
And if you still don't believe me, try this:
#include <iostream>
using namespace std;
class Base
{
public:
Base() { cout << "Base::Base()" << endl; }
virtual ~Base() { cout << "Base::~Base()" << endl; }
void Print() { cout << "Base::Print()" << endl; }
};
class Child : private Base
{
public:
Child() { cout << "Child::Child()" << endl; }
virtual ~Child(){ cout << "Child::~Child()" << endl; }
void MyPrint()
{
cout << "Child::MyPrint()" << endl;
Print();
}
};
int main()
{
Child c;
c.MyPrint();
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
You're right. I didn't carefully look at his code, and it was a part of your comment that confused me :
It is more like copying every member of the base class into the child class, but putting it all under the private keyword
From the outsider's point of view it is correct, but the child class cannot access non-public members of base, and if you copy every member of the base to child's private section, all of them would be accessible from the child.
|
|
|
|
|
Nemanja Trifunovic wrote: From the outsider's point of view it is correct, but the child class cannot access non-public members of base, and if you copy every member of the base to child's private section, all of them would be accessible from the child.
The child class can access protected members, but no, it can't access private members.
As a side note, this is part of why it is recommended to NOT use private inheritance unless it is absolutely necessary (which it only is in very few cases) and instead use aggregation.
[sarcasm]Of course, my favorite type of inheritance is still protected .... [/sarcasm]
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
That's because you are using protected , not private
[EDIT] Forget it - didn't read the code sample well[/EDIT]
-- modified at 13:11 Friday 13th October, 2006
|
|
|
|
|
Hi
I am very new to VC++ ,I want to add a progress bar. Can anybody tell me how to put a progress bar in an application
Waiting for reply
|
|
|
|
|
You can see two examples of CProgressCtrl class on MSDN
|
|
|
|
|
Hi,
Use CProgressCtrl class or CreateWindow with PROGRESS_CLASS as its class name.
Regards
|
|
|
|
|
you can look at msdn sample CMNCTRL2. It has a sample of CProgressCtrl. but as a sample
//make a memebr variable
CProgressCtrl m_Progress;
//in OnInitDialog()
m_Progress.Create(WS_VISIBLE | WS_CHILD, rect, this, IDC_PROGRESS);
m_Progress.SetRange(0, 30);
//set the step by
m_Progress.SetStep(2);
//increment it
m_Progress.StepIt();
//or set position by
m_Progress.SetPos(26);
|
|
|
|
|
Javagal Srinath wrote: Can anybody tell me how to put a progress bar in an application
Like you would any other control. With your dialog template open in the resource editor, just select the control (in the Controls window) you want to add and then click the dialog. Move and size as needed.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I want to copy the items from the tree control that are selected using checkboxes into the File Open Dialog Box.To be brief my aplication consists of tree conrol and button in a form view.When i press the button File open Dialog Box is opening.Now i want to add the selected items from the tree control to that opened window.How can i do it.
Thanks.
|
|
|
|
|
Hi,
Open file dialog box is not designed for such functionality, it is common dialog box, though it is not impossible.
Use CopyFile, MoveFile functions to copy files to specified directory.
Regards
|
|
|
|
|
Galatei wrote: Open file dialog box is not designed for such functionality, it is common dialog box, though it is not impossible.
The open file dialog allows dragging and dropping files
Mark
|
|
|
|
|
Is there any article that contains dragging and dropping folders from tree control to the outside environment i.e,open file dialog box or desktop etc.If it is there please tell me ,it is very urgently needed for my project.
|
|
|
|
|
|
I have a application in which I open a file to edit in Notepad. But when I used the _execl() function, the dialog disappeared and Notepad was active. I can not to find the way that is appropriate to fix the problem so I want to have help from more experient people. sincerely thank alot
duc an
|
|
|
|
|
Hi,
AFAIK _execl & _wexecl doesn't return to the calling process if operation was successfull.
You can use ShellExecute , to do that, with a lot more flexibility.
Regards
|
|
|
|
|
Pham duc an wrote: But when I used the _execl() function...
Why use such antiquated functions when CreateProcess() and ShellExecute() are available?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
My project code is same as below. In the below code i get an exception when i delete the amount.
Please kindly tell me what exactly is wrong in the below code.
I should be able to use the values and also delete it.
#include "stdafx.h"
#include "iostream.h"
#include "iomanip.h"
#include <algorithm>
#include <vector>
void fun(long **a);
int main(int argc, char* argv[])
{
long *amount = NULL;
fun(&amount);
for (int i = 0; i<5 ;++i,++amount)
{
cout<< *amount <<endl;
}
="" delete="" amount;="" i="" get="" an="" exception="" here.
="" return="" 0;
}
void="" fun(long="" **a)
{
="" *a="new" long[5];
=""
="" std::vector<long=""> var;
var.push_back(5);
var.push_back(6);
var.push_back(65);
var.push_back(58);
var.push_back(57);
std::vector<long>::iterator i;
int k = 0;
for(i= var.begin();i != var.end();++k, ++i)
{
a[k] = new long;
(*a)[k] = *i;
}
}
Thanks in advance!
Thanks & Regards,
Dhana
|
|
|
|
|
Hi,
That's very simple. When you increment amount pointer, you actually change its address, which is not valid when you call delete.
You can do something like this to avoid its modification (in main):
...
long *ptr = amount;
for (int i = 0; i < 5 ;++i,++ptr) {
cout<< *ptr << endl;
}
delete [] amount;
...
Regards
|
|
|
|
|
Thank you, but i still get the same error.
Thanks & Regards,
Dhana
|
|
|
|
|
jana_dhana wrote: for (int i = 0; i<5 ;++i)
{
cout<< amount[i] <<endl;
}< blockquote="">
Why you need to increment address?As you need to delete it.Use indexing instead.
jana_dhana wrote: a[k] = new long;
Whats this for ?
I've modified your code like this,
#include "iostream.h"
#include "iomanip.h"
#include <vector>
void fun(long **a);
int main(int argc, char* argv[])
{
long *amount = NULL;
fun(&amount);
for (int i = 0; i<5 ;i++)
{
cout<< amount[i]<<endl;
}
delete [] amount;
return 0;
}
void fun(long **a)
{
*a = new long[5];
std::vector<int> var;
var.push_back(5);
var.push_back(6);
var.push_back(65);
var.push_back(58);
var.push_back(57);
std::vector<int>::iterator i;
int k = 0;
for(i= var.begin();i != var.end();++k, ++i)
{
(*a)[k] = *i;
}
}
-- modified at 10:57 Friday 13th October, 2006
-- modified at 10:58 Friday 13th October, 2006
|
|
|
|
|
i get the same errors with the above code also.
Thank you.
Thanks & Regards,
Dhana
|
|
|
|
|
Oh ! posted wrong code.
See modified code above now.
|
|
|
|
|
jana_dhana wrote: fun(&amount);
fun() is expecting a pointer to a pointer to a long . However, you are calling it with just a pointer to a long .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|