|
As you have written member function as inline, i change code as following,
<br />
class CProg<br />
{<br />
int val;<br />
public :<br />
void SetVal(int y);<br />
template<class T><br />
void AddValues(T a, T b)<br />
{<br />
T x = a+b;<br />
}<br />
};<br />
void CProg::SetVal(int y)<br />
{<br />
val = y;<br />
}<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
CProg prog;<br />
prog.SetVal(9);<br />
int a,b;<br />
a = b =8;<br />
prog.AddValues(a,b);<br />
double x, y<br />
x = 12.1212;<br />
y = 12.446;<br />
prog.AddValues(x,y);<br />
return 0;<br />
}
Above code is working properly. Thanks for that.
But eventhough, is there any other way for non-inline memeber function for class to use as Function Template ?
|
|
|
|
|
If it works... cool
but actually... I edited the message because of the < class T >, I forgot the empty spaces so the web took them as format snippets.
Anyways... The inline statement is not needed. The only thing is that for so short functions is better because the compiler add the inline function wherever it is called, insteads of referencing and going to read the code everytime it is called.
It should work as well without the inline.
I'm glad helping
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Nelek wrote: The inline statement is not needed. [...] It should work as well without the inline.
Probably not. The Compiler must see the definition of the template at every point where a new template is instantiated.
And as tou almost newer include CPP-files, the template body must be in the header.
Failure is not an option - it's built right in.
|
|
|
|
|
I didn't say "put the template in the .cpp". I said that the same template function should work as well defined as inline as not defined as inline. It is already clear that all template functions have to go in headers.
In my article the functions I added to the SmartList are not inline and works perfectly.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Try with...
template< class T >
class CProg
{
public :
int val;
void SetVal(int y);
void AddValues(T a, T b);
};
template< class T >
inline void CProg< class T >::SetVal(int y)
{
val = y;
}
template< class T >
inline T CProg< class T >::AddValues(T a, T b)
{
return (T) (a + b);
}
EDIT: Some corrections, like empty space between < > and class T, so the web doesn't take them as labels for format.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
I'm having a Cstring buffer that I'm accumulating for n iterations. At the end of each iteration I add \r\n to the end of buffer. After end of all the iterations I'm writing the CString buffer to the CFile object. I'm seeing hre two things.
1) The characters occupy double space may be two bytes. So the look i expanded rather than the normal.
2) Instead of \r\n the file contains some junk square characters. Also the file is not written with full contents.
The project is build in VS2005 with unicode. IS it mandatory to build a project with the default unicode support in VS2005.
|
|
|
|
|
1 is probably due to unicode. As for 2., post your writing code.
tom groezer wrote: IS it mandatory to build a project with the default unicode support in VS2005
Not that I know of.
|
|
|
|
|
tom groezer wrote: IS it mandatory to build a project with the default unicode support in VS2005
I think it is not mandatory, but VS2005 default to UNICODE settings.
|
|
|
|
|
Dear all,
Recently i have faced an interview .... so there the interviewer asked me.. have u knowledge of COM+ ... so what should i have to answer...
Now i am telling about me...
I am using the dlls(COM component) just for doing some logical operation from ASP page.or when i need the acess for the data base.. that time also from asp page only
so please tell me during interview what should i tell... about my work knowledge....
Tasu
Tasu
|
|
|
|
|
The more diplomatic answer is: I know the concepts but I have not used in realtime projects
|
|
|
|
|
Completely agree
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
tasumisra wrote: so please tell me during interview what should i tell... about my work knowledge....
If you have to ask, then you don't know COM.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,
I use WinXP. I noticed that if we create bursh or pen object and destroy them, the GDI object count that is seen in the task manager is not decreasing.
What I did is,
I created 20 brushes in a button click. Then the GDI object count is increased from 28 to 48. Then destroyed the objects in another button click. Now the GDI object count is 38. But if click the first button again the count is getting increased to only 48, means the objects are already destroyed but the count is not updated correctly.
Why this behaviour?
The code sample:
HGDIOBJ hBr[20];<br />
void CMyDlg::OnButtonCreate() <br />
{<br />
for( int i = 0; i < 20; i++ ) hBr[i] = CreateSolidBrush( 0 );<br />
}<br />
<br />
void CMyDlg::OnButtonDestroy() <br />
{<br />
for( int i = 0; i < 20; i++ ) DeleteObject( hBr[i] );<br />
}<br />
I tried it for pen objects, then the result is 28 to 48 on creation and 48 to 36 on destruction. But the 48 is stable for each creation similar to the brush, if the destruction is done for each creation.
But for font objects it is working fine. That is 28 to 48 on creation and 48 to 28 on destruction.
- NS -
|
|
|
|
|
Where GDI object count is displayed in the task manager? I have not seen before
|
|
|
|
|
Please use menu to enable that. View > Select Columns...
- NS -
|
|
|
|
|
HFILE hFile = OpenFile( szPath , ofStruct , OF_READWRITE )
how to close this hFile pointer ?
thanks
|
|
|
|
|
It clearly mentioned in documentation, this API is for compatibility with 16bit OS.
Use CreateFile instead.
And CloseHandle to close it.
Prasad
MS MVP - VC++
|
|
|
|
|
i alswo want to test OF_EXIST
HFILE hFile = OpenFile( szPath , ofStruct , OF_EXIST )
and
ofStruct.fFixedDisk
so i dont want to use CreateFile.
|
|
|
|
|
Check value return of this file (hFile).
|
|
|
|
|
Hi,
Can we change the size of the default scrollbar for a particular window (control) only?
For example, I need to change the default scrollbar size of the edit box leaving all other controls' scrollbars unchanged.
Size means width of the vertical scrollbar and height of the horizontal scrollbar.
Thanks in advance.
- NS -
|
|
|
|
|
|
Thanks.
I already had look at this article. But it is just for listbox. It is done by hiding the default and place a new one.
Actually i need to change the default scrollbar size.
- NS -
|
|
|
|
|
Dear All,
Good day. I have problem with the code below (which I used to get the directory path in the address bar of explorer.exe):
<small>
TCHAR lpString[1024] = _T("");
if ((strcmp(c, "ExploreWClass") == 0) || strcmp(c, "CabinetWClass") == 0) {
HWND hWorker, hReBar32, hCombo32, hCombo, hEdit;
hWorker = FindWindowEx(hwnd, 0, "WorkerW", NULL);
if (hWorker) {
hReBar32 = FindWindowEx(hWorker, 0, "ReBarWindow32", NULL);
if (hReBar32) {
hCombo32 = FindWindowEx(hReBar32, 0, "ComboBoxEx32", NULL);
if (hCombo32) {
hCombo = FindWindowEx(hCombo32, 0, "ComboBox", NULL);
if (hCombo) {
hEdit = FindWindowEx(hCombo, 0, "Edit", NULL);
if (hEdit) {
SendMessage(hEdit, WM_GETTEXT, 1024, (LPARAM)(void*)lpString);
}
}
}
}
}
}
</small>
I believed due to Vista Architecture different from 2K and XP, this code doesn't work anymore and it always fail at FindWindowEx(hReBar32, 0, "ComboBoxEx32", NULL); in Vista. Anybody can give me some instructions on how to make this work with Vista?
|
|
|
|
|
Hirakawa wrote: it always fail at FindWindowEx(hReBar32, 0, "ComboBoxEx32", NULL); in Vista
What does GetLastError returns ?
Prasad
MS MVP - VC++
|
|
|
|
|
Hi Prasad_Som
Thank you for reply. I use the following codes to get the last error and I got dword value 0.
DWORD dwResult = GetLastError();
CString Temporary;
Temporary.Format("%d", dwResult);
AfxMessageBox(Temporary);
|
|
|
|