|
No no thats not possible. I only need to call the function with different types.
I think the problem is with the vc6. In vc8, it is working fine.
|
|
|
|
|
Naveen,
It's a bug of Microsoft Visual C++ (6.0) compiler. There's no workaround available.
They have corrected it in the newer versions.
Please check KB article[^]
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Oh I misunderstood your question. Sorry!
Maxwell Chen
|
|
|
|
|
Hi Naveen ,
You are right the code given by you is working on VC7 and onwards
But if you want to make it possible on VC6 then please refere the code given below and make the changes accordingly. Hope this will help you.
template<class T><br />
class Test<br />
{<br />
public:<br />
void someFunction( T obj );<br />
};<br />
<br />
template<class T> <br />
void Test<T>::someFunction( T obj )<br />
{<br />
<br />
}<br />
<br />
int main(int argc, char* argv[])<br />
{ <br />
int n = 0;<br />
Test<int> obj;<br />
obj.someFunction( n );
return 0;<br />
}
The secret of life is not enjoyment
but education through experience.
- Swami Vivekananda.
|
|
|
|
|
Hi Mahesh ,
The problem with your sugeestion is that, I cannot call the obj.someFunction() with both int and long at the same time like..
int n = 0;<br />
long l = 0;<br />
obj.someFunction( n ); <br />
obj.someFunction( l );
|
|
|
|
|
I think that Naveen wants (member) function templates of a class, not class templates .
If it is a class template, the argument type is fixed when the class object is declared. So we can not invoke member functions with different input types (something like function overloading).
Maxwell Chen
|
|
|
|
|
HI Naveen and MaxWell
I am really sorry ..It was my misunderstanding.
later I worked for wht Naveen exactly want, on VC6
But it was not working then i googled,
I found the Following link
http://forums.devx.com/archive/index.php/t-82949.html[^]
The secret of life is not enjoyment
but education through experience.
- Swami Vivekananda.
|
|
|
|
|
To tell the truth, I have been 7 years not coding template stuffs.
I just tried hard to recall everything about templates (both member function template and class template), and tried with VC++2008. It works well finally.
Maxwell Chen
|
|
|
|
|
How to resize bitmap which in CStatic
<code>
CStatic* myStatic;
myStatic = new CStatic();
myStatic->Create(_T("my static"), WS_CHILD|WS_VISIBLE|SS_BITMAP|SS_CENTERIMAGE, CRect(50,80, 150, 150), this);
myStatic->SetBitmap(LoadBitmap(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDB_BITMAP_default)));
</code>
these code set bitmap in CStatic control, but the picture is not whole displaied, because its area more than CRect(50,80, 150, 150),
how to resize the bitmap area that to dispaly full onto the CStatic control?
thanks!
|
|
|
|
|
This control[^] does all the dirty work.
This article[^] shows what you can do with the static control. Not settng the SS_CENTERIMAGE or SS_REALSIZEIMAGE style supposedly makes the image fit the static control.
Note that the actual size of the static control in pixels, and even its aspect ratio depends on the dialog font, so it may be different when moving to another PC.
|
|
|
|
|
|
I define a class CArray2D,inside it I imeplement a "proxy" class CArray1D, so that if I create a object of CArray2D like CArray2D array(2,3), I can output the its element like cout<<array[0][0].
But when I run it, I met with serials of strange questions like error address.
Can anyone tell me why?
Many thanks
The code is as follows
class CArray2D
{
public:
void Print()
{
CArray1D *pHead = pArray1D;
for(int i=0; i<size2D; i++)
{
cout<<"[ "<<i<<" }";
pHead->Print1D();
pHead = pHead+i*sizeof(CArray1D);
cout<<endl;
}
}
CArray2D(int n2DWidth, int n1DWidth):size2D(n2DWidth)
{
pArray1D = new CArray1D[size2D];
};
~CArray2D()
{
delete[] pArray1D;
};
class CArray1D
{
public:
CArray1D(int n1DWidth=3):size1D(n1DWidth)
{
pArray = new int[size1D];
for(int i=0; i<size1D; i++)
{
*(pArray+i*sizeof(int)) = 0;
}
};
~CArray1D()
{
delete[] pArray;
};
const int& operator[](int nIndex) const
{
return *(pArray+nIndex*sizeof(int));
}
int& operator[](int nIndex)
{
return *(pArray+nIndex*sizeof(int));
}
void Print1D()
{
for(int i=0; i<size1D; i++)
{
cout<<"["<<i<<"]="<<*(pArray+i*sizeof(int))<<" ";
}
}
private:
int size1D;
int *pArray;
};
const CArray1D& operator[](int nIndex) const
{
return *(pArray1D+nIndex*sizeof(CArray1D));
};
CArray1D& operator[](int nIndex)
{
return *(pArray1D+nIndex*sizeof(CArray1D));
};
public:
int size2D;
CArray1D *pArray1D;
};
int main()
{
CArray2D array(2,3);
array.Print();
array[0][0] = 3;
array.Print();
cout<<array[0][0]<<endl;
return 0;
}
}
Tomorrow is another day
|
|
|
|
|
Hi,
I'm doing a CPU-intensive program right now (C++ WinAPI, no MFC but I could use it if I had to) that uses some graphics, frequently calling a FillRect function to clear its back-buffered HDC to white. Is there a more efficient way to do this? Maybe by using bitwise operators somehow?
Thanks!
KR
|
|
|
|
|
You could use a DIB section for the back buffer's bitmap and write the
bits directly to memory in a loop.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Ok I'll try that, thanks!
KR
|
|
|
|
|
Using BitBlt API with WHITENESS isn't better?
|
|
|
|
|
BitBlt with WHITENESS seems to be the fastest way to do it that I've tried. I guess I might be able to get it a little faster using a straight memcpy but I think BitBlt basically is a memcpy already so I doubt it'll help much.
KR
|
|
|
|
|
Through BitBlt we can avoid the risk of bugs, since we dont need to handle the DC bitmap directly.
|
|
|
|
|
RECT r = {...};
SetBkColor(dc, your_white);
ExtTextOut(dc, r.left, r.top, ETO_OPAQUE, &r, NULL, 0, NULL);
[EDIT]
Not saying it's faster, just another way.
At one point i believe it was the prefered way (don't recall why).
[/EDIT]
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
That way seems to be faster than FillRect, but copying directly to memory with BitBlt is slightly faster. Thanks!
KR
|
|
|
|
|
You may want to read:
http://blogs.msdn.com/oldnewthing/archive/2006/01/03/508694.aspx[^]
However, if BitlBlt accepts hdcSrc = NULL when dwRop is WHITENESS then you may as well stick with that if it's faster. This is a special case (color is set to palette index 1 = usually white). ExtTextOut is still fastest for setting any color.
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
How can I get the paths of the directories from which the application has been loaded, and the "current" directory (the one, which is specified in the "Start in" of the properties)?
|
|
|
|
|
GetModuleFileName(NULL, buffer, buffersize)
and
GetCurrentDirectory(...)
|
|
|
|
|
Thanks, it was very quick.
|
|
|
|
|
I has already been tried to this codes.. It does not work. Anybody can help me about picture control usage to review a picture.
HBITMAP hBmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), <br />
MAKEINTRESOURCE(IDB_BITMAP2),<br />
IMAGE_BITMAP, <br />
0,0, <br />
LR_LOADMAP3DCOLORS);<br />
<br />
CStatic* pSt = (CStatic*) GetDlgItem(IDC_STATIC);<br />
pSt->SetBitmap(hBmp);<br />
pSt->UpdateWindow();<br />
pSt->InvalidateRect(NULL);
Was is das¿
|
|
|
|