|
Hi,
CC result= *this;
does not create anything; it declares a reference called result to a type CC and sets it equal
to *this, so now result and this are one and the same object.
IMO it was not really necessary; there must be a way to do *this.Set_X(sum) directly)
in your line 5.
modified on Sunday, July 6, 2008 5:31 PM
|
|
|
|
|
Luc Pattyn wrote: CC result= *this;
does not create anything; it declares a reference called result to a type CC and sets it equal
to *this, so now result and this are one and the same object.
Sorry, that statement is not correct.
CC result= *this;
creates an object of type CC and assigns the contents of the current object to it. To create a reference you would use CC& result = *this;
Actually the above code probably does not use the assigment operator, it may well use the copy constructor (the compiler is allowed to treat declaration and assignment in one statement as copy construction rather than default construction followed by assignment).
Graham
Librarians rule, Ook!
|
|
|
|
|
Hi,
I believe you are right, I was looking through my C# glasses once more.
|
|
|
|
|
The code is fine, the compiler will generate operator= and the copy constructor for you, it's simply implicit instead of explicit.
Rhe default implementation is a simple bitwise copy.
The way the compiler generates the copy is sort of like:
ClassA::ClassA( const ClassA &from)
:member1( from.member1 )
,member2( from.member2 )
,.... etc
{}
This is perfectly fine for this class since you don't have any pointers to worry about.
The default for operator= is functionally the same as the copy constructor.
So your code for operator+ is correct.
this is copied to result.
result is modified.
this actually remains constant.
So actually to be on the safe side you should do.
......
CC operator+( CC &source ) const;
......
CC CC::operator+( CC &source ) const
{
CC result = *this;
double sum = source.Query_X() + X;
result.Set_X( sum );
return result;
}
|
|
|
|
|
Hello Dan,
I am rather certain I agree about the const. However, I am a bit weak on exactly where the const goes to effect which part of a declaration. For the moment, I want to keep the thread as simple as I can. I will get back to the const in another thread. Thanks for the reminder.
Thanks for your time
|
|
|
|
|
Hi,
Can I know how to perform structured exception handling in Windows Vista..
I need alternatives to Isbadreadptr,IsBadWritePtr in Windows Vista.. But Vista documentation suggests to perform Structured exception handling. Can I know how to perform Structured exception handling
Thanks,
venkat
|
|
|
|
|
Using IsBadReadPtr or Structured Exception Handling (or for that matter any other method) to detect illegal memory accesses is wrong headed in the vast majority of cases. There are many issues but here are a few:
- Makes debugging harder as an exception that would have triggered a debugger or the generation of a crash dump is swallowed. I do a lot of post-mortem debugging: when you click the “Send Error Report” button, in theory, someone will look at the dump-file which is sent and actually figure out what’s going on. If you don't use the Windows Error Reporting[^] service (or something else which performs the same task) then you're doing it wrong.
- In general proper recovery is impossible and attempting to just makes things worse. An analogy is a person who continues to drive with a flat tire.
Follow link this[^] for Larry Osterman's opinion on the matter and follow this[^] link for Raymond Chen's.
Steve
|
|
|
|
|
Thanks Steve. Can I Know what could be the better substitute for detecting illegal memory access.. Can I have a sample code snippet to get an idea.
Thanks,
Venkat
|
|
|
|
|
int* x = new int[1000];
void foo(int i)
{
if(i>0 && i<1000)
{
x[i] = 0;
}
else
{
}
}
That's it!
-Saurabh
|
|
|
|
|
As I said, in general the best substitute for detecting an illegal memory access is crashing!
Steve
|
|
|
|
|
Hi,
We have a legacy code written in C. We are porting to Windows Vista. We have certain checks like IsBadReadPtr and IsBadWritePtr. These two checks donot work in Windows-Vista. Can I know how to validate a memory block before its usage in Window-Vista... I mean what could be the appropriate replacement for IsBadReadPtr and IsBadWritePtr in Windows Vista.
Thanks,
Venkat
|
|
|
|
|
Documentation [^] suggests to substitute such a function with structured exception handling.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks.. Can I have a code snippet for performing structured exception handling..
|
|
|
|
|
Possibly documentation [^] helps.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Possibly documentation helps.
Not when left unread
|
|
|
|
|
Plz give code urgent plz plz.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Why not write your own.
Just set up a try/catch block and a for loop which reads each byte in the range. return true from the catch, or false if it terminates in the try block. IsBadWritePtr goes similar, just try to write the selfsame byte back to where it was read from.
Regards,
Bram van Kampen
|
|
|
|
|
Why not just crash? See here[^].
Steve
|
|
|
|
|
Hey everybody!
Does anyone know where can I find the domain controller SID in the WMI (XP) ???
Thanks!
|
|
|
|
|
Look at Win32_NTDomain class in WMI. It has among other these members.
string DomainControllerAddress;
int32 DomainControllerAddressType;
string DomainControllerName;
string DomainGUID;
string DomainName;
-Saurabh
|
|
|
|
|
Hey, Thanks for your help!
But I need SID, which is not found over there...
|
|
|
|
|
Okay, found it.
If we will take a look for at Win32_Group (it can be done in other ways, that is just one of them), all the groups that belong to the domain has the same SID prefix.
This prefix is the domain's SID!
Ta-Da!
Have Fun!
|
|
|
|
|
Great! Thanks for sharing.
-Saurabh
|
|
|
|
|
the application i am using requires the uncompressed tiff file having bit depth 1 and resolution of 300dpi. it is built in dot net 2003. whenever i open the uncompressed tiff image having bit depth 1 and save the same tiff image using savefiledialog function of dot net2003, the uncompressed tiff file becomes compressed and the bit depth is increased to 32. i haven't use any compression function. the code of saving the file is given below
private: void saveImageFile()
{
saveImage->Filter= "Tiff files (*.tif)|*.tif" ;
saveImage->FilterIndex = 1 ;
saveImage->RestoreDirectory = true ;
System::Windows::Forms::DialogResult d = this->saveImage->ShowDialog();
if (d == System::Windows::Forms::DialogResult::OK)
{
// creating a bitmap
Bitmap* saveMyImage;
saveMyImage=new Bitmap(this->pictureBox1->Image);//,System::Drawing::Imaging::PixelFormat::Format1bppIndexed);
saveMyImage->SetResolution(300,300);
saveMyImage->PixelFormat::Format1bppIndexed;// this line doesnot work
saveMyImage->Save(saveImage->FileName,System::Drawing::Imaging::ImageFormat::Tiff);
}
}
|
|
|
|
|
I think you better ask the managed C++/CLI forum [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|