|
Fixing the constructor/destructor syntax is one thing.
I'm not sure how you're going to get a template class through the
CWnd message map macros though...
template <class T>
class CTestTemp : public CWnd
{
public:
CTestTemp();
virtual ~CTestTemp();
protected:
DECLARE_MESSAGE_MAP()
};
template <class T> CTestTemp<T>::CTestTemp()
{
}
template <class T> CTestTemp<T>::~CTestTemp()
{
}
<font color="Red">
BEGIN_MESSAGE_MAP(CTestTemp<int>, CWnd)
END_MESSAGE_MAP() Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The problem with templates is that you can't have the definition in a .h and the implementation in .cpp
Templates are like macros in that they are processed before the compilaton proper. There is a reason that I can't remember why that causes the problem... something to do with operating at the file scope rather than program scope
There are a few ways around it, one is to write everything into the class defintion in the .h file. Contrary to popular belief this will not stop your code from working, but it is generally not good practice. There are some more elaborate workarounds out there if you look on Google...
Hope this helps.
|
|
|
|
|
Hi,
I use a c++ class library.
All of the class are derived from one base class (ex 'CObject')
Some class's methods return a pointer(allocated using 'new') to class objects.
So i have to delete those objects. (its hard because of heavy usage of such classes/methods all over the code)
and i have a plan to delete all pointers when app close using a pointer array.
// File : cobject.h
std::vector <CObject*> vecObjPtr;
class CObject
{
CObject::CObject()
{
vecObjPtr.push_back(this);
}
};
// File : keyboard.h
class Keyboard: public CObject
{
Keys* getKeys()
{
return new Keys();
}
};
// File : keys.h
class Keys : public CObject
{
Key* getKey(int value)
{
return new Key(value);
}
};
// File : key.h
class Key : class CObject
{
Key(int value)
{
//...
}
};
#include <cobject.h>
#include ...
...
void main()
{
Keyboard *keybrd = new Keyboard();
Key *key = keybrd->getKeys()->getKey(10);
// done
delete the pointer returned by getKeys,getKey and keybrd by
poping items from vecObjPtr and delete;
}
is it a right way to do or is there any standard way of freeing memory like this ?
thanks in advance
-- modified at 11:36 Sunday 18th November, 2007
|
|
|
|
|
Why do you need a pointer?
e.g. if Key has a constructor Key(int) then instead of "return new Key(10)" with return type Key* you should be doing "return Key(10)" with return type Key. This way the compiler handles the allocations and frees for you.
The only time I ended up keeping track of pointers as you described is when generating strings for an object, and only that one time because I didn't think hard enough about a solution. You can always avoid these situations with better design.
|
|
|
|
|
Thanks Jheriko++,
The c++ library i use returns the allocated pointers and expect from the user of the library to delete these objects. The library has many such methods that returns newly allocated pointers so i cant change it.
every getSomethingX returns a new pointer
getSomething1->getSomething2->getSomething3->getSomething4....
for the flexibility reason i write code like the above otherwise i have to declare new pointer variable for every getSomethingX returned pointer so i can delete it later.
|
|
|
|
|
Its a shame that you are restricted by the library... you can at least avoid this trap in your own code though.
|
|
|
|
|
As a general rule, it's better to delete objects deliberately as soon as they are no longer needed. The mechanism you have described will continuously use more memory as the program runs. The longer it runs, the more memory will be consumed. You could eventually exhaust system resources, which is poor behavior .
I can see circumstances where your approach might be useful, however. Make sure that you mark your destructors virtual , and write a destructor for each class derived from your base object.
Software Zen: delete this;
|
|
|
|
|
thanks Gary,
Gary R. Wheeler wrote: As a general rule, it's better to delete objects deliberately as soon as they are no longer needed. The mechanism you have described will continuously use more memory as the program runs. The longer it runs, the more memory will be consumed. You could eventually exhaust system resources, which is poor behavior
Thats true i will declare pointer variables for newly returned pointers and delete them when they are no longer needed.
|
|
|
|
|
How do you change the working area of a non-primary screen?
AppBars effect the primary, but not the non-primary, from my experience.
TIA
|
|
|
|
|
mmm...
Screen? Or view?
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?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Thanks MDV,
Screen, the .NET class that wraps an individual physical monitor.
It hold stuff like resolution, BPP, offset from primary screen, height, width, working height and width.
It is the workingarea that I am trying to modify. In the primary display, the change if made wirh the AppBar.
Thanks
RM
|
|
|
|
|
Then sorry, I dont have used .NET yet
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?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
I'm open to a non .NET solution, I was defining what the terms I used meant, as much as anything else.
|
|
|
|
|
I have created the window in MFC and I want that it should not move it. How can I do this?
Chetan
|
|
|
|
|
Have you looked into WM_WINDOWPOSCHANGING
From MSDN:
An application can prevent changes to the window by setting or clearing the appropriate bits in the flags member of the WINDOWPOS structure.
|
|
|
|
|
Hello All,
I am developing Server Application for RTMP Server, used for Flash.
I am sending to many messages on SOCKET . If it increase the number 750 packets then connection get close.
So anybody has idea about it?
Is it a problem of SOCKET
Thanks in advance
Regards,
Manish Patel.
B.E. - Information Technology.
|
|
|
|
|
I can only guess - either a bug or bad design.
It's up to you to deal with sending "to many messages".
Manish_mnp wrote: If it increase the number 750 packets then connection get close.
What does that mean? Socket connections don't close because of some kind
of packet increase.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You better watch it... you may begin to grow gills soon
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real" Score: 1.0 in the Soap Box
led mike
|
|
|
|
|
.
.
.
><::>
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Manish_mnp wrote: I am sending to many messages on SOCKET. If it increase the number 750 packets then connection get close.
Which error code do you get back?
Do you check receiver and sender side for errors, if yes check WSAGetLastError() or GetLastError() . Maybe your socket's send buffer is full and you have to wait until you can send more.
|
|
|
|
|
See what I found here, looks like the send buffer was full
|
|
|
|
|
Hi All,
In my project I want to get the string value set in text box. So I write
following code as
CEdit *pOpenEdit = (CEdit *) GetDlgItem(IDC_FOLDER_PATH);
if( NULL != pOpenEdit->GetSafeHwnd())
{
pOpenEdit->GetWindowText(buff,256);
}
In the above code I did not get handle of edit box. What is wrong in this code.
Please send me solution if anybody have.
Thanks
Om
|
|
|
|
|
What happens if you run this code?
CWnd *pwnd=GetDlgItem(IDC_FOLDER_PATH);
pwnd->GetWindowText(buff,256);
Or if you declare a variable for editbox
m_Edit.GetWindowText(buff,256);
or if you use of WM_GETTEXT message ?
|
|
|
|
|
When I run above code I get null handle. so the code on next line is not execute.
I use same code in other function of same class for Setting string value to editbox,the code is executed in that function. So why i did not get the handle od edit box in above code.
Plz reply me.
OM
|
|
|
|
|
Are you sure id of editbox is correct and what happens if you declare a variable for it did you can values of edit control.
|
|
|
|