|
bilbobaggio wrote: I think the problem...
What problem?
bilbobaggio wrote: ...i get an error.
What error?
bilbobaggio wrote: ~A() { delete data; }
Use delete[] instead.
There's also a missing semicolon at the end of the class.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
ok, sorry for not indenting and explaining myself properly. i have the missing semicolon and am using delete []. when i run the program. the values from temp2 get copied to temp1 and this gets displayed. but then when the program exits i get a 'Debug Assertion failed error - file: dbgheap.d, line:1017,
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
When I debug the application I see that the A dtor gets called after the assignment operation which removes the reference to the array data. So when the program exits and the destructor is called again it gives an error. But i dont know why this is happening or how to overcome it. here is my code sample
extern int y;
class A {
private:
int* data;
public:
A() { data = new int[5]; for (int i=0; i<5; i++) data[i]=y+i; }
~A() { delete [] data; cout<<"a dtor"<<endl; }
A& operator= (const A a);
friend ostream& operator<< (ostream& out, const A &a);
};
A& A::operator =(const A a)
{
if (this == &a)
return *this;
for (int i=0; i<5; i++)
data[i] = a.data[i];
return *this;
}
ostream& operator<< (ostream& out, const A &a)
{
for (int i=0; i<5; i++)
out << a.data[i] << " ";
return out;
}
then the main
void main()
{
y=1;
A temp1;
y++;
A temp2;
cout << temp1 << endl;
cout << temp2 << endl;
temp1=temp2;
cout << temp1 << endl;
}
the program output is as follows
1 2 3 4 5
2 3 4 5 6
a dtor
2 3 4 5 6
then the error.
|
|
|
|
|
bilbobaggio wrote: A& operator= (const A a);
Your assignment operator should take a reference as argument, like this:
A& operator=( const A& a ) The way you've implemented it, when the operator= function is called a copy will be created on the stack. Since you don't have a copy constructor the stack copy will be a shallow copy, i.e. the stack copy's data member will point to the same location as temp2 in main(). The allocated data will be deleted by the stack copy dtor. The error occurs when temp2 dtor is called since the memory already has been deleted.
--
Roger
It's supposed to be hard, otherwise anybody could do it!
|
|
|
|
|
Roger Stoltz wrote: Your assignment operator should take a reference as argument...
Which is odd because that is what he had in the original code snippet. It really irks me when folks try and type code snippets into their posts rather than use copy/paste.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hmm, I saw that now when you mentioned it.
I just read your reply earlier and since you asked him for more info I figured I rather read the second post of his.
Well, given his explanation about the error it could be the assignment operator declaration and that his first post was erroneous.
--
Rog
It's supposed to be hard, otherwise anybody could do it!
|
|
|
|
|
There is no indentation - If you want people to help you make it easy for them be including formatting in your code. Apart from that, I can't see anything wrong (beyond the already mentioned fact that you're using delete instead of delete [] ). Looks like you'd be better off using a std::vector or std::valarray to me.
Steve
|
|
|
|
|
I noticed that in VS 2005, the return values of GetCount method of CList and CArray and their derived classes are of INT_PTR. I am wondering why INT_PTR not int or long? To me, that is getting messy of MFC 7.0 or higher in dealing with data types.
Thanks.
-- modified at 16:05 Tuesday 28th March, 2006
|
|
|
|
|
yellowine wrote: I am wondering why INT_PTR not int or long?
In basetsd.h , it is defined as an int (or __int64 ).
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hi, you can you const int nLength = (int)pArray.GetSize() to remove all the 4 level warnings in your application - i'm dealing with 32 bit applications.
|
|
|
|
|
I am using directshow to develop some applications. I need to use IMediaSeeking::setpositions to set start position and stop position to run the buildergraph to write a segment of a song. As I use setpositions function, hr = E_NOTIMPL. Thanks for any information about this problem.
|
|
|
|
|
Sir , Can Any one help me in knowing why it is not possible to Split a StaticSplitter More than 16rows and 16Cols? pls help me in understanding the concept better.
Thank U
Fly Like An Eagle With MIGHTY POWER.
|
|
|
|
|
Why would you think it useful to navigate through 256 different windows?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
I remember seeing an article somewhere, maybe here on CP, where a splitter was used to create a table. Each 'window' displayed a simple float. I know its not really related, just thought I would mention it.
I couldn't help thinking of the overhead and code which goes into managing so many windows.
http://www.codeproject.com/splitter/extsplitter.asp[^]
|
|
|
|
|
waldermort wrote: I remember seeing an article somewhere, maybe here on CP, where a splitter was used to create a table. Each 'window' displayed a simple float.
I would think a grid control would be better suited for the job.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hello.
Dunno that MFC or COM question.
How to construct or attach to ActiveX Control wrapper class, derived from CWnd, already exist COM object exposed LPDISPATCH.
-- modified at 15:22 Tuesday 28th March, 2006
|
|
|
|
|
You can try CWnd::GetControlUnknown() from the control container or CCmdTarget::GetControllingUnknown() inside an ActiveX control's source(an undocumented function and may not function in future versions of MFC)
My blogs:
http://blog.joycode.com/jiangsheng
http://blog.csdn.net/jiangsheng
http://bloglines.com/public/jiangsheng
Command what is yours
Conquer what is not
---Kane
|
|
|
|
|
I posted this same question two days ago but have so far not gotten an answer. I am assuming that there is no way to do what I want, but I will ask again just in case someone who does know missed my question the first time.
Given an HCURSOR handle, how can one tell if it is an animated cursor (loaded from an .ani file or RT_ANICURSOR resource) or not?
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
A cursor is almost identical to an Icon. So in theory you should be able to use the ExtractIconEx() function to return an array of Icons. If you have more than one icon, then you are dealing with an animated cursor.
Take a look here[^] for more ideas.
|
|
|
|
|
The theory is not bad, but unfortunately it does not work. ExtractIcon and ExtractIconEx are used to retrieve icons from a file (.exe, .dll, or .ico), not from an HICON or HCURSOR handle.
I am writing a wrapper class around HCURSOR, and there are some things that I can do with a static cursor that I can not do with an animated one, such as compare them to see if they are the same or change the location of the hotspot. Being able to tell if an HCURSOR is animated or not would be handy.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Then why don't you try the DrawIconEx and set the istepIfAniCur member to something greater than 0. I'm sure the function would fail if it's not an animated cursor.
|
|
|
|
|
From MSDN:
istepIfAniCur
[in] Specifies the index of the frame to draw, if hIcon identifies an animated cursor.
This parameter is ignored if hIcon does not identify an animated cursor.
But I will try it anyway
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
I might be able to make this work, if I draw frame zero and frame one and then compare them. If they are different I got an animated cursor, if they are the same I got a static cursor. Seems like a really bad hack but until something better comes along
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Do not use the CopyCursor function for animated cursors. Instead, use the CopyImage function.
I'm wondering if CopyCursor returns an error if you pass it an animated cursor?
Montreal great Guy Lafleur, quoted by CBC on being mugged while vacationing recently in Buenos Aires: "I didn't have any time to react before I got a sucker-punch in the eye. It was like one of the players from the Bruins."
|
|
|
|
|
Jack Squirrel wrote: I'm wondering if CopyCursor returns an error if you pass it an animated cursor?
No error, it just creates a static cursor containing the first frame of the animated cursor.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Hi, I am using ADO 2.81 with C++ 6.
In my program I have a datagrid which is filled with data from adodatacontrol. Whenever i select a different row, my app needs to display information about it. The problem is, I can't find in which row the user clicked...
Is there any code that can help me?
i am trying to put it in the function:
void CMyDlg::RowColChangeDatagrid(VARIANT* LastRow, short LastCol)
here lastRow shows the last row clicked not the present.
I tried with dataGrid.get_Row();
this works fine if I dont scrool the data grid. But if I do so, it gives me the same informations (like I am not scrolling)
PLS help
|
|
|
|