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.
 
  • Locked thread
hobbesmaster
Jan 28, 2008

MrMoo posted:

A single question ok, but laboring the point in every permutation of usage is just too much. Having coding standards and following them is more acceptable than C++ rule lawyering that some developers love a bit too much. Using delete this; in a constructor is valid apparently but that does not make it not stupid.

You can use it anywhere technically, https://isocpp.org/wiki/faq/freestore-mgmt#delete-this
I'm not sure its ever a good idea though?

quote:

The interviewer was trying to replace class with struct and ask me where it would break.

Then thats #define class struct
And it should always work.

Adbot
ADBOT LOVES YOU

hobbesmaster
Jan 28, 2008

Plorkyeran posted:

It's UB if you include any standard library headers afterwards, and members of classes are allowed to have different name mangling from members of structs. The compiler could also decide to lay out the sections differently.

Yes, I meant in your own code compiling your own classes. This is why I screw up interviews!

Why can't C++ questions be more like Hashmap vs Hashtable

hobbesmaster
Jan 28, 2008

MrMoo posted:

The interviewer was looking for something in templates, e.g.
C++ code:
template <class T> // template argument
void qux() {
    T t;
}
Although I guess one should be able to template a struct there is probably some conditional operator that breaks.

Maybe something like nested templates:
C++ code:
template <template <typename> class Store, typename T>
struct CachedStore2 {
  Store<T> store;
  Cache<T> cache;
};

A struct is a class. Full stop.

Take a look at the C++14 standard starting on page 226. You may be surprised at the keywords they use when describing class declarations.

hobbesmaster
Jan 28, 2008

Unions are also classes if we're talking about C++ trivia.

I have no idea why.

hobbesmaster
Jan 28, 2008

In C++? A surprising amount!

Adbot
ADBOT LOVES YOU

hobbesmaster
Jan 28, 2008

MrMoo posted:

I was asked but then followed up with this more trivia type questions, it was really a bit tenuous. They still want to interview me which suggests there are not a lot of C++ people really looking for jobs.

There also aren't all that many C++ jobs out there.

  • Locked thread