|
It was already checked. It shows up fully in my browser (chrome) and in IE just fine. Not sure why you can't see it.
--
Joseph Dempsey
Sr. Software Engineer
joseph_r_dempsey@yahoo.com
|
|
|
|
|
I'm using chrome and this is what I see -
#include
class Cloneable
{
public:
template TYPE* clone() const { return dynamic_cast< TYPE* > ( clone() ); }
virtual Cloneable* clone() const = 0;
};
class X : public Cloneable
{
public:
X(int _y ) : data(_y) { }
virtual ~X() { }
virtual Cloneable* clone() const { return new X(data); }
protected:
X() { }
int data;
};
class Y : public X
{
public:
Y(double f, int y) : X(y), dataf(f) { }
virtual ~Y() { }
virtual Cloneable* clone() const { return new Y(dataf, data); }
protected:
double dataf;
};
int main(int argc, char* argv[])
{
X* x = new X(1);
X* x1 = x->clone();
Y* y = new Y(2.12, 4);
Y* y1 = y->clone();
delete y;
delete y1;
delete x;
delete x1;
return 0;
}
|
|
|
|
|
ok... not sure whats going on there but i tried repasting it with and w/o the checkbox and it still shows up erred.
Its missing the angle brackets obviously. The code itself is correct syntactically. Just pretend they are there If you're real interested in seeing the actual file i can email it.
* EDIT: Screw it... just removed HTML completely. should show up right now.
--
Joseph Dempsey
Sr. Software Engineer
joseph_r_dempsey@yahoo.com
|
|
|
|
|
|
Good call, forgot about using using to add functions to the overload set.
Cheers,
Ash
|
|
|
|
|
Have a dig in the standard for the rules on overload resolution and how it interacts with template expansion. As both VC++ later than 2002 and gcc 4.x agree on the behaviour it's probably standard. Essentially it looks like what's happening is that clone<T> is not part of the overload set for Y::clone() and X::clone() as there functions with that name already in the class of the pointer you're calling through.
One of three solutions spring to mind. Either make clone<t> an ordinary function, change it's name or call it explicitly. e.g. if you change your base class to:
class Cloneable
{
public:
template<class TYPE> TYPE* clone_as() const { return dynamic_cast< TYPE* > ( clone() ); }
virtual Cloneable* clone() const = 0;
};
and change your client code to match things work the way I think you think they should. Incidentally be very careful writing code like this... You can write leaky code very easily:
int main()
{
X x( 7 );
Cloneable *p = &x;
Y *py = p->clone_as<Y>();
}
leaks an X. I'd be tempted to return shared_ptrs or auto_ptrs to avoid this sort of faux pas.
Basically the interaction between overloading, overriding and templates (i.e. when templates are expanded and considered part of the set of overload candidates) is a nightmare. My advice would be avoid it unless you're writing a compiler.
Cheers,
Ash
PS: This is very similar to the well known interaction between overrides and overloads with implicit conversion:
class base
{
public:
virtual void do_something( int ) { std::cout << "Doing the base class int thing" << std::endl; }
virtual void do_something( double ) { std::cout << "Doing the base class double thing" << std::endl; }
};
class derived : public base
{
public:
virtual void do_something( double ) { std::cout << "Doing the derived class double thing" << std::endl; }
};
int main()
{
derived d;
d.do_something( int( 7 ) );
}
This could always prints the derived class double message. You get around this by either changing the name or calling the function explicitly.
PPS: Superman's solution from the mouth of Bjarne would work as well - I didn't consider it as using declarations have their own fun properties which you may or may not be happy with.
modified on Saturday, November 6, 2010 2:48 AM
|
|
|
|
|
I wouldn't recommend to do it that way at all.. Let Clonable be what it is, an interface with no implementation, skip the template member completely. In your example you don't need to cast anything, if you use covariant return type for overrides of clone inimplementations of Clonable :
class X : public Cloneable
{
virtual X* clone() const { return new X(data); }
};
class Y : public X
{
virtual Y* clone() const { return new Y(dataf, data); }
};
int main(int argc, char* argv[])
{
X* x = new X(1);
X* x1 = x->clone();
Y* y = new Y(2.12, 4);
Y* y1 = y->clone();
return 0;
}
As suggested above, usage of an std::auto_ptr is preferable, but only in client code, since otherwise you loose the ability to define covariant return types. I am using a "Cloner" utility for comfortable casts to derived types which looks something like this:
class ClonerUtility {
template <class TCoVariantClonable>
static std::auto_ptr<TCoVariantClonable> CloneAs(const Clonable& pToBeCloned) {
std::auto_ptr<Clonable> tClone(pToBeCloned.clone());
if (TCoVariantClonable* tCoVariantClone =
dynamic_cast<TCoVariantClonable*>(tClone.get())) {
tClone.reset(0);
return std::auto_ptr<TCoVariantClonable>(tCoVariantClone);
}
return std::auto_ptr<TCoVariantClonable>();
}
template<class TCoVariantClonable>
static std::auto_ptr<TCoVariantClonable> Clone(const TCoVariantClonable& pToBeCloned) {
return std::auto_ptr<TCoVariantClonable>(pToBeCloned.clone());
}
};
int main(int argc, char* argv[])
{
std::auto_ptr<X> tX(new X);
std::auto_ptr<X> tCloneX = ClonerUtility::Clone(*tX);
Clonable& tPureClonable = *tCloneX;
std::auto_ptr<X> tOtherCloneOfX = ClonerUtility::CloneAs<X>(tPureClonable);
}
modified on Sunday, November 7, 2010 4:05 AM
|
|
|
|
|
I'm trying to get write a message-only window to receive device change notification messages for a USB device. I am using MFC, C++, and Visual Studio 2008. Everything compiles, and it runs without crashing or locking up, but the event handler is never triggered. The device of interest is installed on Windows as a virtual COM port.
My main application instantiates the class described below then waits for a character input from the keyboard polling using a while loop. It is during this wait time that I remove and insert my USB device expecting the event to get fired.
class CMessageOnlyWindow : public CWnd
{
DECLARE_DYNAMIC(CMessageOnlyWindow)
private:
DEV_BROADCAST_DEVICEINTERFACE * _pDevIF;
HDEVNOTIFY _hNotifyDev;
public:
CMessageOnlyWindow();
virtual ~CMessageOnlyWindow();
protected:
afx_msg BOOL OnDeviceChange( UINT nEventType, DWORD dwData );
private:
void RegisterNotification( void );
void UnregisterNotification( void );
protected:
DECLARE_MESSAGE_MAP()
};
For simplicity, I've removed all the cleanup and error-handling:
DEFINE_GUID(GUID_INTERFACE_CP210x, 0x993f7832, 0x6e2d, 0x4a0f, \
0xb2, 0x72, 0xe2, 0xc7, 0x8e, 0x74, 0xf9, 0x3e);
IMPLEMENT_DYNAMIC(CMessageOnlyWindow, CWnd)
CMessageOnlyWindow::CMessageOnlyWindow()
{
CString cstrWndClassName = ::AfxRegisterWndClass( NULL );
BOOL bCreated = this->CreateEx( 0, cstrWndClassName,
L"CMessageOnlyWindow", 0, 0, 0, 0, 0, HWND_MESSAGE, 0 );
this->RegisterNotification();
}
CMessageOnlyWindow::~CMessageOnlyWindow() {}
BEGIN_MESSAGE_MAP(CMessageOnlyWindow, CWnd)
ON_WM_DEVICECHANGE()
END_MESSAGE_MAP()
afx_msg BOOL CMessageOnlyWindow::OnDeviceChange( UINT nEventType, DWORD dwData )
{
switch ( nEventType )
{
case DBT_DEVICEARRIVAL:
break;
case DBT_DEVICEREMOVECOMPLETE:
break;
default:
break;
}
return TRUE;
}
void CMessageOnlyWindow::RegisterNotification(void)
{
_pDevIF = (DEV_BROADCAST_DEVICEINTERFACE *)malloc( sizeof(DEV_BROADCAST_DEVICEINTERFACE) );
memset( _pDevIF, 0, sizeof(DEV_BROADCAST_DEVICEINTERFACE) );
_pDevIF->dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
_pDevIF->dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
_pDevIF->dbcc_classguid = GUID_INTERFACE_CP210x;
_hNotifyDev = RegisterDeviceNotification( this->m_hWnd, _pDevIF, DEVICE_NOTIFY_WINDOW_HANDLE );
}
void CMessageOnlyWindow::UnregisterNotification(void)
{
UnregisterDeviceNotification( _hNotifyDev );
}
Any thoughts or suggestions would be much appreciated. If any details are missing, let me know, and I will be glad to add them. Thanks.
Does the message-only window need to be started in a new thread, or does creating a new window automatically spin off a new thread?
ADDITIONAL INFO
Changing the type of recipient handle passed to `RegisterDeviceNotification` to `DEVICE_NOTIFY_ALL_INTERFACE_CLASSES` caused it to start working. Do you know why that would make a difference, or are there any problems, if I leave it like this?
modified on Friday, November 5, 2010 12:18 PM
|
|
|
|
|
AFAIK the window will only get messages when it is "visible" and non-minimized, which means you should show it on the desktop, at any location you like, including (-1000,-1000) to keep it out of sight.
|
|
|
|
|
Thanks, Luc. I tried specifying a location with the same lackluster results:
BOOL bCreated = this->CreateEx( 0, cstrWndClassName,
L"CMessageOnlyWindow", -1000, -1000, 100, 100, 0, HWND_MESSAGE, 0 );
|
|
|
|
|
I was thinking you had to actually show the window (hence the off-screen coordinates), howver my source code (which is C#) doesn't, and works well. I'm afraid I can't help you.
|
|
|
|
|
Hi again,
I happened to require detection of memory stick insertions (in C# again), and experimented a bit more. My conclusion is the app needs a window that is shown, non-minimized, possibly off-screen, and then overriding the wndProc yields the necessary events. So I chose "manual window position" with a bounding rectangle of (-32000,-32000,100,100) and it works well; it does not when minimized or not shown at all.
|
|
|
|
|
I've got that configuration Video capture -> Sample Grabber -> Null renderer to play video file.
I'd like to able to seek to any position in a video file to grab raw image data.
If the filter graph is stopped, then seek is performed to specific position and then run again sample grabber captures the correct image. But graph stop and run takes significant amount of time.
If the graph is already running the seeking does not position to correct location however. It is always the first frame or in some video file only after second seeking operation to the same location sample grabber returns correct frame.
m_pSeeking->SetPositions(&m_pPosition, AM_SEEKING_AbsolutePositioning, NULL, NULL);
Чесноков
|
|
|
|
|
And what about the method return value?
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]
|
|
|
|
|
There are no errors. All HRESULTS are OK.
Initially I wanted to seek to specific location in video file, then run the graph, wait for completion and get buffer.
Seeking function
<br />
m_pPosition = (1000000 * (LONGLONG)millisecond) / 100;<br />
hr = m_pSeeking->SetPositions(&m_pPosition, AM_SEEKING_AbsolutePositioning, &m_pStop, AM_SEEKING_AbsolutePositioning);<br />
if (FAILED(hr)) <br />
return -2;<br />
hr = m_pSeeking->GetCurrentPosition(&m_pPosition);<br />
if (FAILED(hr)) <br />
return -3;<br />
Grabbing function
<br />
hr = m_pMC->Run();<br />
if (FAILED(hr)) <br />
return -2; <br />
long evCode;<br />
hr = m_pEvent->WaitForCompletion(m_TimeOut, &evCode);<br />
if (FAILED(hr)) <br />
return -3;<br />
hr = m_pMC->Stop();<br />
if (FAILED(hr)) <br />
return -4;<br />
hr = m_pGrabber->GetCurrentBuffer((long *)&m_BmiHeader.biSizeImage, (long *)pFrameData);<br />
if (FAILED(hr))<br />
return -5;<br />
I used SetOneShot(TRUE); during sample grabber setup to make sure graph filter stops after single grabbing.
But that resulted in significantly slower grabbing due to filter graph run/stop operation.
I realized that it is possible to seek to any location while filter graph is already running as specified in documentation so I used SetOneShot(FALSE) and moved graph running and stopping from grabbing function.
But with SetOneShot false WaitForCompletion returns 0x80004004 if wait interval is specified or never returns with INFINITE wait period.
Is there fast seeking approach to grab raw image data with sample buffer?
Чесноков
|
|
|
|
|
Chesnokov Yuriy wrote: But with SetOneShot false WaitForCompletion returns 0x80004004 if wait interval is specified or never returns with INFINITE wait period
And what is the evCode value?
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]
|
|
|
|
|
evCode = 0;
That is wierd. With SetOneShot set to TRUE filter graph does not stop as it should after sample grabber frame capture.
With SetOneShot set to FALSE WaitForCompletion never returns.
Чесноков
|
|
|
|
|
Any pointer to some good example on how to use the CTreeCtrl ?
|
|
|
|
|
|
bad answer... I've already done that and could not find just a full example of the
basic CTreeCtrl, otherwise I wouldn't ask it here, would I ?
|
|
|
|
|
The answer is actually correct.
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]
|
|
|
|
|
With smart-aleck replies like this, you'll be lucky to receive any further help in the future.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
point taken... but I did already my bit in searching the articles first...
neededless to say, giving an answer in search form is a bit pointless as it was my first try to already search the articles... hence what I'm looking for is somewhat different:
a pointer to a short/full application that does use the CTreeCtrl that is not listed in the search
results...
otherwise I'll just feel somebody thinks me to be so stupid to don't search before asking !!!
|
|
|
|
|
federico.strati wrote: otherwise I'll just feel somebody thinks me to be so stupid to don't search before asking !!!
How can we tell, in advance, how stupid are 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]
|
|
|
|
|
you have just to assume what you would do in the first place, like an "I wouldn't do that,
wouldn't I?" ...
Oh well, I just know I'll end up as always writing my own little app exploring all available options of the CTreeCtrl just for fun in learning...
grazie comunque
|
|
|
|
|