|
|
I have a template class(my 2nd one) that I am using here the code that give me error and the error latter.
class UseClassMemebersInTemplate
{
public:
void Build(){...};
void Kill();
...
};
template<Type& T>
class TemplateClass
{
public:
TemplateClass()
{
CallAFunctionInConstructor();
}
~TemplateClass()
{
CallAnotherFunctionInConstructor();
}
void CallAFunctionInConstructor()
{
T.Build();
}
void CallAnotherFunctionInConstructor()
{
T.Kill();
}
};
...
//In Another class same header file futher to EOF
...
TemplateClass<UseClassMemebersInTemplate> NewObj;
///////////
When the above is build in VC++ 6.0
I get a couple of errors one looks like...
"missing a ';' before '.'"
At one time I had the calls to Build() and Kill() but empty template constructor and destructor. So I comment constructor and destructor bodies and I was able to build it fine.
I was looking at my 1st template class that I build a year or two ago which applied to the class above modifiy only three places in the template. Keep in mind I going back to the code that gave me the errors. Here the changes I made...
1. Added a pointer to T as a memeber to the template call. Like "T* pT;".
2. Changed both call to Build() and Kill() from "T.Build();" and "T.Kill();" to "pT->Build();" and "pT->Kill();"
And it works find. I can live with calling w/ a pointer but if anyone know why I can use "T." please let me know why not.
|
|
|
|
|
One way is this:
class UseClassMemebersInTemplate
{
public:
void Build()
{
TRACE("Build\n");
};
void Kill()
{
TRACE("Kill\n");
};
};
template< class T >
class TemplateClass : public T
{
public:
TemplateClass()
{
CallAFunctionInConstructor();
}
~TemplateClass()
{
CallAnotherFunctionInConstructor();
}
void CallAFunctionInConstructor()
{
Build();
}
void CallAnotherFunctionInConstructor()
{
Kill();
}
};
|
|
|
|
|
you need to store an instance of UseClassMembersInTemplate in your template class and refer to that, ie, rather then T.whatever(), to myTInstance.Whatever().
template <class t="">
class CTemplateClass
{
private:
T myT;
public:
// now, use the myT member to do your stuff
};
|
|
|
|
|
I see what was going on I wasn't storing UseClassMemebersInTemplate on the stack. So T when use with "T." isn't resolved to an object to call the function. When I used the pointer it work. I can see it is like using CFile::GetStatis(FileNameStr,...) so you don't need to opened the file first. The code I presented in my other post(using pointers) works for functions but I don't think it will work with varibles which I haven't worked on yet but will. I will change the declaration of the pointer to an instance of UseClassMembersInTemplate and call the functions and use varibles(when I have them) using the the stored object's instance.
Thank you for the help so I wouldn't have to post another thread call "Templates errors I found and fix. But a quest...Why the errors? - Varible Extendtion"
|
|
|
|
|
From web camera come image frames which i'd like to store in a file ( .bse i defined ).
to store received images i writed the following..
// msg structure contains head and pointer to the frame data.
RES_MSG msg;
nFrameSize = m_pCamera->ReadFrame(&msg, (char *)mFrameBuf, MAX_FRAME_BUF_SZ);
if( nFrameSize > 0 ) {
msg.u.frame_data = mFrameBuf;
m_pArchive->Write( &msg ,sizeof(RES_MSG)+ nFrameSize )
}
//
to retrieve frame i writed the following...
// m_pTempBuf buffer is enough to store data
RES_MSG * pmsg;
archive.Read( m_pTempBuf , bufsize );
pmsg = (RES_MSG *)m_pTempBuf;
pmsg->u.frame_data = (unsigned char *) ( m_pTempBuf + sizeof(RES_MSG) );
//
after all, i can get head information , but can't get frame data.
is there anything wrong ????
somebody please help me.
thanks in advance.
|
|
|
|
|
Looks like you are writing the pointer to the data, but not the actual data!
|
|
|
|
|
Hello,
I am parsing through a long string and pulling out info between two quotes.. everything works great but when I compile the program I get four
warnings..
warning C4305: 'argument' : truncation from 'const int' to 'char'
warning C4309: 'argument' : truncation of constant value
warning C4305: 'argument' : truncation from 'const int' to 'char'
warning C4309: 'argument' : truncation of constant value
Heres a sample of the code..
int nMyIndex, nFirstQuoteIndex, nSecondQuoteIndex;
nMyIndex = strSource.Find(_T("key"));
nFirstQuoteIndex = strSource.Find('""', nMyIndex);
nSecondQuoteIndex = strSource.Find('""', nFirstQuoteIndex+1);
m_strKey = strSource.Mid(nFirstQuoteIndex+1, nSecondQuoteIndex-nFirstQuoteIndex-1);
Is there a way to keep the compiler from having a fit? Should I not worrie about it?
Should I parse the string differently?
Any suggestions would be appreciated.
Thanks,
Rob Jones
|
|
|
|
|
I'm not sure why your code is searching for two double-quotes, but if your looking to find something between two quotes, you might consider something like the folowing;
nFirstQuoteIndex = strSource.Find('\"', nMyIndex);
nSecondQuoteIndex = strSource.Find('\"', nFirstQuoteIndex+1);
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
|
I am writing my first program. When I execute the program it prompts the user for a number and then returns a calculation. However, the program is displaying the result super fast and then closing the window immediately. It's impossible to even read the answer.
How can I get the program to not terminate so quickly or to say "Hit any key to continue."?
|
|
|
|
|
Are you using Visual C++? It should automatically pause after a terminal program is done executing.
If not, give getchar() a try.
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Alternatively, instead of double clicking the executeable, run it from the command line (ie cmd or dosprmpt).
|
|
|
|
|
Hello, the codegurus around the world.
It seems that you're working a DOS program or the console application.
You open the dos window directed to the location of your EXE files.
C:\>whatever, and type dir/w. You will find your EXE file.
So,
C:\whatever\Your.exe
You can take a look at your result.
Maybe, there may be some way to keep opening the console application from
executing in Visual Studio.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
I am makeing a Direct Sound music player. How would I use MP3s with it.
|
|
|
|
|
That's easy - there is a demo app here to show how to do skinnable apps, and it uses Direct Sound to play mp3's, all the code you need is there. Now if you come across a way to play more than one mp3, I'd love to hear about it. I want to play multiple mp3's at once, but the code in question uses globals and I couldn't for the life of me get it into a class structure so I could create multiple instance....
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
You don't remember the name of it do you. I can find a WinAmp plugin that uses skinning but not much else?
-Matt Newman
|
|
|
|
|
Here it is...
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Thanks. It will give me something to to while I download DX 8 SDK on a dialup modem.
-Matt Newman
|
|
|
|
|
I want to add a menu item (About...) to the SystemMenu of a console window. I have the menu items added but cannot figure out how to process the message for the menu items I've added.
I have a WinMain that is invisible that does the AllocConsole() call running a msgloop. Checked there for a WM_SYSCOMMAND and got nothing. Have a ConsoleControlHandler installed for the console and that only processes Ctrl-C/Ctrl-Break/Logoff... Don't see anything that helps me there.
I'm using Girish Bharadwaj console class to get things rolling and extending it to get the hWnd for the console along with other extensions ideas I've found in forums discussing Win32 consoles.
Anybody got any ideas on this? Any help appreciated.
--
Michael McGarrah
mcgarrah@ncsu.edu
|
|
|
|
|
Menu commands are sent directly to the window - you can't catch them in your message loop. It seems that you'll have to subclass the console window.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi!
In my main frame, I have a list control. There are severals possibilities to add a item in this list control. One of them is from another dialog, this dialog get the informations of any file and send them to the list control.
void CSendFile::m_SendFilePush(void) //Dialog to send a file
{
CListCtrl *CCtrList;
.............
//Informations of the file
v_CFileInfo.itv_sPathName = v_FilePathName;
v_CFileInfo.itv_sFileName = v_FileName;
v_CFileInfo.itv_sExtName = v_ExtFile;
//The code to add item in my lsit control
CCompadApp *pApp = (CCompadApp *)AfxGetApp();
//CCompadDlg has the list control
CCompadDlg *pDlg = (CCompadDlg *)pApp->m_pMainWnd;
CCtrList = (CListCtrl *)GetDlgItem(IDC_LIST_CONTROL);
LVITEM v_ListCtrlItem;
CString v_StringItem;
CString v_FileType;
// Insert the item
v_ListCtrlItem.mask = LVIF_TEXT;
v_StringItem.Format(v_FileName, 0);
v_ListCtrlItem.iItem = 0;
v_ListCtrlItem.iSubItem = 0;
v_ListCtrlItem.pszText = (LPTSTR)(LPCTSTR)(v_StringItem);
v_ListCtrlItem.iImage = NULL;
CCtrList->InsertItem(&v_ListCtrlItem);
EndDialog(v_SendFileDlgID);
}
This compile but there aren't any added item in the list control from CSendFile Dialog.
What is the problem?
Thanks
PS. Excuse me for this english
Endymion
|
|
|
|
|
Here is the problem....
GetDlgItem(IDC_LIST_CONTROL);
You need to get a reference of The listctrl but in ther other Dialog.
You need to do this.
CCTrlList = (*CListCtrl)pDlg.GetDlgItem(IDC_LIST_CONTROL); //Where pDlg is the class of the other Dialog.
The compiler don't return errors because the IDC_LIST_CONTROL constant exist in the resurce.h file.
Cheers!!!
Carlos Antollini.
|
|
|
|
|
I'm getting a runtime error that reads:
"The value of ESP was not properly saved across a function call. This is usually the result of calling a function declared with one calling convention with a function pointed declared with a different calling convention."
What I'm trying to do is use a CToolbar-derived class to respond to events and access the active document via the toolbar's parent, CMainFrame.
//In the Toolbar-derived class
CMainFrame *mf = (CMainFrame*) GetParent();
CTestDoc *pDoc = (CTestDoc*)(mf->GetActiveDocument());
The error seems to say I can't use a pointer to the MainFrame to call the GetActiveDocument function? Any suggestions would be appreciated
Jake
|
|
|
|
|
i always find that a thorough Rebuild-All will fix this. i think it's a stack corruption issue.
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|