This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hi all. I just did an interview and I'm a bit annoyed that I wasted 1/3rd of the allocated time because I was stuck on accessing an enum inside of a struct. It was a while since I used c . I don't think I can go into specifics of the problem.
Basically there was a struct, an enum inside the struct with a few states, and a function inside the struct. I was then supposed to write the functionality for the function outside of the struct. The problem is, I couldn't figure out in writing the functionality for the function on how to access the enum for a switch statement. Assuming the struct name is x, and the enum name is y, I tried switch(x::y), wasn't working, and other variations, usually " expected unqualified-id before ')' ". Maybe my whole approach was wrong, I don't know. There is NO main anywhere.
struct x{
enum states { // not a enum class
state1
state2
}
x::somefunction(bool x) // dont remember exactly how declared here or below
}
x::somefunction(bool x){
// some of my code
switch(states) // This is where I had trouble
}
What I ended up doing was adding the enum as one of the function parameters at the end because I was about to run out of time. I didn't even have time to test, just saw it compiled fine. It wasn't clear whether I could change the already given template, so not sure if that was even allowed.
So how should I accessed that enum? Thanks. Really disappointed because I probably ruined my chances.
Subreddit
Post Details
- Posted
- 3 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/cpp_questio...