|
It should work, but you have to provide all the required DLLs.
to figure out which one you need to bring with your exe, use Dependency Walker[^] (if you have VC6, you already have it under the name depends.exe )
|
|
|
|
|
|
NOTE: In the following text and code I use [] rather than the greater than and less than signs because of the HTML editor.
I read about class templates in three books and MSDN and thought I understood. So, I created a SDI test project in VC++ to learn about them. I added only this single CTestTemp class. As you can see, I didn't get far. The following code keeps giving me a C2955 (use of class template requires template argument list) error in TestTemp.cpp each place a function is defined (or BEGIN MESSAGE MAP).
I have tried all kinds of argument lists in the constructor function, tried putting template[class T] in various places in the code, but nothing works. If I add a new function, the same error flags the new function. It appears I'm doing somehting wrong in the function definition. I'm at such a basic point, I figure I must be doing somehting equally basic wrong. Ideas? Thanks.
//TestTemp.h
template[class T] <--only thing I add
class CTestTemp : public CWnd
{
public:
CTestTemp();
virtual ~CTestTemp();
protected:
DECLARE_MESSAGE_MAP()
};
//TestTemp.cpp
CTestTemp::CTestTemp() <---error C2955
{
}
CTestTemp::~CTestTemp() <---error C2955
{
}
BEGIN_MESSAGE_MAP(CTestTemp, CWnd) <---error C2955
//{{AFX_MSG_MAP(CTestTemp)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
|
|
|
|
|
you need, at least, to put 'T' into your constructor:
CTestTemp(T t);
without it, you have no way to tell the compiler what type to use for T
|
|
|
|
|
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
|
|
|
|