Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
2 votes
3 answers
322 views

C++ has a lovely feature where the compiler will prevent you from forgetting to implement a pure virtual method in a subclass. But what if I want to require a user of my abstract base class to ...
15 votes
1 answer
385 views

Consider the following snippet: int main() { struct Local { virtual void foo() = 0; }; void (Local::* ptr)() = &Local::foo; } When compiling with C++20, GCC 13.3.0 and Clang 18.1.3 ...
0 votes
1 answer
150 views

(By an "impure virtual function", I mean pure virtual functions that also have implementations (as described at http://www.gotw.ca/gotw/031.htm).) Consider the following code: #include <...
jamesdlin's user avatar
  • 91.2k
0 votes
1 answer
118 views

Regarding the following code, I would avoid copy paste so much code, or implement the interface class IHardware: #include <iostream> #include <string> class IHardware { public: virtual ~...
0 votes
0 answers
43 views

I am making a game engine in C++ and want to start implementing unit tests. As far as I'm aware, you can only create mocks of pure virtual functions. However, because I do not want to add needless ...
-1 votes
1 answer
71 views

I have a homework assignment, and a small part of that assignment asks for a abstract parent "Movie" class with three concrete subclasses: "Comedy," "Drama," and "Classical." Each subclass will never ...
-1 votes
2 answers
207 views

#include <iostream> using namespace std; class Abstract { protected: int* arr; int size; public: Abstract(int s = 10) { size = s; arr = new int[size]; } ...
1 vote
2 answers
118 views

I am working on a project in which I have a base class called MSTAlgorithm (Minimum Spanning Tree Algorithm). Two classes called PrimsAlgorithm and KruskalsAlgorithm publically derive from this base ...
-2 votes
1 answer
167 views

I have a base class and derived classes. The base class uses pure virtual methods to require the derived classes to implement methods - otherwise it doesn't compile. Classic. Can I also require from ...
0 votes
1 answer
110 views

Let's say we have following interfaces // interface template <typename T> class MyInterface { public: virtual void fun1() = 0; virtual void fun2() = 0; } // just specialization, keep ...
-1 votes
1 answer
262 views

I'm trying to write an abstract struct named Shape, and I need a function in derived classes that will be counting distance from a ray origin to my shape. I use functions from here, they return float, ...
-2 votes
2 answers
376 views

I have a question regarding the declaration of pure virtual functions in C++. I come from a Java background, and so I see pure virtual functions as a way to define abstract classes and the idea of ...
1 vote
2 answers
282 views

Suppose we have the following hierarchy: class Add3Interface { virtual int add3 (const int&) const = 0; }; class Add3: public Add3Interface { virtual int add3 (const int& arg) const ...
antonio's user avatar
  • 483
4 votes
1 answer
107 views

Suppose I have the following interface: struct Person { std::string name; unsigned short age; }; class ContainerInterface { public: virtual ~ContainerInterface () = default; ...
antonio's user avatar
  • 483
1 vote
1 answer
209 views

#include <iostream> #include <algorithm> #include <vector> #include <map> class Base { public: virtual ~Base() = default; virtual void doIt() = 0; public: int base = 1; ...

15 30 50 per page
1
2 3 4 5
...
31

AltStyle によって変換されたページ (->オリジナル) /