Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Zorak
Nov 7, 2005
So I need to take a C/C++ "quiz" as part of a job hiring process. While I've taken courses in it and have worked with it, I've been using predominantly IDL and Python as of late, which aren't really the same. I'm worried that I am going to be rusty!

Are there any good "review" resources for covering general concepts again? I've got my old text books, but I need less first-time stuff and more "remember this?"

Adbot
ADBOT LOVES YOU

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

GrumpyDoctor posted:

What kinds of things can I expect
code:
try {
    // some calls to poorly-documented, exception-throwing libraries
}
catch (...) {
    // blah blah
}
to not catch?

On Itanium-ABI platforms, it should catch everything, even "foreign" exceptions (i.e. exceptions not thrown by C++ code). It does not, however, prevent setjmp/longjmp pairs from skipping over you. Also, note that the unwinder has heuristics for when it's reached the top of the stack that can sometimes inappropriately trigger if you try to unwind through a function that doesn't have unwind information.

On Windows, it should catch anything thrown by C++, but I think it doesn't actually catch native SEH exceptions. Could be wrong, though.

Sephiroth_IRA
Mar 31, 2010
I'm setting up another computer in my 2nd office exclusively for studies/programming. I've noticed that a lot of the resources I'm using suggest using Linux or Unix as a development platform and I think now would be a great opportunity to use something besides Windows.

The problem is that my spare computer is a refurbished Gateway E3600 (P4, 512MB Ram, AGP, CDROM, 20GB HD). I know I could probably dual boot from my other comp but the idea is to separate the computers I use for entertainment for study.

So I need a distribution that is light on resources and some direction on how I can set it up as a development platform. Just pointing me to a well known eguide would be sweet.

(or I could build a new PC....)

Sephiroth_IRA fucked around with this message at 21:46 on Aug 30, 2011

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

rjmccall posted:

On Windows, it should catch anything thrown by C++, but I think it doesn't actually catch native SEH exceptions. Could be wrong, though.
With msvc, catch(...) will grab SEHs with the /EHa flag. (Source)

raminasi
Jan 25, 2005

a last drink with no ice

Mustach posted:

With msvc, catch(...) will grab SEHs with the /EHa flag. (Source)

I figured out the problem anyway, but this looks like what I needed. Thanks!

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
/EHa has potentially nontrivial performance implications and makes it possible to cause hilarity by accidentally swallowing access violation, so if it's practical to do so it's usually better to use __try/__except.

raminasi
Jan 25, 2005

a last drink with no ice
I was only going to be using it for finding specific problems like this, but __try/__except is another thing I didn't know about that looks better.

TasteMyHouse
Dec 21, 2006
Ran into this in some bare-metal code at work (names obfuscated)

code:

void WriteAThingToARegister(RegisterHandle bank, uint32_t offset, uint32_t dat)
{
	/* some assertion code went here */

	*((volatile uint32_t *)(bank->BaseAddress+offset)) = dat;
}
1. This kind of lvalue cast is not legal C, is it? or is it okay because the cast happens before the pointer dereference?
2. what is the point of including "volatile" in the cast?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

TasteMyHouse posted:

1. This kind of lvalue cast is not legal C, is it? or is it okay because the cast happens before the pointer dereference?

It's okay because the cast happens before the pointer dereference. That makes this not an "lvalue cast": it's just a normal cast of an r-value, and it happens to occur during the computation of something that will ultimately be used as an l-value.

TasteMyHouse posted:

2. what is the point of including "volatile" in the cast?

Hard to say without knowing the context. Accessing a volatile object in C/C++ means that the compiler is supposed to do exactly the operation requested at exactly that point in the execution sequence. It's mostly useful with memory-mapped I/O where loads and stores actually have arbitrary side-effects.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Assuming BaseAddress isn't a char/void* (or uint32_t* I guess but then the cast is pointless) that's an aliasing violation. volatile happens to disable the sort of optimizations that make aliasing violations a problem but it's still undefined behavior.

TasteMyHouse
Dec 21, 2006

Plorkyeran posted:

Assuming BaseAddress isn't a char/void* (or uint32_t* I guess but then the cast is pointless) that's an aliasing violation. volatile happens to disable the sort of optimizations that make aliasing violations a problem but it's still undefined behavior.

BaseAddress is declared as a uintptr_t. I should also say that this function is one of 3 otherwise identical functions -- the other ones cast it to volatile uint16_t * and volatile uint8_t *

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I'll grant that I have an older computer, but I feel like with Eclipse CDT that my project is taking too long to compile. When I'm making, say, a 10 line update I am hoping I can have the compiler turn around on that code very rapidly so I can tell if I'm screwing it up or not. Instead I build the project, which leads me to distractions and loss of concentration. Is there anything Eclipse has to make that a bit quicker?

TasteMyHouse
Dec 21, 2006

Rocko Bonaparte posted:

I'll grant that I have an older computer, but I feel like with Eclipse CDT that my project is taking too long to compile. When I'm making, say, a 10 line update I am hoping I can have the compiler turn around on that code very rapidly so I can tell if I'm screwing it up or not. Instead I build the project, which leads me to distractions and loss of concentration. Is there anything Eclipse has to make that a bit quicker?

Depending on what is slowing down the build, precompiled headers may help.

note that this actually doesn't have anything to do with Eclipse itself, but is a feature of GCC

Gerblyn
Apr 4, 2007

"TO BATTLE!"
Fun Shoe

Rocko Bonaparte posted:

I'll grant that I have an older computer, but I feel like with Eclipse CDT that my project is taking too long to compile. When I'm making, say, a 10 line update I am hoping I can have the compiler turn around on that code very rapidly so I can tell if I'm screwing it up or not. Instead I build the project, which leads me to distractions and loss of concentration. Is there anything Eclipse has to make that a bit quicker?

It depends on what you're changing in your code; if you're modifying header files that are used by lots of other files then long compile times are unavoidable, unless you have a way of isolating that header file somehow so that the system doesn't need to recompile all the things that depend on it.

One thing you can do is make a number of testbed projects, with each one containing a subset of your code base. For example, if you have a set of file reading classes, you could make a project that contains just those classes and what they depend on them, but nothing that depends on them. Then, when you change those classes, you can test compile in that project to make sure there are no errors before going back to recompile the main project.

Another option is to split parts of your code off into statically linked libraries, with each library containing the code for a particular subsystem. Then, when you're working on a subsystem, you can recompile the library for it separately.

The latter option is definitely preferable, but might be a hell of a lot more work to sort out compared to the former one.

Edit: Also, quick semantic question since I just really confused myself writing this. If I say "A and it's dependencies", does that mean "A and the things A depends on" or "A and the things that depend on A"?

Gerblyn fucked around with this message at 11:14 on Sep 1, 2011

TasteMyHouse
Dec 21, 2006

Gerblyn posted:

Also, quick semantic question since I just really confused myself writing this. If I say "A and it's dependencies", does that mean "A and the things A depends on" or "A and the things that depend on A"?

If I heard you say that I would think you meant the former.

nielsm
Jun 1, 2009



Zorak posted:

So I need to take a C/C++ "quiz" as part of a job hiring process. While I've taken courses in it and have worked with it, I've been using predominantly IDL and Python as of late, which aren't really the same. I'm worried that I am going to be rusty!

Are there any good "review" resources for covering general concepts again? I've got my old text books, but I need less first-time stuff and more "remember this?"

It's not a review resource per se, but looking over the C++ FAQ lite might help.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Gerblyn posted:

Edit: Also, quick semantic question since I just really confused myself writing this. If I say "A and it's dependencies", does that mean "A and the things A depends on" or "A and the things that depend on A"?
I think it could go either way and I'd probably just judge from context, but Visual C++ certainly appears to think "dependencies" means "things it depends on", since GameX's project dependencies are LibraryY and LibraryZ.

bcrules82
Mar 27, 2003

rjmccall posted:

Hard to say without knowing the context. Accessing a volatile object in C/C++ means that the compiler is supposed to do exactly the operation requested at exactly that point in the execution sequence. It's mostly useful with memory-mapped I/O where loads and stores actually have arbitrary side-effects.

I've used this at work before.
The volatile is required for accessing CSRs (Control & Status Registers) and MMIO (like he said above) so that you don't operate on cached values.

TasteMyHouse
Dec 21, 2006

bcrules82 posted:

I've used this at work before.
The volatile is required for accessing CSRs (Control & Status Registers) and MMIO (like he said above) so that you don't operate on cached values.

What's messing with me is that wouldn't you want to label the actual variable itself as volatile, and not the thing you're casting it to?

bcrules82
Mar 27, 2003

TasteMyHouse posted:

What's messing with me is that wouldn't you want to label the actual variable itself as volatile, and not the thing you're casting it to?

code:
bank->BaseAddress+offset
Contains an integer representing the memory location you wish to write.
It may or may not be a volatile unit32_t*, so if you want to guarantee a 32-bit store to that location, that is how you do it.

yes, you could do something like:
code:
volatile uint32_t* hwAddr = 0x4000; // Your address
*hwAddr = 0xfeedface; // Your 32bit data

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
"Dependencies" = stuff I depend on, "Dependents" = stuff that depends on me.

The latter isn't used all that often because you usually don't know what third-party stuff other developers have created that depends on something you've written, while the set of your dependencies is pretty static.

For example, using your package manager to install gcc + dependencies will install libc etc., but won't install gnuprolog and anything else that in turn depends on gcc. Because that would be a silly operation to want to perform.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Jabor posted:

"Dependencies" = stuff I depend on, "Dependents" = stuff that depends on me.

The latter isn't used all that often because [...]
The thing that was being talked about that raised the question is one that would use "dependents" though - "when you change a header file, all of its dependents must be recompiled."

nop
Mar 31, 2010

Zorak posted:

So I need to take a C/C++ "quiz" as part of a job hiring process. While I've taken courses in it and have worked with it, I've been using predominantly IDL and Python as of late, which aren't really the same. I'm worried that I am going to be rusty!

Are there any good "review" resources for covering general concepts again? I've got my old text books, but I need less first-time stuff and more "remember this?"

A lot of these questions came up in my interview. Anything I didn't know I looked up, and for the most part could pass myself off as knowledgeable.

Inheritance, virtual tables and recursion are most likely to come up.

Paniolo
Oct 9, 2007

Heads will roll.

Zorak posted:

So I need to take a C/C++ "quiz" as part of a job hiring process. While I've taken courses in it and have worked with it, I've been using predominantly IDL and Python as of late, which aren't really the same. I'm worried that I am going to be rusty!

Are there any good "review" resources for covering general concepts again? I've got my old text books, but I need less first-time stuff and more "remember this?"

I don't know what level of experience they're looking for, but if they're looking for an intermediate-level knowledge of C++, I would say:

  • Know what RAII is, and be able to describe a couple of common smart pointer implementations.
  • Know the underlying implementations and general performance characteristics of a STL list, map, and vector.
  • Know why a destructor would be declared virtual and what can happen if it isn't.
  • Know the difference between dynamic_cast, static_cast, and reinterpret_cast.
  • Know the difference between static, heap, and stack storage and what kinds of data gets stored in each.
  • Know how to throw and catch exceptions properly, what stack unwinding is, and be able to describe some of the advantages and disadvantages of exceptions. Also, be able to talk about basic exception safety issues, and explain what can happen if you throw in a destructor.
  • Know what threads are, be able to describe at least a couple of synchronization mechanisms, be able to give at least a couple of simple examples of thread safety issues, and be able to describe at least one simple concurrent algorithm.
  • Know how to use a debugger and be able to describe how you might use one to investigate a bug.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Am I correct in assuming that the lifespan of a value used in an expression is the statement and that destructors will never be called until every operation in the statement happens? Or is there something else that determines destruction time for that?

Also, considering that some compilers pad up the size of empty structures, is it guaranteed that a class that extends an empty structure will NOT padded at the start? MSVC clearly doesn't, but I'm not sure if it's standardized or not.

OneEightHundred fucked around with this message at 17:35 on Sep 3, 2011

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

OneEightHundred posted:

Am I correct in assuming that the lifespan of a value used in an expression is the statement and that destructors will never be called until every operation in the statement happens? Or is there something else that determines destruction time for that?

Temporaries created during the evaluation of an expression are destroyed in reverse order at the end of the evaluation of that full-expression, where things like if conditions are their own full-expression.

The one exception is when an expression is used as the initializer of a reference variable or (in a constructor) member variable; in this case, if the reference is bound to a temporary, that temporary lives as long as the variable or constructor call.

OneEightHundred posted:

Also, considering that some compilers pad up the size of empty structures, is it guaranteed that a class that extends an empty structure will NOT padded at the start? MSVC clearly doesn't, but I'm not sure if it's standardized or not.

The standard doesn't make any promises. Both MSVC and the Itanium ABI (i.e. most other compilers) try pretty hard to avoid adding unnecessary padding for empty subobjects. MSVC actually tries *too* hard, i.e., it has bugs and sometimes allocates different subobjects of the same empty type at the same address.

Super Dude
Jan 23, 2005
Do the Jew
I'm writing some regular expression code in flex, and I'm having a problem. I am trying to detect if there are non-printable characters inbetween a set of < >. For some reason, I can't figure out why my current solution is not working.

code:
\<[^>[:print:]]*[^[:print:]][^>]*\>
For instance, my input is: <tag is ^L not valid>

Any ideas?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
So what you're attempting to match is:

1. An open-<
2. Any characters as long as they aren't >
3. A non-printable character
4. Some more any-characters-that-aren't >
5. A close->

The regex you've got (with some liberties taken for whitespace):

code:
\<
[^>[:print:]]*
[^[:print:]]
[^>]*
\>
Hopefully this helps make stuff more apparent.

Super Dude
Jan 23, 2005
Do the Jew

Jabor posted:

So what you're attempting to match is:

1. An open-<
2. Any characters as long as they aren't >
3. A non-printable character
4. Some more any-characters-that-aren't >
5. A close->

The regex you've got (with some liberties taken for whitespace):

code:
\<
[^>[:print:]]*
[^[:print:]]
[^>]*
\>
Hopefully this helps make stuff more apparent.

I guess I'm not seeing what I'm missing because from what I see, my regex matches the description.

Gerblyn
Apr 4, 2007

"TO BATTLE!"
Fun Shoe
I hate regular expressions, a friend of mine once told me "So, you have a problem, and you decide to use regular expressions to fix it. Now, you have two problems."

Anyways, are you sure you should be having the :print: in the first character set? It looks to me like the first character set is saying "Any character, except > or a printable character, repeated 0 or more times".

Secondly, even if your rexexp worked, it would only find cases where a tag contained one non-printable character, if there were more than one, it would ignore it. I'm afraid I'm nowhere near good enough with these things to know how to fix it though.

nielsm
Jun 1, 2009



Gerblyn posted:

I hate regular expressions, a friend of mine once told me "So, you have a problem, and you decide to use regular expressions to fix it. Now, you have two problems."
This.


If your problem really isn't any more complex, i.e. there are no more elements to your parser, then go write it by hand as a state machine, similar to what flex would output.

State 0: Default state, between tags. If '<' is encountered, switch to state 1 and take note of where the '<' was encountered. If '&' encountered take note of the position and switch to state 3. If EOF, end processing.

State 1: Inside tag. If '>' encountered, you have matched a valid tag and can use the current position along with the tag start position noted in state 0 to process the valid tag, then switch to state 0. If a non-printable is encountered, switch to state 2. If EOF, your file smells broken.

State 2: Inside invalid tag. If '>' encountered, process your invalid tag then switch to state 0.

State 3: Possibly an entity. For every character read, check the entire entity name read against your list of valid entity names, if what you have read is not a prefix of a valid one switch to state 0. If you match an entity name exactly, process it.
(In reality this handling makes state 3 a sub-tree of a much more complex state machine. You can expand it in full if you like, switching state for every character read.)


Of course, maybe you're required to use flex for some reason. In that case, good luck :thumbsup:

DeciusMagnus
Mar 16, 2004

Seven times five
They were livin' creatures
Watch 'em come to life
Right before your eyes

Super Dude posted:

I'm writing some regular expression code in flex, and I'm having a problem. I am trying to detect if there are non-printable characters inbetween a set of < >. For some reason, I can't figure out why my current solution is not working.

code:
\<[^>[:print:]]*[^[:print:]][^>]*\>
For instance, my input is: <tag is ^L not valid>

Any ideas?

If you want to detect whether some non-printable characters are between < > you should just use \<[^[:print:]]*\>. Your regular expression doesn't do that, instead it is also trying to filter out strings like <>>^M>>^Z>> and <abc>>>>>.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

DeciusMagnus posted:

If you want to detect whether some non-printable characters are between < > you should just use \<[^[:print:]]*\>.
The problem with that is that you would match on
<valid stuff in a tag> ^M Not printable stuff outside a tag <valid stuff in a tag>

The problem the original regexp has is in the second part of the regexp (thanks Jabor for breaking it into parts) - you have it matching NOT(> or printables), but you want it matching NOT(>) or printables. (ie. you have it matching NOT printables, but you want it to match printables.)

I think in some regexp formats you could do that step like:
(?:[^>]|[:print:])*

But I don't know if flex will do that or not.

Edit: Actually, you don't really need to do that anyway, just [^>]* would be fine - it doesn't matter if you accidentally match a non-printable character during that section because it will still have to match a non-printable afterwards in the third part. If you did it my complicated way your third part would match the first non-printable character, but if you do it the simpler way the third part would just match the last non-printable character in the tag.

Edit2: Also you could have it match the first non-printable more simply with [^>]*? assuming the specific regexp parser supports that "match shortest" semantic.

roomforthetuna fucked around with this message at 17:40 on Sep 5, 2011

Super Dude
Jan 23, 2005
Do the Jew

roomforthetuna posted:

Edit2: Also you could have it match the first non-printable more simply with [^>]*? assuming the specific regexp parser supports that "match shortest" semantic.

Unfortunately ? isn't supported (flex is stupid).

\<([[:print:]]{-}[>\n<])*[^[:print:]][^>]*\>

I think this fixed the problem. It looks horrible and is impossible to read, which really pisses me off.

Super Dude fucked around with this message at 18:52 on Sep 5, 2011

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Super Dude posted:

Unfortunately ? isn't supported (flex is stupid).
Did you need it to match the first non-printable character then, not just detect that there is one? (My first edit didn't require ? support)

Which is to say, I think
\<[^>]*[^[:print:]][^>]*\>
would work if all you need to do is detect that there is a non-printable in a tag.

pseudorandom name
May 6, 2007

nielsm posted:

This.


If your problem really isn't any more complex, i.e. there are no more elements to your parser, then go write it by hand as a state machine, similar to what flex would output.

State 0: Default state, between tags. If '<' is encountered, switch to state 1 and take note of where the '<' was encountered. If '&' encountered take note of the position and switch to state 3. If EOF, end processing.

State 1: Inside tag. If '>' encountered, you have matched a valid tag and can use the current position along with the tag start position noted in state 0 to process the valid tag, then switch to state 0. If a non-printable is encountered, switch to state 2. If EOF, your file smells broken.

State 2: Inside invalid tag. If '>' encountered, process your invalid tag then switch to state 0.

State 3: Possibly an entity. For every character read, check the entire entity name read against your list of valid entity names, if what you have read is not a prefix of a valid one switch to state 0. If you match an entity name exactly, process it.
(In reality this handling makes state 3 a sub-tree of a much more complex state machine. You can expand it in full if you like, switching state for every character read.)


Of course, maybe you're required to use flex for some reason. In that case, good luck :thumbsup:

flex supports conditional rules.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I have a situation with RTTI that I'm trying to figure out if I can do the way I want. That being said I am pretty sure I can work around the issue if I must. Imagine I have list of pointers to a bunch of stuff of class "Fundamental." So we have stuff like:

class A : public Fundamental
class B : public Fundamental

Let's throw in an interface for giggles: class IStuff.

So let's add on:
class C : public IStuff, public Fundamental
class D : public IStuff, public Fundamental

I have a list of Fundamentals, and my informal policy is I only put one of any particular subclass in. I don't know if that matters, but it's what I'm doing. Now I want to iterate the list and find, say, class A dynamically. This is easy enough with type_info checking. However, let's say I put in class C, and I want to see if anything in the list is an IStuff*. At compile time I can do this with dynamic_cast, but I'm lost about runtime. Any ideas?

Oh yes the other way I was thinking I might get this to work is if I can add the IStuff to the list more explicitly, but I have to try it. In my particular situation IStuff is mostly-related to stuff that also implements Fundamental, so I could make IStuff subclass that, then have C and D subclass as usual. So that way I can pass an object of C to the list, but simultaneously cast it as an IStuff. So when I iterate and do type checks, I am hoping there it'll see the IStuff. Now then if I wanted to see if it had something of type C, I'm screwed. It's a game of whack-a-mole... :(

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Rocko Bonaparte posted:

At compile time I can do this with dynamic_cast, but I'm lost about runtime.

The entire point of dynamic_cast is that it checks at runtime.

nielsm
Jun 1, 2009



Plorkyeran posted:

The entire point of dynamic_cast is that it checks at runtime.

To elaborate, dynamic_cast<B*>(a) returns a B pointer if a has a dynamic type compatible with B, and returns 0/nullptr if a does not have a dynamic type compatible with B.

Adbot
ADBOT LOVES YOU

Brecht
Nov 7, 2009

Rocko Bonaparte posted:

However, let's say I put in class C, and I want to see if anything in the list is an IStuff*. At compile time I can do this with dynamic_cast, but I'm lost about runtime. Any ideas?
This:
code:
#include <iostream>
#include <vector>

class Fundamental { public: virtual ~Fundamental() { } };
class A : public Fundamental { public: virtual ~A() { } };
class B : public Fundamental { public: virtual ~B() { } };
class IStuff { public: virtual ~IStuff() { } };
class C : public IStuff, public Fundamental { public: virtual ~C() { } };
class D : public IStuff, public Fundamental { public: virtual ~D() { } };

int main()
{
	std::vector<Fundamental *> v;
	v.push_back(new A());
	v.push_back(new B());
	v.push_back(new C());
	v.push_back(new D());
	for (size_t i = 0; i < v.size(); ++i) {
		Fundamental *f(v.at(i));
		if (dynamic_cast<A *>(f)) { std::cout << i << ": A" << std::endl; }
		if (dynamic_cast<B *>(f)) { std::cout << i << ": B" << std::endl; }
		if (dynamic_cast<C *>(f)) { std::cout << i << ": C" << std::endl; }
		if (dynamic_cast<D *>(f)) { std::cout << i << ": D" << std::endl; }
		if (dynamic_cast<IStuff *>(f)) { std::cout << i << ": IStuff" << std::endl; }
	}
	return 0;
}
produces the output
code:
0: A
1: B
2: C
2: IStuff
3: D
3: IStuff
which seems to satisfy your requirements. Or do you mean something else by "run-time"?

But, frankly, I don't know why this compiles. My understanding of dynamic_cast is that it works up and down the inheritance hierarchy, but not sideways. Is that wrong? Is it really able to do arbitrary casting regardless of inheritance ancestry?

edit: enshorten code

Brecht fucked around with this message at 20:53 on Sep 5, 2011

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply