|
pDerived->Base::Fun1()
Steve
|
|
|
|
|
hey this dont work it gives an error
class Base
{
public:
virtual fun1()
{
cout<<"Base::fun1 \n";
}
};
class Derived: Base
{
public:
virtual fun1()
{
cout<<"Derived::fun1\n";
}
};
void main()
{
Derived *der_ptr=new Derived;
Base *bas_ptr=new Base;
der_ptr->fun1();
der_ptr->Base::fun1() ;
}
Vikas Amin
Embin Technology
Bombay
|
|
|
|
|
You're missing the public keyword. Make your derived class look like this:
class Derived: public Base
This specifies public inheritence which is the "normal" choice.
Steve
|
|
|
|
|
Oh yeh
thank you
Vikas Amin
Embin Technology
Bombay
|
|
|
|
|
Also, to complete the other answers, the rule with the virtual keyword is as follow: if the function is not virtual, it will call the function from which the pointer is related to. Take this example:
void main()<br />
{<br />
Base *bas_ptr=new Derived;<br />
<br />
der_ptr->fun1();<br />
} <br />
In this case, if fun1 was not declared as virtual, the function called would be the one from the base class, because your pointer is of the type Base, even if it has been created as a Derived class. Now, take the same example but instead declare fun1 as virtual, then in that case the function that will be called would be the one from the child class.
Hope it makes thing more clear
|
|
|
|
|
Yeh i got the point
The function that is called depends on object if Virtual
but it depends on the pointer if its Non-virtual
A derived pointer cannot point to a Base class object
with type-casting we can assing a derived class pointer to a base class object
say by static_casting , is it a good practise ?
Vikas Amin
Embin Technology
Bombay
|
|
|
|
|
vikas amin wrote: The function that is called depends on object if Virtual
but it depends on the pointer if its Non-virtual
More or less. In fact, with a virtual function, you will have what is called a virtual function table, that is a table that will replace the pointers of the virtual functions of the base class by those of the derived class.
vikas amin wrote: A derived pointer cannot point to a Base class object
I don't really understand your point here. You can always look at a pointer to a derived class as a pointer to the bass class. That's how polymorphism works: you have a bunch of pointers to one base class but each of them is instancied as a specific derived class (derived1, derived2, ...) and they are all treated as if it was a bas class.
vikas amin wrote: with type-casting we can assing a derived class pointer to a base class object
say by static_casting , is it a good practise ?
Yes, you can always cast a derived class into its base class (again, that's used with polymorphism). But in general, you don't need to cast it. In general, when you use virtual functions it is for overriding some of the properties of your base class and replace them with properties of your child class.
|
|
|
|
|
wrote code for downloading a file, what do i do to pause in between using a button on the dialog box? Somebody please help...
|
|
|
|
|
|
Can anyone help me program an OS?
--------------------------
Eric
I still need to learn C++!
--------------------------
|
|
|
|
|
wow, that is a very tough question you have there.
waxie
|
|
|
|
|
First:
Read about PC boot procedures and events. You could also look at a free OS (Linux? FreeDOS?) in order to learn how they implemented that. Or you could resort to a "boot-manager" ala LILO or GRUB and try to build on that.
You also need to read about processor modes (real mode, protected mode, how to switch between them, etc.).
When you have a basic OS up (probably mostly ASM-code) you can think about porting a compiler (GCC?), probably in an older version, to work on your OS. Remember that almost all "new" compilers are compiled by an "old" compiler.
If you are that far, think about porting "standard tools" like directory browsing (have you decided on a partition format yet or are you gonna create your own?) and a driver framework.
Building a VERY BASIC OS may not be too difficult. I remember seeing a book about that once, which claimed that you could write your own "basic" OS within a few weeks of work.
I hope this helps
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
That's like asking "How do I write a 3D game?" such a broad question that if you ask it you aren't ready to write one.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
Hi,
Could you provide me a code snippet on how to acquire the IP address of the computer? I'm not using .NET just a pure visual c++ IDE. I just want to get the ip address of my computer and store it in a string.
If you could give me an idea on how to do that without using the .NET environment, I'd really appreciate it very much.
Thanks,
Christina J.
|
|
|
|
|
Look up GetIpAddrTable in MSDN.
|
|
|
|
|
Hi,
IS this what yoo are looking for?
struct hostent *Host;
SIZE_T t=100;
CString szIP , szName;
char *host_name = new char[100];
gethostname(host_name,t);
Host = gethostbyname(host_name);
szName = host_name;
szIP = inet_ntoa(*((struct in_addr*)Host->h_addr));
delete []host_name;
Regards,
Eli
|
|
|
|
|
hi everybody,
i need all computer name in a network fastly but i have make a following code which is able to get all machine name but its time taken i am giving code for you if there is possibility to change in this code to get fastly so please change this code and reply me ASAP.
BOOL CMessangerDlg::Enumration(int level, NETRESOURCE *pnr, CListCtrl *clistctrl)
{
DWORD rc;
HANDLE hEnum;
CString strTemp;
DWORD count, bufsize, ui;
NETRESOURCE buf[200];
const char *type, *cont;
//GetDlgItem(IDC_BTN_SEND)->EnableWindow( FALSE );
WORD version;
WSADATA wsaData;
int rVal;
version=MAKEWORD(1,1);
rVal=WSAStartup(version,(LPWSADATA)&wsaData);
rc = WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, pnr, &hEnum );
if ( rc == ERROR_ACCESS_DENIED )
{
return 1;
}
while ( 1 )
{
count = (DWORD) -1L;
bufsize = sizeof buf;
rc = WNetEnumResource( hEnum, &count, buf, &bufsize );
if ( rc != NO_ERROR )
break;
Sleep(0);
for ( ui = 0; ui < count; ++ ui )
{
//AfxMessageBox("hello2");
switch ( buf[ui].dwDisplayType )
{
case RESOURCEDISPLAYTYPE_DOMAIN:
type = "domain"; break;
case RESOURCEDISPLAYTYPE_GENERIC:
type = "generic"; break;
case RESOURCEDISPLAYTYPE_SERVER:
type = "server"; break;
case RESOURCEDISPLAYTYPE_SHARE:
type = "share"; break;
default:
type = "unknown"; break;
}
cont = ( buf[ui].dwUsage & RESOURCEUSAGE_CONTAINER )? "container": "";
if(level==2)
{
//AfxMessageBox("hello3");
CString networkmachinename;
CString str;
str=buf[ui].lpRemoteName;
str.Remove('\\');
LPHOSTENT host=gethostbyname(str);
//AfxMessageBox(str);
if(host==NULL)
{
//AfxMessageBox("one machine is off");
continue;
}
else
{
clistctrl->InsertItem(li," ");
clistctrl->SetItemText(li,0,str);
//clistctrl->SetItemText(li,1,str);
li++;
CString member;
member.Format("%d",li);
m_member.SetWindowText(member);
}
}
if ( buf[ui].dwUsage & RESOURCEUSAGE_CONTAINER)
{
Enumration( level + 1, &buf[ui] ,clistctrl);
}
}
}
WNetCloseEnum( hEnum );
Sleep(0);
WSACleanup();
return 0;
}
Bankey Khandelwal
Software Engineer
Solversa TechnologiesPvt.Ltd.
15,Yeshwant Nagar
Range Hill Road
Ganeshkhind,Pune-03
bankey.khandelwal@solversa.com
Mobile: +91-9850432990
Office : +91-20-25521888
|
|
|
|
|
I have one dailog box with two functions as exercise and monitor...My question is....When i check the exercise check box the monitor should diable...after finishing the exercixe function...automatically the monitor should get enable?My functions are in threads....
How can i ??
PLs help me..,..
|
|
|
|
|
|
Anu_Bala wrote: My question is....When i check the exercise check box the monitor should diable...after finishing the exercixe function...automatically the monitor should get enable?
Use EnableWindow() for this.
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
Have your worker threads post predefined windows messages (custom user-defined messages) back to the dialog, in the message handler the dialog enables/disables the controls as needed.
It's usually best to communicate with your GUI thread from your worker threads using messages. Takes away a lot of synchronization issues too, since messages are by definition synchronous.
I think there's a good article somewhere on Dr. Joseph Newcomer's site on this subject: www.flounder.net
Good Luck!
Mike Stephenson
|
|
|
|
|
Hi all
I need your guidelines, problem is something like this
I want to add keboard hendling in already existing project.
First Suppose that
1) There is a CList in which many items are there.
2) when user double click on any item(row) of the list then a Tabbed dialog box appears in which we have all the settings related information of selected items.
3) So here I need that dispite of double clicking, user must be able to see same tabbed dialog box by entering to that item
Please help me.
Thanks
|
|
|
|
|
I think you have already written the code for opening that Tabbed dialog box you were talking about. (When double clicked). So your problem is to handle the key press event. You can easily solve this by overriding the PreTranslateMessage() .
Regards,
Rajesh R. Subramanian
You have an apple and me too. We exchange those and We have an apple each.
You have an idea and me too. We exchange those and We have two ideas each.
|
|
|
|
|
Thanks for your advise.
Could you please tell me by some code snippet that how can I override PreTranslateMessage()message.
Please reply
Thanks
|
|
|
|
|
rajeevktripathi wrote: how can I override PreTranslateMessage()message
MFC or plain WIn32 ?
~RaGE();
|
|
|
|