|
Eric__V wrote: It seems that when an instance of a pure virtual base class is created, an instance of its child is in fact created.
When an instance of the derived class is created then you have also an instance of the base class (because 'derived' is 'base'): you cannot instantiate an abstract class.
Eric__V wrote: An observation. VS finds it impossible to debug step into any functions of the _child instance.
Visual Studio debugger should be able to do that (the debugger is one of the amazing features of Visual Studio, in my opinion).
Eric__V wrote: Further question. What if you have two descendents from _base. How does the compiler know which one to instantiate?
Choosing the appropriate derived class to instantiate (to get base class functionality) is up to you.
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
[My articles]
|
|
|
|
|
I dug a bit deeper and in fact the _base pointer instance is new'ed as the sub classes.
And now I saw that, I remember from about 12 years ago, that I have seen this before. Spent the last 10 years pretty much 100% in the kernel so I guess I got a bit rusty with the old C++ inheritance game.
==============================
Nothing to say.
|
|
|
|
|
Eric__V wrote: The code creates an instance of _base and uses it.
Maybe I do not understand the question correctly.
You cannot create an instance of the base class if it contains pure virtual member functions.
class Onion
{
public:
virtual void f( ) = 0;
};
class Tata : public Onion
{
virtual void f();
};
...
Onion onion; // will generate a compiler error.
...
Watched code never compiles.
|
|
|
|
|
Even
Tata tata;
would generate a compiler error...
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
[My articles]
|
|
|
|
|
CPallini wrote: would generate a compiler error...
No, that does not generate a compiler error.
But maybe you're laughing at something else ?
Watched code never compiles.
|
|
|
|
|
Did you try it?
In your code the function implementation is missing.
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
[My articles]
|
|
|
|
|
I think he meant that it won‘t be a compiler problem, but rather something the linker will stumble upon.
|
|
|
|
|
Good point. However I don't know if it is what he meant.
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
[My articles]
|
|
|
|
|
Your guess is as good a mine, I suppose. Only one person knows for sure.
|
|
|
|
|
It is never referenced, so the linker will not report it.
yeah, good catch!
Watched code never compiles.
|
|
|
|
|
But Onion* pOnion = new Tata is OK, and this is what the code was actually doing when I looked a bit deeper.
Doesnt explain VS though not debugging into the funcs.
==============================
Nothing to say.
|
|
|
|
|
Have you still not solved that issue? VS should step into virtual funcs - I do it every day, using VS 2003, and now that I switched it to VS2010 it works just as well.
Apart from your debugging a remote program - I haven't done that myself, the only thing I can think of is that your code does something different than you think it should. but without seeing the code we can't say. Can you extract the relavnt bits of your code (i. e. the declaration of the virtual func in the base class and how you overrode it in your derived class) and post it?
|
|
|
|
|
Havent got time to spend on the VS issue so it looks like I will never know.
==============================
Nothing to say.
|
|
|
|
|
sir/mam
can you please tell me if there is any particular reason why the following operators can't be oveloaded..
.
::
?:
|
|
|
|
|
You can read what the inventor of the language, Bjarne Stroustrup, thinks about this right here[^]. No-one can give you a better explanation than him.
|
|
|
|
|
Great link! The explanations are even better than those found in Stroustrup's 'The C++ Programming Language' (that's what I checked, I was especially curious about :? and am somewhat disappointed that there isn't even a good reason against overloading it. I could think of a good use or two...)
|
|
|
|
|
The entire page is a good resource.
In the next version of the standard I'm looking forward to see overloading of the new operators:
; - ) and : - P
|
|
|
|
|
The mentioned operators are used for only one purpose. Example in c++ the '.' operator used only for accessing member functions. (so there is no use of overloading '.' )
.
::
?:
But the symbols (+,- and etc..) are used to add numbers and objects .
Ex:
By default '+' operators are used for adding the numbers only and not the objects
(we are overloading the '+' operator to add the objects )
In c++ operator overloading takes the meaning as below
Operator Overloading: customize the operator to do other operations also(other than default operation).
clear?
|
|
|
|
|
The documentation states the mmioxxxx provides for unbuffered and buffered files.
The CFile supports only unbuffered files.
I am sending the data retrieved by wave API ( from buffer) to the mmioxxxx file.
So do I need mmioxxxx or not?
I am "doing" MFC in VC++
Any contructive help will be as always appreciated.
Cheers
Vaclav
|
|
|
|
|
Vaclav_Sal wrote: What are the basic benefits of using mmioxxxx “file” functions as opposed to “plain “ MFC CFile?
None.
THe mmioOpen docs also state "This function is deprecated. Applications should call CreateFile or CreateFileEx to create or open files. "
CreateFile or CreateFileEx are used in the windows implementations of most standard library and MFC file classes.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks again Mark.
Since I got my wave API going I 'll tackle this mmioxxx.
I do not remember but I think I done CFile before so it should not be much of a struggle this time.
I think I picked this mmioxxxx because the guy I copied it from build the wave file header and really did not explained why it was build that way. Most of the time when I use someone else program like that ( poorly documented) I get burned in the long run!
For example the stuff I used for wave hardly checks the functions returns. I think that is not very good programming style.
I think I need to read up on buffered and unbuffered files too.
Vaclav
|
|
|
|
|
Hi guys. I am stuck again with IOCP again. The problem is that, i just cannot create more then one worker thread. If i'll create more then one worker thread, for example 10 and on the other side there are 10 client connections, everything crashes in a random places, or it crashes because buffer for WSARecv is not allocated while in debugger i can see perfectly allocated buffer, or it crashes because socket is invalid - i just dont get it. While it is only one thread - it is working perfectly, when there more threads, it becomes unstable, and when there are 10 or more, it crashes after 1 second. Is there some magic trick i am missing again?
Thanks
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
|
Could only guess without seeing the code.
Some comments and random thoughts though...
The IOCP knows nothing about how many threads there are beyond how many are waiting on ::GetQueuedCompletionStatus().
There's no correlation between number of sockets (one for each client) associated with the IOCP and the number of worker threads. In fact, one thread per client is wrong and exactly what IOCPs are meant to eliminate.
So something is up in your code (obviously? ).
You can't share completion packets (OVERLAPPED structs) between sockets.
If the threads are accessing any common data objects then synchronization must be used.
For what it's worth, here's an example of an OVERLAPPED struct from one of my apps. Maybe it will spark something on your end...
Notes:
CClientConnection is a class that holds client information and also holds the socket handle and associated information.
pData is the I/O buffer, and is reallocated for each I/O operation. In my protocol I send a header of a known size first. That header has the number of following data bytes to expect.
dwDataLength and dwDataLengthProcessed are used tohandle situations where a single WSASend/WSARecv call doesn't process the total number of bytes requested. This MUST be done! There's no guarantee send and recv operations will send or receive all the bytes in one call. Successful completion could mean just a single byte!
#define OVERLAPPEDOP_NOOP 0
#define OVERLAPPEDOP_SOCKACCEPT 1 // CompletionKey = SOCKET, pData = 0
#define OVERLAPPEDOP_SOCKSEND 2 // CompletionKey = SOCKET, pData = NETCOMMPACKET*
#define OVERLAPPEDOP_SOCKRECVHEADER 3 // CompletionKey = SOCKET, pData = NETPACKETHEADER*
#define OVERLAPPEDOP_SOCKRECVPACKET 4 // CompletionKey = SOCKET, pData = NETCOMMPACKET*
#define OVERLAPPEDOP_EXITTHREAD 5 // CompletionKey = 0
#define MANAGEROP_ADDCLIENTCONNECTION 1 // pData = NEWUSERSOCKETINFO*
#define MANAGEROP_REMOVECLIENTCONNECTION 2 // lParam1 = CClientConnection*
#define MANAGEROP_REMOVEIOCPTHREAD 3 // lParam1 = CIOCPHandlerThread*
#define MANAGEROP_BROADCASTMESSAGE 4 // lParam1 = NETCOMMPACKETLITE* (alloc'd as BYTE*), lParam2 = CClientConnection* client to exclude
#pragma pack( push, SRVRMGR_OVERLAPPEDpack, 1 )
struct SRVRMGR_OVERLAPPED
{
OVERLAPPED Overlapped;
DWORD dwOpCode;
CClientConnection *pClientConnection;
LPARAM lParam1;
LPARAM lParam2;
DWORD dwDataLength;
DWORD dwDataLengthProcessed;
BYTE *pData;
SRVRMGR_OVERLAPPED() {memset(this, 0, sizeof(SRVRMGR_OVERLAPPED));}
};
#pragma pack( pop, SRVRMGR_OVERLAPPEDpack)
typedef CTypedPtrList<CPtrList, SRVRMGR_OVERLAPPED*> SRVRMGR_OVERLAPPEDPtrList;
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hey Mark. The worst thing is, i am sure that i am doing everything the exact same way but something is always wrong. I can give you the code only if i could send it to you - it is a solution with 5 projects and there are a LOT of lines, if you could take a look at it and point out mistakes i would appreciate it so much!!! (because i desperately need help with this ), can i ask you for this? please? My email: info[at]machinized[dot]com or maybe you can post yours, then i can send you the code. I am in pain
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|