|
OOps,I meant it didnt run at all, didnt compile errors were like:
C:\Trainer\Train\Train1\Train1View.cpp(796) : error C2440: '=' : cannot convert from 'char [7]' to 'int'
which didnt clue me in to the fact that I had not declared "value" . I'm sure that error was there too, but I didnt see it buried in all the compiler warnings for STL.
It works now.
Thanks,
ns
|
|
|
|
|
(I know I'm not answering your question, but...) You should bracket your code within <pre> and </pre> tags in order to preserve the indentation so that it's easy to read. The new formatting buttons that Chris introduced makes it easy to do this.
Thanks,
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
ns wrote:
I'm sure that error was there too, but I didnt see it buried in all the compiler warnings for STL.
You can get rid of those warnings with a pragma.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
|
I want to integrate a version for my DLL... How to do that???
Thanks in advances
Hello World!!!
from Raphaël
|
|
|
|
|
Add a resource script (.rc) file to the project, then select the "Resources" tab within VC++ and add a version resource.
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I was the beginner of the learner c language now meet some proble instead donot how to apply the colour source in my program so hope can u help me? The project that want to apply in the background text and text that hv the colour.
Thank you.
|
|
|
|
|
I'm sorry, but I can't understand what you're trying to ask
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
i want ask how to apply the colour in the c language program while we execute the program that colour will appear at the MS-DOS Prompt
|
|
|
|
|
i need the colour source code and that function how to use i hv try before that with using the #include <graphics.h> to apply the color for my text and text background color but cannot work
|
|
|
|
|
|
My current code is this
AddPrinterDialog::AddPrinterDialog()
{
try
{
mAddPrinterDialogPointer = new AddPrinterDialog;
}
catch(...)
{
PostMessage( WM_QUIT, 0, 0 );
}
}
BUT what happens if I have an overloaded constructor that initialises data members during construction? My try block won't work will it, as I am using 'new' to implicitly call the default constructor.
How could I change my code so I can construct an object with all data members initialised to ArgumentA that is passed in?
Daniel
Obseve everything, remember more...
|
|
|
|
|
I'm not sure what you're after now. Can't you just use right constructor with new?
m_addPrinterDialogPtr = new AddPrinterDialog("doopa", "zoopa", "koopa", NULL, 3.14);
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
I've just found that the following puts the aplication into an assertion loop.
AddPrinterDialog::AddPrinterDialog()<br />
{<br />
try<br />
{<br />
mAddPrinterDialogPointer = new AddPrinterDialog;<br />
}<br />
catch(...)<br />
{<br />
<br />
}<br />
<br />
}
All I want is some code that has a constructor throwing an exception if it fails. It seems I can't use the current code.
That webpage was interesting, but the code was v.confusing. For example
<br />
C::C()<br />
try<br />
: A ( )
, b_( )<br />
{<br />
}<br />
catch( ... )<br />
{<br />
<br />
}<br />
<br />
is all very well but what if you're NOT inheriting? Or you don't care about parent classes (say you derived from an MFC class).
All I want is a default constructor throwing an exception. But I have no idea how you test for an object's existence, especially inside the default constructor's body as the object won't have been created yet.
Obseve everything, remember more...
|
|
|
|
|
First of all, you have infinite recursion in your construction - I didn't spot this in original post. Why are you keeping pointer to AddPrinterDlg inside AddPrinterDlg?
Second: as the article I've pointed you to said, object doesn't live (and, in fact, have never been born) when exception was thrown during construction. If you expect exceptions coming out of constructor, you should create your object in try/catch block.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Firstly thanks for your continued support. Much appreciated. I am understanding a bit more now.
The pointer is a member of AddPrinterDlg.
My instructions are that "every constructor that fails shall throw an exception" but I am having problems with this.
From what you say, should I assume that every time I create an object in my .cpp files I should put it in a try block?
Like so:
//... some code...
try
{
if ( !AddPrinterDlg DlgObject )
{
throw 100;
}
}
catch( int i )
{
cout << "Error: " << i << endl;
}
DlgObject.DoModal()
//... more code...
Obseve everything, remember more...
|
|
|
|
|
You should use try/catch when your objects may throw an exception from their constructors (and from other methods as well).
What kind of failures are you expecting in AddPrinterDlg constructor?
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
I'm not expecting any failures whatsoever, but it's got to be in as a safeguard.
So what do I put in the empty constructor body? do I need to put a try and catch block in there or do I just leave it blank?
Obseve everything, remember more...
|
|
|
|
|
tom76 wrote:
So what do I put in the empty constructor body?
Nothing. If your base class constructor throws, you're not going to catch it in constructor body. Standard C++ allows try/catch blocks outside body of the constructor (you could see examples at www.gotw.ca site), but Visual C++ doesn't support that, at least in version 6. Even if you could use try/catch outside of the c'tor body, your only option would be translating caught exception to some other type.
For more info on exceptions, I'd recommend reading "Exceptional C++" by Herb Sutter.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
As someone else answer, you do not need to detect exception from inside of your constructor as exception will propagate to the caller.
And in client code, you should add try/catch only if you want to handle the exception (or do some cleanup before throwing it again). Generally, at some point, you may want to catch the exception and display something to the user and then either continue or quit from there...
Also as someone point out, there are good books if you want to learn more.
Philippe Mori
|
|
|
|
|
This is what we do because destructors are not called if an exception occurs in the constructor. We put try/catch blocks in constructors but also do cleanup of allocated memory if it fails. This is a good process for making sure you cleanup what was allocated before the failure occurred.
MyObject::MyObject()
{
// first set all ptrs to null.
m_pBlackCat = NULL;
m_pWhiteCat = NULL;
m_pDog = NULL;
// then allocate the memory or whatever process you're going to try to
// catch exception on
try
{
m_pBlackCat = new BlackCat();
m_pWhiteCat = new WhiteCat();
m_pDog = new Dog();
}
catch(...) // or catch CMemoryException& ce
{
CleanUp();
throw;
}
}
MyObject::~MyObject()
{
CleanUp();
}
MyObject::CleanUp();
{
// It's okay to delete, even if ptr is equal to NULL.
delete m_pBlackCat;
delete m_pWhiteCat;
delete m_Dog;
}
|
|
|
|
|
But if I do
try
{
m_pBlackCat = new MyObject;
}
(which is what I need to do as I am creating an object of type MyObject) I get a recursive loop (the constructor trying to call itself).
I cannot use try/catch in the .cpp file as the object goes out of scope like so
void DevModeDlg::OnButtonPrinter()
{
try
{
AddPrinterDialog Printerbox( this );
}
catch( CMemoryException &ce )
{
MessageBox( "Error", "Error", MB_OK );
}
Printerbox.DoModal();
}
Obseve everything, remember more...
|
|
|
|
|
// Default constructor
AddPrinterDialog::AddPrinterDialog()
{
mAddPrinterDialogPointer = NULL;
mPointerToParent = NULL;
/* If this pointer has failed to be assigned as specified then
construction has failed (object cannot, and therefore never
has, existed.
*/
if ( mAddPrinterDialogPointer != NULL )
{
throw int(100);
}
}
// The function where we try the constructor code.
void DevModeDlg::OnButtonPrinter()
{
try
{
DoOnButtonPrinterWork(); // Sneaky!
}
catch ( int ThrownInt )
{
MessageBox
(
"Error constructing object Printerbox of class AddPrinterDialog.",
"Error",
MB_OK
);
}
}
// Call the constructor from here. The object is in scope (if it was
// created ok) to be able to call DoModal(). Otherwise it breaks out
// and is caught be the catch all block in OnButtonPrinter.
void DevModeDlg::DoOnButtonPrinterWork()
{
AddPrinterDialog Printerbox( this );
Printerbox.DoModal();
}
Thank you to all who helped out!
Daniel
Obseve everything, remember more...
|
|
|
|
|
Dear All,
i want to develop a notepad as comes with MS windows.
it should support unicode like in notepad.
plz help me and guide me if there is code example
plz reffer me.
omar lodhi
|
|
|
|
|
There is a sample of WordPad that come with VC and should also be able to have most of Notepad or Wordpad functionality by generating an application with the Wizard. Simply select the appropriates options.
Philippe Mori
|
|
|
|