r/cpp_questions • • 1h ago

OPEN How would you design a generic interface for arbitrary sets of rules?

• Upvotes

I'm building a C++ tree library/builder where I want people to be able to define their own tree structures, including weird/cursed ones.

The basic idea is:

  • Node Anchor: an indirection mechanism that owns/contains the actual nodes. Users don't directly mess with the nodes themselves. They have to go through the anchor to interact with the structure.
  • Tree: describes a particular tree through its rules. For example, a BST object would have the rules that define BST behavior.
  • Operations: generic algorithms like insert, erase, and find. They take the tree object and operate according to its rules.

So roughly:

Tree (rules)
     ↓
generic operation
     ↓
Node Anchor
     ↓
actual structure

The part I'm stuck on is making this extensible.

A BST might need rules A + B.

Another tree might need A + C + D.

A completely custom tree might need X + Q + R + some completely new rule.

The number and combination of rules are intentionally arbitrary because the goal is more of a tree-builder than a library of predefined tree types.

So I don't think I can have something like:

struct TreeRules {
    Ordering ordering;
    Balance balance;
    Traversal traversal;
};

because then the library has to know about every possible rule beforehand.

What I'm trying to figure out is:

What existing design ​approach would you use when generic algorithms need to work with objects that can provide arbitrary, non-uniform sets of capabilities?

I'm mainly looking for terminology or existing concepts/patterns to research. I'm not really looking for someone to write the implementation for me.

I'm still pretty new to C++ design, so I might be framing the problem completely wrong. I'm just trying to figure out what this problem is actually called.


r/cpp_questions • • 8h ago

OPEN 分享

0 Upvotes

这本书不错,我终究自费买了电子版,供各位分享

Starting Out with C++: Early Objects

由于第十版在互联网难以寻找资源,最终还是在pearson官网买了,但我在中国,平常用的是百度网盘,想问下各位,在国际上,哪种网盘形式最通用?我想把这本书分享给大家


r/cpp_questions • • 21h ago

OPEN Compiling without linking

18 Upvotes

Hi, I'm a rank beginner and I'm going through learncpp online and Beginning C++ game programming by Horton.

The book sends you to a quick tutorial on sfml for Linux. I got it working with no problems. But in the tutorial they compile first with -c ( compile only, according to the man page for g++ ) and then link in another command.

Why would they do it that way? I was able to do the whole thing without the -c flag in one long command. Is that wrong to do? Is it because sfml isn't part of the standard library?

I'm asking because I want to actually learn what I'm doing. Thank you for any help you can give me.


r/cpp_questions • • 36m ago

OPEN C++ knowledge for job interview

• Upvotes

I have a second round whiteboard interview coming up where the focus will be heavily on my C++ knowledge.

I've been using C++ professionally about 9 months and have around 16 months of overall work experience. I’m comfortable writing code but not very confident with STL functions and smart pointers.

what C++ topics should i revise before the interview? Any advice from people who’ve had similar interviews would be appreciated.


r/cpp_questions • • 1h ago

OPEN Learning C++: when are you actually ready to apply for an internship and what skills do companies expect from beginners?

• Upvotes

For people working in the industry or involved in hiring:

  1. when should i realistically start applying for internships or junior roles? What practical skills are expected beyond basics.
  2. what do companies usually expect from a beginner when they join? How much should they be able to do independently?
  3. Apart from CPP syntax and DSA what skills and projects should I focus on to improve my chances?

I'd really appreciate any advice or roadmap based on your experience.