|
|
when you return a reference, you will be able tou chain the operators like this:
animal MyAnimal1, MyAnimal2, MyAnimal3; <font style="color:green;">
MyAnimal1 = animal(<font style="color:green;"></font>); <font style="color:green;">
MyAnimal3 = MyAnimal2 = MyAnimal1; <font style="color:green;">
in general, we prefer the synopsis T& operator= (const T&) ...
make your choice
TOXCCT >>> GEII power
|
|
|
|
|
It may be a typo but if the code reflects what you have in your project you have missed a D out of DeleteMedia in the .cpp file.
In my experience if the function has not been defined in the header the autocompletion does not function.
Otherwise delete the project .ncb file and reload the project. This normally fixes such glitches.
Ant.
|
|
|
|
|
Two problems:
1. Intellisense sometimes has a problem with templates.
In that case you just have to type
2. You used a wrong syntax for declaring a template.
Also the methods of a template must be defined within
the header.
See the following example:
<br />
<br />
#include <vector><br />
using namespace std;<br />
<br />
template < class T > class CPlaylist<br />
{<br />
public:<br />
CPlaylist(T m_vPlaylist)<br />
{<br />
};<br />
virtual ~CPlaylist()<br />
{<br />
};<br />
void DeleteMedia(int iPosition);<br />
<br />
protected:<br />
std::vector< T > m_vPlaylist;<br />
...<br />
};<br />
<br />
template < class T > void CPlaylist< T >::DeleteMedia(int iPosition)<br />
{<br />
...<br />
}<br />
<br />
Jens
|
|
|
|
|
We said me that when I work with the templates I have to define the function in the header file when they are declared... Is it true ?
When I define:
std::vector <t> m_vPlaylist;
Is this call correct?
m_vPlaylist.Erase(iPosition);
When I write "m_vPlaylist." I can't see all the functions that work with vectors... For example "Erase" function.
|
|
|
|
|
Well, try it
Your linker will complain about missing functions...
You cannot define
std::vector m_vPlaylist;
since std::vector is a template and therefor
it needs a type, a specialization like
std::vector< int > m_vPlaylist;
which will generate a vector for storing ints.
But anyway you cannot call erase with an int parameter,
it takes an iterator.
Jens
|
|
|
|
|
Also note erase is all lower case.
Ant.
|
|
|
|
|
How to define a constructor when using Templates?
Here is the one I've declared:
template<class t=""> CPlaylist<t>::CPlaylist(T m_csName)
{
}
with those protected variables:
vector <t> m_vPlaylist;
CString m_csName;
No problem at compilation but the functions I've declared after are unabled...
Function's declaration:
template<class t=""> void CPlaylist<t>::MyFunction()
{
//smthg
}
|
|
|
|
|
<br />
template < class T > class CPlaylist<br />
{<br />
public:<br />
CPlaylist();<br />
CPlaylist(T m_vPlaylist);<br />
virtual ~CPlaylist();<br />
void DeleteMedia(int iPosition);<br />
<br />
protected:<br />
std::vector< T > m_vPlaylist;<br />
CString m_csName; <br />
};<br />
<br />
template < class T > CPlaylist< T >::CPlaylist()<br />
{<br />
};<br />
<br />
template < class T > CPlaylist< T >::CPlaylist(T m_vPlaylist)<br />
{<br />
};<br />
<br />
template < class T > CPlaylist< T >::~CPlaylist()<br />
{<br />
};<br />
<br />
template < class T > void CPlaylist< T >::DeleteMedia(int iPosition)<br />
{<br />
}<br />
<br />
Jens
|
|
|
|
|
Thank's!
I have one last question... How to initialyse a variable which type is CPlaylist ?
CPlaylist <t> MyVariable;
??
|
|
|
|
|
|
Well, that really depends on your implementation of CPlayList...
Jens
|
|
|
|
|
Here is how I declare my template in my .h:
template<class t=""> class CPlaylist
{
public:
CPlaylist(T m_vPlaylist);
virtual ~CPlaylist();
void DeleteMedia(int iPosition);
protected:
vector <t> m_vPlaylist;
CString m_csName;
};
In my .cpp, I define my function:
template<class t=""> void CPlaylist<t>:eleteMedia(int iPosition)
{
m_vPlaylist.Erase(iPosition);
}
That compiles but I have no access to all of the Vector function when I write a "." . I can't see them...
Some ideas about that?
|
|
|
|
|
If i set one time in my application, I hope that it can act like a clock to notify me to do something at that time.
How can i achieve this?? Is there any Win32 API which can do this or some sample code that i can reference??
Thank in advance
|
|
|
|
|
Look up CreateWaitableTimer()/SetWaitableTimer()
(I last used this about three years ago at a different company so I have no source; sorry.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
If i create a thread to check if the time is up, is this the same with CreateWaitableTimer??
Thank you
|
|
|
|
|
Yes and no. You could do a timeout on a wait, but since the system clock can slip, the longer the timeout, the worse the precision. You're also limited to a relatively short period of time.
An alternative, which I have also used, is to have the thread wake up every hour, or some time period, check the time, then go back into the wait with a timeout (the wait was monitoring a shutdown event for graceful exit.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
If the thread wake up every hour, i set the clock between one hour scale.
Will i lose the chance to get the correct time??
I don't know why should go back into the wait with a timeout??
Thank for your help
|
|
|
|
|
Givens:
1) hEvent is a handle to an event
2) the following is in a thread
3) proper initialization has been done
for (;;)<br />
{<br />
if (WaitForSingleObject(hEvent, 60 * 60 * 1000) != WAIT_TIMEOUT)<br />
break;<br />
<br />
SYSTEMTIME time;<br />
GetSystemTime(&time);<br />
}
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
what's the difference when opening the file between in the way of text and
in the way of binary system?
|
|
|
|
|
One difference is how some characters are interpreted,
\r and \n for example.
Jens
|
|
|
|
|
Hello, Sir!
I am writing a MFC based program to extract files in a Zip archive, just like WinZip or WinRAR. I want to extract special files when I drop them from my CListView to the explorer or desktop. I think I must use delayed rendering to implement it.
I don't know how to do it. Could you give me some advice or example?
Thank you for your attention.
Best regards,
andy xia
andyxia@radinf.com
2004-05-04
|
|
|
|
|
What exactly is your problem?
Please give some more details.
Dow you just want to know how to
get the files that the user dropped
to the window of your application?
Jens
|
|
|
|
|
Hi,Jens,
Thanks for your reply.
In my program, I will do:
1. Drag some items from my ListView control to Windows Explorer.
2. I should get the target path where I finished the dragging.
3. If it is a valid path, I will extract the selected files to there.
My program is a Compress/Decompress tool just like WinZip and WinRAR.
In my ListView class, I responsed LVN_BEGINDRAG message to begin a dropping action like follow codes:
// Begin dropping...
CMyZipBoxDataSource datasrc;
FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
datasrc.DelayRenderFileData(CF_HDROP, &etc);
DROPEFFECT dwEffect = datasrc.DoDragDrop ( DROPEFFECT_COPY );
... ...
// End dropping
the Class CMyZipBoxDataSource is inherited from COleDataSource, and I overrided the function:
BOOL CMyZipBoxDataSource::OnRenderFileData(LPFORMATETC lpFormatEtc,CFile* pFile)
I don't know:
1. what should I write down in this function to handle this process?
2. how to get the target path the file will be extracted?
3. WinRAR extract selected files to a temp path after mouse up when draged. when it finished, move the extracted files to target path. Can I extract them to the target path directly?
That's my question, Thanks for your attention again.
Could you help me?
|
|
|
|
|
Sorry, I have not worked this way, till now I always accepted files to be dropped to my application, but yours is the other way round
But anyhow, your problem is much clearer now, maybe someone else can help you.
Sorry,
Jens
|
|
|
|