|
You can use template< class T> class yourClass{
...
Array[T]
...
}
After that you replace class T by interger value
Good luck
Bye.
|
|
|
|
|
I thought template <class t=""> is used for changing int/char/BOOL etc.
Now I am getting invalid template argument for 'size' type expected
|
|
|
|
|
template <int size=""> class A
{
char name[size] ;
} ;
when you new a object A you must put extractly number ( real value)
don't put variant . because template is transfer to code at compiler-time
thanks
|
|
|
|
|
Anonymous wrote:
int array[MAXSIZE]; //MAXSIZE is dynamic
This array has a static, not dynamic, size. To make it dynamic:
class CMyArray : public CObject
{
private:
int *array;
public:
CMyArray()
{
array = new int[MAXSIZE];
}
virtual ~CMyArray()
{
delete [] array;
}
};
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
It is static but it should be dynamically changing everytime the class constructor is called.
Something like
A1 X X X X
A2 X X X
A3 X X X X X X
A4 X X X X
I guess I could do it that way. I thought maybe I could use template.
|
|
|
|
|
poiut wrote:
...it should be dynamically changing everytime the class constructor is called.
What's wrong with:
class CMyArray : public CObject
{
private:
int *array;
public:
CMyArray( const int size )
{
array = new int[size];
}
virtual ~CMyArray()
{
delete [] array;
}
};
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Nothing wrong with it. I just wanted to practice using template and see how it works.
Thanks for the help
|
|
|
|
|
Are you sure your class IS A array, instead of HAS A array ? Don't use CArray, it's crap. Contain a vector, and if you want your class to be an array, expose the methods you need to.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I'm trying to implement a timer in my UI thread, with a call back. I need 3 timers setup. In order for my timer to work I need to pass a hwnd as part of the settimer function.
Is there a way to convert my m_hThread HANDLE to a HWND so that my timer will work?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Check out GetGUIThreadInfo() , maybe it helps you.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
A thread and a window are totally distinct objects.
If you don't have a window handy, pass a NULL HWND and a non-NULL function pointer to SetTimer() and it will call that function.
--Mike--
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
Tom Wright wrote:
Is there a way to convert my m_hThread HANDLE to a HWND so that my timer will work?
Short answer: No.
Long answer: The SetTimer function is used to tell the system to call a given function (in your process), at set time intervals. You can use the SetTimer function, even if there is no associated window (hWnd=NULL), in which case the nIDEvent has no meaning. What you would use it for, I have no ideas (at this time).
If your timers are all used in just one window, then you can call the SetTimer function once for each event that is required with different event IDs. Then switch on the ID passed to the TimerProc, to determine which timer event has occured. This also applies if you do not provide a TimerProc, in which case you need to handle the WM_TIMER message.
Of cource you could roll your own timer thread that takes the handle to a window and post message back to the window at given intervals. But why bother, when it is built in.
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
My problem is that my threads do not have windows. So I do not have a HWND to pass to settimer. The problem with that is that each thread has 3 timers in order for the 3 timers to work I need an nIDEvent to be passed. But this is ignored if I do not have a HWND. So my...hence my delemia. If I pass the HWND of my main app then if one thread kills a timer, then it's killed for all threads....why...I'm thinking that since the HWND and the nIDEvent are the same the message systems does not know which one to effect so it effects them all.
John R. Shaw wrote:
If your timers are all used in just one window, then you can call the SetTimer function once for each event that is required with different event IDs. Then switch on the ID passed to the TimerProc, to determine which timer event has occured. This also applies if you do not provide a TimerProc, in which case you need to handle the WM_TIMER message.
I'm not sure what you mean by this...can you explain some more?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Tom Wright wrote:
I'm not sure what you mean by this...can you explain some more?
When you are using a timer in a window, you use the nIDEvent parameter to set the event ID. The event ID is passed to the the TimerProc, so that you can determine which timer event caused the TimerProc to be called. For instants you may have an event that occurs every 1 second and anouther event that occurs every 5 seconds. By checking the event ID that is passed to the TimerProc, you can decide what your programm needs to do.
Now as for running a non-windowed thread that needs timer events, well you will probably have to insert code in that thread to check when the individule time periods have passed (manual time interval monitoring). Or you could roll your own timer thread and use one of the WaitFor... functions to check when a times up event to occur.
I know there is an article out there somewhere on rolling your own timer, but I have not looked at it in years, so I do not know where it is.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Does anybody know which *.dll files i have to copy with my program ,which i have compiled in C++.Net with "Release" when i take it to other computer where Microsoft Visula Studio.Net is not installed.
G.Moniava
|
|
|
|
|
two things. One if you try and run your program it will usually tell you what dll's are missing. Two....just link in the runtime dll's and you won't have to worry about it.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
|
also, keep in mind that Microsof didn't include dlls to run release versions of C++ .NET applications on Server 2003. (you can run release versions of VC6 apps, but not VC7 apps)
Serge
|
|
|
|
|
I have written a class for doing arithmetic operations on big numbers,inherited from CString class.But when i multiply numbers which are longer than 512 digits i get the incorrect result.In other cases i get the correct result.
P.S : i think the promblem is in displaying numbers which are longer than 1024 digit.why ? maybe CString objects can't contain texts longer than 1024 digit??
Can anyone help ?
G.Moniava
|
|
|
|
|
does "digit" = bit or byte?
includeh10
|
|
|
|
|
for example : 1500 is a 4 digit number, 545 3 digit number and etc.
SROCalm
|
|
|
|
|
if so
what do u mean "256 digits"?
int i=928373774848 .......... 382772 ?????
includeh10
|
|
|
|
|
Yes, but not
int i=928373774848 .......... 382772 ?????
i mean
CString s = "928373774848 .......... 382772";
s is text which contains 256 letters
m0n0
|
|
|
|
|
if so, there is no problem, i am sure.
CString can handle much longer than 256.
includeh10
|
|
|
|
|
Do you know approximately how much longer ?
Because this class handles all operations +,-,*,/ and returns the right result . //Only if result (the number) is //less than 1024 digits.
m0n0
|
|
|
|