|
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)
|
|
|
|
|
Once you have added actual code to the catch blocks, try running outside your IDE. Some, like Visual Studio, sometimes intercept exceptions before your catch block becomes active, although you typically can influence that through some IDE settings.
|
|
|
|
|
You're catching a pointer to CArchiveException, shouldn't you catch a reference to it?
ex. catch(CArchiveException & e) or maybe catch(CArchiveException const & e)
John
|
|
|
|
|
See here[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hi!
I'm stuck with the calling that DLL.
Can someone help me how to read the values of the DLL? OCIOpen of the opening returns sucess, but that reading doesn't work.
I guess... The problem is unmanaged/managed, but I don't how to solve it.
************ Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at WindowsFormsApplication3.Form1.oci.OCIRead(Int32 lOIObject, Int32 lDevice, Int32 lIndex,
OCIRead or OCIGetIndexInfo doesn't work.
using System.Runtime.InteropServices;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
[StructLayout(LayoutKind.Sequential)]
public struct OIDATA
{
[MarshalAsAttribute(UnmanagedType.SafeArray, SafeArrayUserDefinedSubType = typeof(Int32))]
public Int32[] lData; //'array of data, values depeds of index number
public Int32 lCheckAlarm; //'when read request is done and this is > 0 user should check alarm
public Int32 lCategory; //'when this is > 0 device configuration is changed
public Int32 lReadError; //'read error is occured
[MarshalAsAttribute(UnmanagedType.SafeArray, SafeArrayUserDefinedSubType = typeof(byte))]
public byte[] szData; // 'String * 128 'raw index read data as comma separated
}
/*
[StructLayout(LayoutKind.Explicit)]
public unsafe struct OIDATA
{
[FieldOffset(0)]
public fixed Int32 lData[32];
[FieldOffset(128)]
public Int32 lCheckAlarm;
[FieldOffset(132)]
public Int32 lCategory;
[FieldOffset(136)]
public Int32 lReadError;
[FieldOffset(140)]
public fixed byte szData[128];
}
*/
public OIDATA pOIDATA = new OIDATA();
public Int32 lObject = 0;
public Int32 lComPort = 5;
public Int32 OCI_OUTDOORTEMP = 3;
public Int32 OCI_MIN_INDEX = 0;
public Int32 OCI_MAX_INDEX = 63;
public sealed class oci // api // DLL Wrapper
{
internal const string DllName = "oci200.dll"; // handy const
[DllImport(DllName)]
public static extern Int32 OCIOpen(ref Int32 lOIObject, Int32 lComPort);
[DllImport(DllName)]
public static extern Int32 OCIRead(Int32 lOIObject, Int32 lDevice, Int32 lIndex, [param: MarshalAs(UnmanagedType.Struct)] ref OIDATA pOIData);
// _EXPORT(long) OCIGetIndexInfo(long lIndex,char **pszInfo,long *plRead,long *plWrite);
[DllImport(DllName)]
public static extern Int32 OCIGetIndexInfo(Int32 lIndex ,
[In, MarshalAs(UnmanagedType.LPStr)] System.String pszInfo,
ref Int32 plRead, ref Int32 plWrite);
}
private void cmdConnect_Click_1(object sender, EventArgs e)
{
Int32 l = oci.OCIOpen(ref lObject, lComPort);
lstOuman.Items.Add("OCIOpen: " + l);
pOIDATA.lData = new Int32[32];
pOIDATA.lCategory = 1;
pOIDATA.lCheckAlarm = 0;
pOIDATA.lReadError = 0;
pOIDATA.szData = new byte[128];
Int32 lIndex = OCI_OUTDOORTEMP;
Int32 lDevice = 2;
System.String pszInfo ;
Int32 plRead = 0;
Int32 plWrite = 0;
//pOIDATA.szData[127] = 0;
Int32 k = oci.OCIRead(lObject, lDevice, OCI_OUTDOORTEMP, ref pOIDATA); //This is where error occurs
lstOuman.Items.Add("OCIRead: " + k);
txtOuman.Text = k.ToString();
// l = pOIDATA.lData[0];
for (int i = OCI_MIN_INDEX; i < OCI_MAX_INDEX; i++)
{
long result = oci.OCIRead(lObject, lDevice, i, ref pOIDATA); //This is where error occurs
lstOuman.Items.Add(" " + i + " arvo: " + result );
//_EXPORT(long) OCIGetIndexInfo(long lIndex,char **pszInfo,long *plRead,long *plWrite);
long results = oci.OCIGetIndexInfo(i, "", ref plRead, ref plWrite);
lstOuman.Items.Add(" " + i + " info: " + results );
}
}
********* oci200.h ******************
/*******************************************************************************
Index struct
*******************************************************************************/
struct OIDATA
{
long lData[32]; // array of data, values depeds of index number
long lCheckAlarm; // when read request is done and this is > 0 user should check alarm
long lCategory; // when this is > 0 device configuration is changed
long lReadError; // read error is occured
char szData[128]; // raw index read data as comma separated
};
/*******************************************************************************
Function: OCIRead
Comments: Read index data from EHx device
Input: long lOIObject , connection handle
long lDevice, device index 0..x if more than 1 device in com line
long lIndex, index to read OCI_MIN_INDEX ... OCI_MAX_INDEX
struct OIDATA *pOIData, pointer to read data struct
Return: success, OCI_OK
failure, OCI_* error code
*******************************************************************************/
_EXPORT(long) OCIRead(long lOIObject,long lDevice,long lIndex,struct OIDATA *pOIData);
*******************************************************************************/
_EXPORT(long) OCIWrite(long lOIObject,long lDevice,long lIndex,struct OIDATA *pOIData);
/*******************************************************************************
Function: OCIGetIndexInfo
Comments: Get read/write index info
Input: long lIndex, index id value range OCI_MIN_INDEX ... OCI_MAX_INDEX
char ** pszInfo, pointer to description info
long *plRead, pointer to readable flag, if > 0 index can be read
long *plWrite, pointer to writable flag, if > 0 index can be write
Return: success, OCI_OK
failure, OCI_ERROR
*******************************************************************************/
_EXPORT(long) OCIGetIndexInfo(long lIndex,char **pszInfo,long *plRead,long *plWrite);
Programming is like sex:
One mistake and you have to support it for the rest of your life.
|
|
|
|
|
I need some detailed explanations about constructors using pointers.
|
|
|
|
|
Perhaps a specific question would be more appropriate?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
I am using VS 2010 Professional.
I am getting the error:
error C2143: syntax error : missing ';' before '*'
From:
Unmanaged *pu;
I assume there is something very simple that I am overlooking. This problem can be easily re-created. I re-created it by creating a Visual C++ CLR Class Librsry project. Then I used the Class Wizard to create an unmanaged class called Unmanaged. Then in the managed Class1 class I added the line shown above. Then I built that without any other changes and got the error. I do not understand why.
|
|
|
|
|
There is obviously something missing in your code such that the term Unmanaged is not being correctly interpreted by the compiler. Perhaps if you post your class definition also, someone can figure out what's wrong.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I am an idiot. I forgot to #include "Unmanaged.h". I definitely know better but for some reason I did not use my brain.
|
|
|
|
|
Sam Hobbs wrote: for some reason I did not use my brain.
You are now a certified developer; it's something we all do from time to time.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|