|
isn't delete[] useful only when the memory is allocated with new[] and simple delete useful when simple new used ?
|
|
|
|
|
toxcct wrote: isn't delete[] useful only when the memory is allocated with new[]
Yes, and that's what he has here:
BYTE *pbMessage= new BYTE[12];
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Rage wrote: Note that delete pbTest does not work either in the first example.
Is it throwing exception right from the first element in the loop while deleting? Are you sure pop is working correctly?
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http:\\nibuthomas.wordpress.com
|
|
|
|
|
How is your "sort of stack" declared? Template argument, if any, and push/pop functions...
I wonder since the stack::pop() function of the usual STL stack is declared as void pop() , so you must be using something else. The equivalent function in the STL stack would be <YourType>& top() .
If your pop() works like you think it should work, I can't see why you would get the exception...
But perhaps it's still too early in the morning for me...
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hello again,
If that's one of my stacks you're adapting the chances are it takes the address of what you pass to it, so it would actually be storing a BYTE** in this case, requiring you to dereference the result of pop back to a BYTE* with something like BYTE* pData = *pPopResult . You definitely need to check this if you adapted one of my data structures. I tend to make containers store the addresses of contained items to avoid copying.
Remember BYTE[15] and BYTE* are the same type so delete [] pbTest is correct if pbTest is BYTE*. If it's BYTE** then it will be trying to delete an array of 4 byte BYTE* pointers hence the exception.
If the stack comes from elsewhere then feel free to ignore all this rambling.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Thanks, but I only took a few ideas from your article, and the implementation is indeed different here.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverb
|
|
|
|
|
Yes you must check them else you have trouble code.
|
|
|
|
|
Ok, thanks.
I appreciate your help all the time...
Eranga
|
|
|
|
|
|
now that i am displaying the designators in a combo box. i used recursive function to display that in the combo box. the next thing that i need to do is when i click on the designator the files and folders in that designator should display in a list box. what needs to be done for that?
chandru080
|
|
|
|
|
Well it seems that this question is in the continue other question but do you want to show content a file on the listbox or other thing?
|
|
|
|
|
yes it is. i need to shw the content of the directory in a list box. that is when i click on C: the folders and files of that c: should appear on the listbox. same goes to other directories also
|
|
|
|
|
For show files and folders on the listbox you can use of DlgDirList function also you can use of FindFirstFile/FindNextFile .
|
|
|
|
|
Take a look in the forum, there has been a similar question a few days ago
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
|
|
|
|
|
Nelek wrote: ...there has been a similar question a few days ago
And the posters share the same name. Amazing! Maybe that's why he started off by stating, "now that i am displaying the designators in a combo box."
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
something wrong in that usage??? well that was a continuation of a previous query. thought will start of with a new one..
|
|
|
|
|
Chandrasekharanp wrote: something wrong in that usage???
No, I was just curious why Nelek did not associate the two posts were both from you.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Because I didnt notice different questions, sorry
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
|
|
|
|
|
what is advantage of "Base class pointer to Derived Class object" ?
class Base
{
public:
Base(){ cout<<"Constructor: Base"<<endl;}
~base(){ cout<<"destructor="" :="" base"<<endl;}
void="" funbase()
{
cout="" <<"base="" function="" invoked"<<endl;
}
};
class="" derived:="" public="" base
{
public:
derived(){="" cout<<"constructor:="" derived"<<endl;}
~derived(){="" derived"<<endl;}
void="" funderived()
{
cout="" <<"derived="" invoked"<<endl;
}
};
int="" _tmain(int="" argc,="" _tchar*="" argv[])
{
cout<<"ashish"<<"\n";
base="" *var="new" derived();
delete="" var;
}
even="" though="" "var"="" points="" to="" derived="" class="" object="" ,="" it="" cannot="" access="" member="" i.e="" funderived().="" var="" can="" only="" base="" functions.
instead="" of="" why="" dont="" we="" use="" ,
base="" *check="new" base();
check-="">fun1();
I guess it is having same behaviour. Please let me know wht is advantage of using base class pointer to derived class object?
Thanks\
Ash.
|
|
|
|
|
It is in fact extremly powerfull and widely used. This is what is called 'polymorphism' (if you google for it, you'll probably find tons of information).
The principle is that you declare some virtual function in your base class that can be redefined by a derived class. In this way the derived class can have a different behavior as its parent. And, if you have several different derived classes that inherit from the same base class, they all can be treated as a base class but have different behavior (and, so, they can all be stored in an array for example).
If you want a typical example: suppose that you write a program to draw shapes (triangles, squares, circles, ...). What you would do in that case is have a base class CShape that has a virtual method Draw. Each derived class (CSquare, CCircle, CTriangle, ...) will specialize this Draw method for itself. All the shapes, as they are inherited by the same base class can be manipulated exactly the same way (they will be stored in an array, and whenever you need to redraw your drawing, you will call Draw from all the shapes in your array, no matter what shape it really is).
This is an extremly important concept in OOP.
|
|
|
|
|
Try using virtual functions.
This gives your base class pointer a behaviour depending on the class where it is derived from.
class CBase
{
public:
virtual void OpenDoor( ) = 0;
};
class House: public CBase
{
public:
virtual void OpenDoor( )
{
AfxMessageBox(_T("Open door of house") );
}
};
class Car: public CBase
{
public:
virtual void OpenDoor( )
{
AfxMessageBox(_T("Open door of Car") );
}
};
CBase* pObject = new House;<br />
pObject->OpenDoor( );<br />
|
|
|
|
|
Thanks Koos,
I got wht i ws searching for..
|
|
|
|
|
Below is the steps that i have followed to create a web page viewer and i have a restriction to create it only using Win32 Projects.
Using visual studio .NET 7.0 with framework 1.1
1.File -> New -> Project
2.Choose Visual C++ Projects -> Win32 -> Win32 Project
3.Project Name "Browser"
Now i want to make it a web page viewer and want to take screen shot of the viewed pages and want to save it as 24bit bitmap image.
Thanks,
Soumyadipta De
|
|
|
|
|
These steps are common for other objects except you set a browser name for it
but do you want to show html pages on your dialog?
|
|
|
|
|
Hi All,
I am writing a non MFC Application using Opengl (Win32 Project) but i am using
some MFC Headers below
#include // MFC core and standard components
#include // MFC extensions
#include // MFC Automation classes
#include // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include
#include
////////////////////////////////////////////////////////////////////////
I want to use Web Browser Control On my project (Activex) but i am not
using any form i want create web browser using createWindow function
////////////////////////////////////////////////////////////////////////
It will be really help full if anyone please send me sample code
Thanks,
Soumyadipta De
|
|
|
|