|
I compile the following C++ code VS.NET2003 IDE and the compiler enter an infinit/endless compiling process, What's wrong within it?
The code is given as following:
//The testtempl.h
#ifndef __TESTTEMPL_H__
#define __TESTTEMPL_H__
#include <stdlib.h>
#include <stdio.h>
#include <vector>
template<int n> class MyTempl
{
public:
std::vector<int> m_array;
public:
MyTempl()
{
m_array.assign(n, n);
}
int Summation()
{
int rn = 0;
for(int i = 0; i < (int)m_array.size(); i++)
rn += m_array[i];
return rn;
}
int Foo()
{
if(n <= 1)
return 1;
else
{
int r = 0;
MyTempl<n-1> mtempl;
r = mtempl.Foo()*Summation();
return r;
}
}
};
typedef MyTempl<4> My4Foo;
#endif
//The testtempl.cpp file
#include "testtempl.h"
int main(int argc, char* argv[])
{
My4Foo myfoo;
int i = myfoo.Foo();
printf("foo value: %u\n", i);
return 0;
}
-- modified at 19:25 Thursday 6th October, 2005
|
|
|
|
|
First of all, check 'do not treat < as html' below, so we can SEE the code
I think this line
MyTempl<n-1> mtempl;
means that every time the compiler creates a template class, it needs to create a new one, recursively forever. Hence the error.
Christian Graus - Microsoft MVP - C++
-- modified at 18:51 Thursday 6th October, 2005
|
|
|
|
|
I haven't tested it, but I think one way to avoid the problem while maintaining the recursive nature of the solution would be to do as follows:
In the class declaration, declare only the prototype for the Foo method:
int Foo();
Then, provide a general implementation for Foo():
template<int n>
int MyTempl::Foo()
{
int r = 0;
MyTempl<n-1> mtempl;
r = mtempl.Foo()*Summation();
return r;
}
Finally, provide an explicit implementation for the 1 case, so as to end the recursion:
template<1>
int MyTempl::Foo()
{
return 1;
}
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Kinda offtopic question;
Whenever I startup Windows Media Center, the actual program, not the OS, Visual C++ starts up and starts debugging. Everytime (I think its called ehShell.exe), the debugger starts up. Its slowing down the computer significantly. Is there anyway to stop this from doing it? Thanks alot
Dave
|
|
|
|
|
Anyone know of a good book covering Boost?
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
There are books on some Boost libraries, like Graph, and metaprogramming, but AFAIK, no book covers "all Boost".
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
|
hi guyz
i am a complete begginer in programming stuff and it seems like i am stuck in a very bad situation, tht i have to do a project in c "motion capturing and detection"
now cause i ama compplete begginer....
i need ur help in these... plz help me by sending any good information or algorithm related this topic...
plzz i need ur help
u can also email me.
sH*t haPPeNs
|
|
|
|
|
It's a pity. So many interests, but no idea...
|
|
|
|
|
You little scumbag! I got your name, I got your ass! You will not laugh, you will not cry, you will learn by the numbers, I will teach you! Now get up off your face! Col.Walter.E.Kurtz you better unfuck yourself before I unscrew your head and sh*t down your neck!
Now choke yourself.
|
|
|
|
|
I've seen horrors... horrors that you've seen. But you have no right to call me a murderer. You have a right to kill me. You have a right to do that... but you have no right to judge me.
Horror and moral terror are your friends. If they are not then they are enemies to be feared.
|
|
|
|
|
Col.Walter.E.Kurtz, you climb obstacles like old people f***.
Now choke yourself.
|
|
|
|
|
I watched a snail crawl along the edge of a straight razor. That's my dream. That's my nightmare. Crawling, slithering, along the edge of a straight... razor... and surviving.
Horror and moral terror are your friends. If they are not then they are enemies to be feared.
|
|
|
|
|
I'll bet you're the kind of guy that would f*** a person in the ass and not even have the goddam common courtesy to give him a reach-around. I'll be watching you.
Now choke yourself.
|
|
|
|
|
You're an errand boy, sent by grocery clerks, to collect a bill.
Horror and moral terror are your friends. If they are not then they are enemies to be feared.
|
|
|
|
|
I am Gunnery Sergeant Hartman, your senior drill instructor. From now on you will speak only when spoken to, and the first and last word out of your filthy sewer will be sir.
Now choke yourself.
|
|
|
|
|
Gunnery Sergeant Hartman wrote:
I am Gunnery Sergeant Hartman, your senior drill instructor. From now on you will speak only when spoken to, and the first and last word out of your filthy sewer will be sir.
Is this your play ground..? Shut Up and get to your work (what ever you do).... disrespectful and rude language is not allowed here.. for any so called reason...?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
-- modified at 0:31 Friday 7th October, 2005
|
|
|
|
|
There are some examples of video capture here[^] as to the detection is this motion or shape? This is more specialist so maybe searching MDSN will help. If not, a careful Google search is next.
Elaine
The tigress is here
|
|
|
|
|
hi..
I'm using MySQL and c++.
I used CDatabase and CRecordSet to access database.
I am trying to get the columns names from the given tables.
I look at the sql code and found
--> show columns from tableName; gives all the column names, type (int or memo..etc) etc.
----------------------------
column1 | column2 | column3 |
----------------------------
data1 | data2 | data3 |
----------------------------
In c++ using CRecordSet .. how am I going to get column names?
which are column1, column2, column3.
|
|
|
|
|
CRecordset has a GetODBCFieldInfo function that you can use to get the information on the fields such as the name of the field (column).
If a wizard fails to cast an enchantment correctly, is that a mis-spelling?
Never argue with an idiot. They will drag you down to their level where they are an expert.
|
|
|
|
|
|
Hello,
I have a CBitmap and load it.
CBitmap mybmp;
mybmp.Load(IDB_TEST);
However, my listbox overlaps the CBitmap.
How can i make CBitmap on top of other
controls?
Thanks a lot.
|
|
|
|
|
NewVCbie wrote:
How can i make CBitmap on top of other
controls?
What are you doing after mybmp.Load(IDB_TEST); with your bitmap ? Can you post some code ? Which listbox are you talking about ?
~RaGE();
|
|
|
|
|
actually i create a class CMyBitmap derived from CBitmap,
void DrawTransparent (CDC* pDC, int x, int y, COLORREF clrTransparency);
void Draw (CDC* pDC, int x, int y);
The actual call is
CMyBitmap bmpheader;
bmpheader.LoadBitmap(IDB_LISTHHISTORY);
bmpheader.DrawTransparent(GetDC(),24,85,RGB(255,0,255));
My bitmap is long and it hit some area where listbox is, but what happens is that the hit area appears that my bitmap is behind the listbox, i wanted the opposite. I wanted my bitmap to be on top of whatever control it encounter on its area..
Thanks...
Below is the Code:
void CDTGBitmap::Draw(CDC *pDC, int x, int y)
{
BITMAP bm;
GetBitmap (&bm);
CPoint size (bm.bmWidth, bm.bmHeight);
pDC->DPtoLP (&size);
CPoint org (0, 0);
pDC->DPtoLP (&org);
CDC dcMem;
dcMem.CreateCompatibleDC (pDC);
CBitmap* pOldBitmap = dcMem.SelectObject (this);
pDC->BitBlt (x, y, size.x, size.y, &dcMem, org.x, org.y, SRCCOPY);
dcMem.SelectObject (pOldBitmap);
}
void CDTGBitmap::DrawTransparent(CDC *pDC, int x, int y, COLORREF clrTransparency)
{
BITMAP bm;
GetBitmap (&bm);
CPoint size (bm.bmWidth, bm.bmHeight);
pDC->DPtoLP (&size);
CPoint org (0, 0);
pDC->DPtoLP (&org);
CDC dcImage;
dcImage.CreateCompatibleDC (pDC);
CBitmap* pOldBitmapImage = dcImage.SelectObject (this);
CDC dcAnd;
dcAnd.CreateCompatibleDC (pDC);
CBitmap bitmapAnd;
bitmapAnd.CreateBitmap (bm.bmWidth, bm.bmHeight, 1, 1, NULL);
CBitmap* pOldBitmapAnd = dcAnd.SelectObject (&bitmapAnd);
dcImage.SetBkColor (clrTransparency);
dcAnd.BitBlt (org.x, org.y, size.x, size.y, &dcImage, org.x, org.y, SRCCOPY);
CDC dcXor;
dcXor.CreateCompatibleDC (pDC);
CBitmap bitmapXor;
bitmapXor.CreateCompatibleBitmap (&dcImage, bm.bmWidth, bm.bmHeight);
CBitmap* pOldBitmapXor = dcXor.SelectObject (&bitmapXor);
dcXor.BitBlt (org.x, org.y, size.x, size.y, &dcImage, org.x, org.y,
SRCCOPY);
dcXor.BitBlt (org.x, org.y, size.x, size.y, &dcAnd, org.x, org.y,
0x220326);
CDC dcTemp;
dcTemp.CreateCompatibleDC (pDC);
CBitmap bitmapTemp;
bitmapTemp.CreateCompatibleBitmap (&dcImage, bm.bmWidth, bm.bmHeight);
CBitmap* pOldBitmapTemp = dcTemp.SelectObject (&bitmapTemp);
dcTemp.BitBlt (org.x, org.y, size.x, size.y, pDC, x, y, SRCCOPY);
dcTemp.BitBlt (org.x, org.y, size.x, size.y, &dcAnd, org.x, org.y,SRCAND);
dcTemp.BitBlt (org.x, org.y, size.x, size.y, &dcXor, org.x, org.y,SRCINVERT);
pDC->BitBlt (x, y, size.x, size.y, &dcTemp, org.x, org.y, SRCCOPY);
dcTemp.SelectObject (pOldBitmapTemp);
dcXor.SelectObject (pOldBitmapXor);
dcAnd.SelectObject (pOldBitmapAnd);
dcImage.SelectObject (pOldBitmapImage);
}
|
|
|
|
|
It seems like you are just drawing the bitmap in the parent window, so any child control (e.g., the listbox) will be drawn on top of it. I suggest creating a static control with the SS_OWNERDRAW style. Put this control at the top of the children z-order and use CDTGBitmap to do the drawing in the parent's handler for the WM_DRAWITEM message.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|