Implement Person interface, Moe/Larry/Curley classes, and random gree…#2
Open
jasonstratton wants to merge 1 commit intomasterfrom
Open
Implement Person interface, Moe/Larry/Curley classes, and random gree…#2jasonstratton wants to merge 1 commit intomasterfrom
jasonstratton wants to merge 1 commit intomasterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
Implements a new Person interface with three concrete classes and replaces the "Hello, World!" example with randomized greetings.
- Introduces
Personas an abstract base and concreteMoe,Larry,Curleyclasses - Adds a
printHellohelper and random selection of person instances - Replaces simple output with a loop over randomly generated people
Comments suppressed due to low confidence (1)
main.cpp:24
- [nitpick] Verify the spelling of
Curley—if this refers to the Three Stooges character, the common spelling isCurly.
class Curley : public Person {
| std::uniform_int_distribution<> dist(1, 10); // random number of persons | ||
| int numPersons = dist(gen); | ||
|
|
||
| std::vector<std::unique_ptr<Person>> people; |
There was a problem hiding this comment.
Consider calling people.reserve(numPersons); after creating the vector to avoid repeated reallocations when pushing back numPersons elements.
Suggested change
| std::vector<std::unique_ptr<Person>> people; | |
| std::vector<std::unique_ptr<Person>> people; | |
| people.reserve(numPersons); // Preallocate memory for numPersons elements |
| // Seed random number generator | ||
| std::random_device rd; | ||
| std::mt19937 gen(rd()); | ||
| std::uniform_int_distribution<> dist(1, 10); // random number of persons |
There was a problem hiding this comment.
Extract the 1 and 10 bounds into named constants (e.g. kMinPersons, kMaxPersons) for clarity and easier updates.
Suggested change
| std::uniform_int_distribution<> dist(1, 10); // random number of persons | |
| std::uniform_int_distribution<> dist(kMinPersons, kMaxPersons); // random number of persons |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…tings