|
hello
I've found my silly mistake
please help me find error in my code :
class Base
{
public :
virtual ~Base() {};
virtual void getX() const
{
cout<<endl<<"Inside Base : "<<m_X<<endl;
};
protected :
int m_X;
};
class Derived1 : public Base
{
public :
Derived1()
:Base()
{
m_X = 100;
};
virtual void getX() const
{
cout<<endl<<"Inside Derived1 : "<<m_X<<endl;
};
};
int _tmain(int argc, _TCHAR* argv[])
{
try
{
throw Derived1();
}
catch (Base *pError)
{
pError->getX();
}
return 0;
}
sorry for stupid question
I am pretty tired, need a good sleep
-- modified at 9:42 Monday 29th May, 2006
|
|
|
|
|
big_denny_200 wrote: virtual void getX() const {
cout<<endl<<"inside base="" :="" "<<m_x<<endl;
}<b="">;
don't close your functions definitions with semicolons (';').
at last, just curious... don't you understand what the compiler says when complaining ?!
i have no compiler to test here, so, sorry.
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-- modified at 9:45 Monday 29th May, 2006
|
|
|
|
|
no
why not use semicolons ?
thanks
-- modified at 9:34 Monday 29th May, 2006
|
|
|
|
|
big_denny_200 wrote: why not use semicolons ?
and you didn't answer my questions more.
* What are the compiler errors ?
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-- modified at 9:45 Monday 29th May, 2006
|
|
|
|
|
toxcct wrote: because the C++ doesn't want them here
In fact, this won't change anything. You can let them there. They will simply be ignored.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
Cedric have u seen my post? I think that is the reason for his assertion?
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
a function ending with ";" is simply compiling with visual studio .net and visual studio 6 C++ compiler.
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
it is not the problem with a ";"
problem is with ur try catch block;
big_denny_200 wrote: catch (Base *pError)
u r catching a pointer to the throwing object but inside the
try block u r doing
big_denny_200 wrote: throw Derived1(); // when I add this line I get assert
so inside the throw block do as follows
Derived1 d; // when I add this line I get assert
throw &d;
or
throw &Derived1(); // when I add this line I get assert
u can also resolve if u change the catch block to pass by value instead pass by reference
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
SaRath C wrote: Derived1 d; // when I add this line I get assert
throw &d;
Never do this as it’s seriously flawed. The object d is on the stack but the stack is unwound when an exception is caught. The upshot is that when you catch an exception with such code the exception handler gets a pointer to an object which no longer exists. It's the same situation as returning a reference or pointer to a local variable from a function.
Steve
|
|
|
|
|
You're throwing a Derived1 but catching a Base* . If you want to catch a Base* you need code like this:
try
{
throw new Derived1();
}
catch (Base *pError)
{
pError->getX();
delete pError;
}
A better was is not to throw a pointer. Use code like this:
try
{
throw Derived1();
}
catch (const Base &e)
{
e.getX();
}
Steve
|
|
|
|
|
Probably you have seen "winrar" to add "Add to archive" type menuitem to default right-click pop-up menu. I want to add this feature to my file conversion software. After some searching on the internet, I think I have to modify the Windows Explorer context menu. I don't know how to do it. Does anyone know how to do it?
Tamal Saha,
Student,
Bangladesh University of Engineering and Technology.
|
|
|
|
|
|
toxcct wrote: Complete Idiot Guide
Owner drawn
Jesus Loves
|
|
|
|
|
|
toxcct wrote: i didn't name it myself
Thinking about the guys who read it.
toxcct wrote: ps: nice to see you back dear... where were you for all these days ?
Thanks. My ghost was always present here.
Owner drawn
Jesus Loves
|
|
|
|
|
|
Is it really interesting to code with .net framework + C++.
I could not enter into the new world something resisting me to do that
what is ur opinion about new C++ versions and coding with .net?
SaRath
|
|
|
|
|
you'd better ask this in the C++/CLI forum or even in the lounge...
personnaly, i'm not interrested at all in coding for the .NET framework for the moment, in whatever language i could use...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
toxcct wrote: personnaly, i'm not interrested at all in coding for the .NET framework for the moment, in whatever language i could use...
Thanks for ur reply
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
toxcct wrote: you'd better ask this in the C++/CLI forum or even in the lounge...
if i post this question in C++/ CLI they will kick me off from there
why should we take a risk? there are many supporters for that but here we can get mixed opinions that's y I posted here
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
SaRath C wrote: if i post this question in C++/ CLI they will kick me off from there
only stupid guys will...
SaRath C wrote: why should we take a risk?
because i think most people on this forum don't know managed C++ ,and even if they do, it's not the topic of this board to talk about that kind of things.
and as i think this is not a programming question but more a general knowledge question, it worth it asking the lounge
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
Hi,
Before closing my application I write down the status of current working in some file.
But when the application gets closed after sudden electricity failure, how can I write down the status in a file at that time.
any Idea? / link
Regards.
|
|
|
|
|
zahid_ash wrote: But when the application gets closed after sudden electricity failure,
AFAIK there are none. WM_QUERYENDSESSION and others do help only if you are using Shut Down.
Nibu thomas
A Developer
Programming tips[^] My site[^]
|
|
|
|
|
How can you write when the system has shut down?? and Btw is this you really ask?
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[V]--
[My Current Status]
|
|
|
|
|
Mean to say that I want to write in a file( open a file and write status data in it)just before Operating system is shutting down with electricity failure
Regards.
|
|
|
|