|
Voted a 4: although you're right about the class operator new being called first, it will eventually call the global new within it, don't think the compiler allows you to dodge the constructor with the new keyword. See the link I provided below...
It's really a good question because I never tried to do this before.
|
|
|
|
|
Albert Holguin wrote: it will eventually call the global new within it
This is all explained in the MSDN link I provided in my answer.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Overloading operator new only affect how memory is allocated. The constructor of your class is always called.
By the way, it has nothing to do with C++/CLI and thus, it is in the wrong forum.
Philippe Mori
|
|
|
|
|
|
It is defined by the standard to works that way. By the way, why would you wany to override operator new. It is hard to do correctly and efficiently.
And it C++, it never a good idea to create an object without calling its constructor. Thus why you would want it that way?
Also, if you override new, then you should probably override delete also to have a matching implementation.
Philippe Mori
|
|
|
|
|
1. Can I pass the CommVariant to other function, when not created using new ?
2. Should I free it/delete expecitly some where ?
3. Is it safe ?
<pre>CComVariant comVariant;
comVariant.vt = VT_I4;
comVariant.intVal = 10;
SendComVariantToOtherFunction(comVariant);
Thanks in advance!!
|
|
|
|
|
I'm new to C++ and am running into another hicucp I'm hoping someone can help me with. I'm looking to change the opacity on a form when the mouse enters it (to 100%), and then dim it again when the mouse leaves the Windows form. I can almost get things to work, but I'm seeing oddities that I think are due to the fact that it "enters" other controls that are on the form. Here's what I've been tinkering around with:
private: System::Void MyForm_MouseHover(System::Object^ sender, System::EventArgs^ e) {
this->Opacity = 1.00;
}
private: System::Void MyForm_MouseLeave(System::Object^ sender, System::EventArgs^ e) {
this->Opacity = 0.50;
}
private: System::Void MyForm_MouseEnter(System::Object^ sender, System::EventArgs^ e) {
this->Opacity = 1.00;
}
Can someone explain to me how I can prevent my code from repeatedly reading things until the cursor leaves the entire form?
Thanks!
|
|
|
|
|
I NEED HELP WITH THE FOLLOWING:
Write a class called Thermometer. The thermometer should have the following features:
• Return the current temperature in either C or F (conversion)
• Reset the temperature to zero (if the current scale is C) or 32 (if the current scale is F)
• Set the scale of the thermometer to either C or F
• Set the temperature
• Return the current scale
• Provide a copy constructor to make a copy of a Thermometer
All data members of your class should be private. You should include a constructor to initialize the Thermometer object to 0˚ C, as well as a constructor that accepts a temperature and scale to initialize to. You will also need a copy constructor.
|
|
|
|
|
What exactly do you need help doing?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I need help with the copy constructor.
|
|
|
|
|
So, what's the problem ?
This looks like a nice homework for entry level programming.
I assume you have course notes, documentation, discuss the problem with your friends and class mates, ask questions to your teacher and/or lab assistant.
Watched code never compiles.
|
|
|
|
|
include "ClassCons2.h"
#include <iostream>
using namespace std;
class ThermoClass {
private:
char C;
char F;
float temp;
ThermoClass();
SetTemp(float atemp);
SetTheScale(char C, F);
GetTemp();
Scale = 'C';
};
int main ()
{
ThermoClass::Thermoclass (float) {return afloat};
ThermoClass thermoObject;
thermoObject.SetTheScale;
return Scale;
}
THIS IS WHAT I'VE DONE SO FAR. I NEED TO KNOW IF I'M ON THE RIGHT TRACK
|
|
|
|
|
It looks like you have a lot to learn about classes. You have created a class with a number of elements that do not seem to have any purpose. You have also not written the implementation of any of the class methods. I would suggest spending some more time with your course notes learning how to create simple classes and how the various parts fit together (constructors, properties, methods etc.).
You could also use the MSDN documentation[^] to help clarify what a class is.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
1. Write the class without the copy constructor.
2. Review you class notes and text book paying attention to what it says about copy constructors.
3. Using 2 add code to 1 to make a copy constructor.
|
|
|
|
|
I'm new to C++ and still learning a ton, and I'm hoping that someone can point me in the right direction to solve a problem (my Google-fu has failed me). I have a Windows form that displays on the the screen, and everything works just fine. My problem is that I want it to fade in when it's opened, and fade out when it's closed.
I can't seem to find any good C++ examples (that I can understand). Can anyone shed some light on this for me? Thanks!
|
|
|
|
|
Uses a timer and increase the opacity until the form is fully opaque.
Philippe Mori
|
|
|
|
|
I don't understand your reply. I already tried something like this:
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e){
for(double i = 0; i < 1.05; i += 0.05){
this->Opacity = i;
this->Refresh();
}
}
But that didn't do anything. Can someone give me a little more info? Thanks.
|
|
|
|
|
There are at least two problems with your code:
1. there is no delay in your loop, it will sprint from 0 to 1 as fast as it can, all will be over in a fraction of a second.
2. the Form isn't visible while the Load handler is executing; it is only when Load is done that the Form becomes visible, so this is the wrong place for such loop.
The recommended solution to both these issues is as follows:
- give your Form an initial opacity of zero;
- in your Load handler, start a Windows.Forms.Timer with an interval of say 100 msec;
- in the timer's Tick handler, check the Form's opacity; if it is less than 1.0, add 0.05 to it; otherwise, stop the timer.
The reason you choose a Windows.Forms.Timer is that its events get handled by the main thread, and that is the only thread that is allowed to touch Controls and Forms. Other timers would tick on some threadpool thread, resulting in either some InvalidCrossThread exception, or the need for more code, based on Control.Invoke
Also notice there is no explicit loop anywhere; the timer will keep firing until you tell it to stop (when opacity reached 1.0).
|
|
|
|
|
I am reading a courrpted file, and I know that It will throw any exception,
and hence I want to catch it and make the app smoth.
<pre>WORD mydata;
try
{
ar >> mydata;
}
catch(CInvalidArgException* e)
{
}
catch(CArchiveException* e)
{
}
And the application throws below exception
First-chance exception at 0x7c812afb in xxxxxxxxxxx Microsoft C++ exception:
CArchiveException at memory location 0x0497e360.
kinldy help....
|
|
|
|
|
either I didn't understand or your question does not make sense.
What do you mean by corrupted file?
is it corrupted because of file format? or something else
|
|
|
|
|
Issue is control is not comming in to the
catch(CArchiveException* e) block while debuging.. but still CArchiveException is thrown.
soe if CArchiveException is thrown.. then the control should come to catch(CArchiveException* e) right ? That is not happninig 
|
|
|
|
|
You are catching the exceptions but ignoring them, so you will not see anything in your code. Add some code in the catch block to process the exception.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Issue is control is not comming in to the
catch(CArchiveException* e) block while debuging.. but still CArchiveException is thrown.
soe if CArchiveException is thrown.. then the control should come to catch(CArchiveException* e) right ? That is not happninig 
|
|
|
|
|
You have no code in your catch block so there is nowhere for it to go. Add some code and try again, at least you will be able to inspect the contents of the exception object.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
In the actual code I had few lines extrating the exception message and logging it.
but in the code I posted it was not there.... but controls never enters the catch block, even though the code was there and exception it throws was same ie (CArchiveException* e)
|
|
|
|