|
I was thinking the same.
John
|
|
|
|
|
Hi Mike,
Thanks.. No particular reason mike. It was an interview question.
I just want to confirm whether it is possible.
Mahesh
|
|
|
|
|
You can't - an abstract class is defined as having at least one method be virtual and not having an implementation. e.g.,
class VirtualClass
{
public:
virtual void OverrideMe() = 0;
};
A compiler won't let you instantiate such a class. If you can instantiate it, then it is not an abstract class.
"When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein
|
|
|
|
|
We can prevent the instantiation of the class by making it's constructors private, however the problem with this is that the class cannot be derived then.
|
|
|
|
|
Just a thought... did you have the __declspec(novtable) extension in mind?
If so, keep in mind that the novtable attribute does not semantically mark the class as abstract; rather, it just removes the vtable initialization code. It just happens that this is most useful for application to abstract classes.
- Mike
|
|
|
|
|
Hi,
Im writing 2 programs in VC++6 that broadcast messages to each other. One is a full blown windows program, complete with message map and handles incoming messages perfectly. The second however is a small console program, consisting of int main() and 1 global function. All of the examples i have seen implement the message map in dialog classes. Is it possible to implement it globally like shown below?
MESSAGE_MAP()
....
void GotAMessageWooYay()
{
...
}
int main()
{
...
}
|
|
|
|
|
How are you going to broadcast messages to the console application?? I think you need at least a hidden window there. Unless you send thread messages.
John
|
|
|
|
|
I agree, messages are sent through the winproc, and if there is no window, there is no proc.
|
|
|
|
|
Does anyone know how to get around the 31 character limit in IStorage::CreateStorage and IStorage::CreateStream?
I am trying to use the IMAPI functions to programmatically burn data to a cd which I have been able to do successfully, however, I can't seem to get around the 31 character limit when trying to burn a file whose name exceeds 31 characters.
Any suggestions?
|
|
|
|
|
Hi,
I have two dialog boxes, the first one is a normal one with the default buttons ok and cancel, while the second has a ok and a combobox.
The program is supposed to work like this.
When a person clicks ok in the first dialog box, the program takes the "DEFAULT" values and does some job . if cancel is clicked, the second dialog box is opened and some data is chosen from the combobox and takes this value and does the same job.
when the job is done the application is closed,
Now when I open the application once again, I want the last chosen value from the combobox to be set as the "DEFAULT" values . Is there a specific way to do this..
Can anyone suggest me ways as to how to proceed..
Thanks.
Deepak Samuel
|
|
|
|
|
Get the selected item # of the combobox and save it in the registry using AfxGetApp()->WriteProfileInt(). Get it back using AfxGetApp()->GetProfileInt().
John
|
|
|
|
|
Look up history combo here at code project.. Should be in the combo & list box section.. It will do what you want..
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Thanks for reminding me of that. I remember that is a good implementation so better not reinvent the wheel...
John
|
|
|
|
|
Does anyone out there have experience with job objects??? The JOB_OBJECT_PROCESS_ID_LIST structure (which contains (namely) the PID's for all processes running in a job) will only give me the PID for the first process that I assign to the job. (i.e. if I assign Processes with PID's 1132, 1322, and 898, the only PID in the structures member "ProcessIdList" is 1132). If anyone has any insight on this poorly documented subject I would be eccstatic. TIA
|
|
|
|
|
Hay im havin a problem trying to scan if my server is up using winsock because i cant scan the specific port is being used....
anyone know how i could do this?
thanks
|
|
|
|
|
Why is the size of an object of an empty class 1??
class Empty
{
};
void main()
{
Empty ob;
cout << sizeof(ob); //prints 1
}
Any idea why it should print 1? It cannot be the address of something because one byte is not sufficient to store a valid address in WIN32.
|
|
|
|
|
Check this out:
http://www.research.att.com/~bs/bs_faq2.html#sizeof-empty
|
|
|
|
|
According to Bjarne Stroustrup's
"To ensure that the addresses of two different objects will be different. "
However I'm not convinced. One byte is not enough to store any kind of address!!!
Anyway thanks David.
|
|
|
|
|
Yeah, I'm sure Dr. Stroustrup missed that action item. Anyway, don't confuse the size of an item with the size of its address. The size of the class is 1 byte, but it's address is still 4 bytes.
|
|
|
|
|
As others pointed out, the size of empty class objects is not zero so that pointers pointing to different objects do not have the same address value. Your confusion arises from asuming that the object somehow stores its own address: it doesn't, it is the pointers that store the address to the piece of memory occupied by the object (typically one byte). If you don't see it yet, consider the case of char s and pointers to char .
On a sidenote, there's an optional feature called empty base optimization by which an empty class object can effectively occupy zero bytes when it acts as a base of another class. Consider:
struct A{};
struct B{char m;};
struct C:public A{char m;}; Class C can be applied this optimization so that, so to say, its A base takes no space. This can be done as the space occupied by C itself (not taking into account A ) serves as the "token" byte where pointers to A can be set to.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you Joaquín for taking the time to explain it to me. It's now become clear to me. Essentially the address of every object of a class (whether empty or containing members) should be unique.
Regards,
Melwyn
|
|
|
|
|
I have a CListCtrl that I use for logging. For every item that is inserted (always at the back/bottom) I call EnsureVisible() . The annoying thing is, when I try to scroll to an older entry, the list control jumps to the new entry being inserted (ofcourse).
What I would like to do is implement the behaviour of the visual studio output window, i.e. only jump to the latest entry when the vertical scrollbar is set to it's max. (bottom) position. However, when I try something like this:
if (GetScrollPos(SB_VERT) == GetScrollLimit(SB_VERT) -1)<br />
{<br />
EnsureVisible(GetItemCount() - 1, TRUE);<br />
SetScrollPos(SB_VERT, GetScrollLimit(SB_VERT) -1);<br />
}
the cursor of the scrollbar keeps jumping up and down.
Anyone know how to do this the right way?
|
|
|
|
|
Hi!
If I use some "normal" MFC class, VisualStudio offers
such a nice name completition (inteli sense?!)
but with the gdi+ classes, the IDE dont show me the
hints, which methods a class has.
anybody an idea, how to enable it?
|
|
|
|
|
Intellisense in VisualStudio(6) is more or less broken, particularly when you are using third party libraries, you can get away with tools like Visual Assist.
Check out http://www.wholetomato.com
I think they have a 30 day trial.
Cheers,
Kannan
|
|
|
|
|
Ok, this is going to be confusing to explain, but simple to fix (me thinks).
I have a dialog box that pops up asking a user for a password. if they enter the icorrect password, another box pops up saying "Retry or Cancel". when the user hits Retry, i want it to start over (ie pop the password dialog box back up.)
Here's the code:
///*in PropsView.cpp*///
<br />
void CPropsView::OnWindowTransducers()<br />
{<br />
m_password.DoModal();<br />
bool bleh = g_password;<br />
if(bleh == TRUE)<br />
{<br />
m_chsheet.DoModal();
}<br />
else<br />
{<br />
m_fail_pass.DoModal();
m_password.DestroyWindow();<br />
}<br />
g_password = FALSE;<br />
}<br />
in another cpp file, I have an OnOk() statement if the user hits "retry". But, since that onok is in another cpp file, i can't do m_fail_pass.DestroyWindow() to close the retry/cancel window, and i dont know how to make the loop start at the top again with the Password Dialog.
Does anyone get what i mean?
*.*
cin >> knowledge;
|
|
|
|