C# rots your C++ brain part 2
-
Jörgen Sigvardsson wrote:
throw MyException();
does this compile at all? I would expect
new
in there. :)Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
sure. you can technically use either heap or stack based allocation, the difference being that the heap based approach requires you to clean up manually, and is a big potential for mem leaks. pretty much everyone uses the stack based approach.
¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! VCF Blog
-
sure. you can technically use either heap or stack based allocation, the difference being that the heap based approach requires you to clean up manually, and is a big potential for mem leaks. pretty much everyone uses the stack based approach.
¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! VCF Blog
I see. C# would not allow that. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
This works:
class MyException : public std::exception {
I had to write it down to see it. :D
That's the trick. In hindsight, the compiler is absolutely right. I would like C++ compiler writers to issue a warning whenever private inheritance is used and the class itself is used for exceptions.
-- Kein Mitleid Für Die Mehrheit
-
class MyException : std::exception {
...
}try {
throw MyException();
} catch(std::exception& ex) {
}The exception is not going to be caught. Can you figure out why?
no idea. c# rotted my c++ brain too. not that i was really good at c++ though. i think that you can't do this in c++, but you can in c#?
-
class MyException : std::exception {
...
}try {
throw MyException();
} catch(std::exception& ex) {
}The exception is not going to be caught. Can you figure out why?
:sigh: I think I need to take 2 weeks off and go back to straight C++.
cheers, Chris Maunder
CodeProject.com : C++ MVP
-
no idea. c# rotted my c++ brain too. not that i was really good at c++ though. i think that you can't do this in c++, but you can in c#?
No, you can't make this mistake in C#, because you cannot specify whether the inheritance should be private or not. Inheritance is always public in C#.
-
:sigh: I think I need to take 2 weeks off and go back to straight C++.
cheers, Chris Maunder
CodeProject.com : C++ MVP
If parsing C++ wasn't so damn hard, I'd write a tool to find these things for me. During the build process at 2 am, the build server would send me an SMS for each find. Do you know if Lint can find these kinds of things? :~
-
If parsing C++ wasn't so damn hard, I'd write a tool to find these things for me. During the build process at 2 am, the build server would send me an SMS for each find. Do you know if Lint can find these kinds of things? :~
-
class MyException : std::exception {
...
}try {
throw MyException();
} catch(std::exception& ex) {
}The exception is not going to be caught. Can you figure out why?
-
C# rots your C++ brain
C# rots your C++ brain
imagine what it does to non c++ brains (example: "The other day I saw the tooth fairy sodomizing easter bunny using a Dispose Pattern, SIDEWAYS!" :omg: ) ;)
led mike
-
Yes. You definitely need less C#. :)
----
You're right. These facts that you've laid out totally contradict the wild ramblings that I pulled off the back of cornflakes packets.
Shog9 wrote:
You definitely need less C#
I'm trying. I have started working with our C code base last year. It's a nightmare of course, unstructured, retarded spaghetti code. Unfortunately I still double duty in the wonderful new .NET world of our shop as well. I can't help but laughcry whenever I think about the dispose pattern. Here, we give you ( developers that can't deal with memory management "pointers" ) this magical world of garbage collection to eliminate the burden of understanding how computers work. This new magical world provides more native access than Java and so make sure to take a look at the, *gulp* simple eh yeah eh simple Dispose Pattern to ensure you are allocating and releasing native resources correctly. LMAO! Sure, they can't deal with pointers but they'll get this Dispose Pattern no problem! ROTF! :laugh::laugh::laugh:
led mike
-
That's the trick. In hindsight, the compiler is absolutely right. I would like C++ compiler writers to issue a warning whenever private inheritance is used and the class itself is used for exceptions.
-- Kein Mitleid Für Die Mehrheit
Frankly, I don't see the point of private inheritance. I see it more like a <<uses>> than an <<is>>.
-
Frankly, I don't see the point of private inheritance. I see it more like a <<uses>> than an <<is>>.
That is exactly the purpose it is intended to serve. It's there to save some extra typing for programmers. Instead of aggregating another object as a member variable, it's merged together with the "this" object. I think the language should've required the use of a visibility modifier. That way it wouldn't have been such a potential source of errors.
-
This works:
class MyException : public std::exception {
I had to write it down to see it. :D
Ah yes, I didn't spot that! It's the kind of nasty trick they would pull on you at interview. :) I haven't done any C++ for about 4 years now.
Kevin
-
class MyException : std::exception {
...
}try {
throw MyException();
} catch(std::exception& ex) {
}The exception is not going to be caught. Can you figure out why?
it's not functionally useful to adorn c++ inheritance with the
private
modifier (or no modifier at all). just keep all inheritance
public
(and don't forget it). i couldn't spot the error as it would never have happened to me coz of the above rule.
Love is the illusion that one
kiss
is different from another. - e.m -
Frankly, I don't see the point of private inheritance. I see it more like a <<uses>> than an <<is>>.
-
class MyException : std::exception {
...
}try {
throw MyException();
} catch(std::exception& ex) {
}The exception is not going to be caught. Can you figure out why?
I admit I didn't spot the missing public modifier, but I noticed something else that I wasn't sure of:
throw MyException**()**;
In C++, you don't use parenthesis when instanciating an object with the default constructor (ie,throw MyException;
). I'm trying to remember if using parenthesis in this case would trigger an unintended call to the copy constructor. Do you know?ShamWow
-
I admit I didn't spot the missing public modifier, but I noticed something else that I wasn't sure of:
throw MyException**()**;
In C++, you don't use parenthesis when instanciating an object with the default constructor (ie,throw MyException;
). I'm trying to remember if using parenthesis in this case would trigger an unintended call to the copy constructor. Do you know?ShamWow
It does not matter if you use the parenthesis or not, the default constructor is called anyway. I tend to use parenthesis (how the hell do you pluralize that word? :)), because it makes the syntax more uniform. There are some odd scenarios though, where the parenthesis can fool the compiler into believing that you're declaring a function prototype. Can't remember exactly how to provoke it though...
-- Kein Mitleid Für Die Mehrheit