private-inheritance Questions
1
Solved
I always assumed that private inheritance simply means that a type doesn't tell the outside that it's inheriting from some base class. However, it seems that there are more restrictions.
Consider t...
Jann asked 26/7, 2023 at 13:8
2
Solved
I'm having trouble using shared_ptr and weak_ptr along with enable_shared_from_this.
When I google the symptoms of what I'm seeing, everybody suggests "you cannot use shared_from_this() when there...
Insignia asked 16/7, 2019 at 19:33
1
I found very strange behavior of std::unique_ptr in Visual Studio 2013 and 2017. Let's consider an example:
class Base
{
public:
virtual ~Base() = default;
virtual void Foo() = 0;
};
class Der...
Shelbashelbi asked 20/4, 2017 at 20:9
4
Solved
I was playing around for a bit using the shared_ptr's and enable_shared_from_this, while I run into something I don't really understand.
In my first attempt I constructed something like this:
cla...
Illuminism asked 8/10, 2016 at 20:34
4
Consider the below code:
#include<iostream>
using namespace std;
class A
{
public:
A() {cout << "1";}
A(const A &obj) {cout << "2";}
};
class B: virtual A
{
public:
B() {...
Camden asked 30/4, 2017 at 5:28
5
Solved
Due to the layout of a third-party library, I have something like the following code:
struct Base
{
static void SomeStaticMethod(){}
};
struct Derived1: private Base {};
struct Derived2: public...
Kazukokb asked 6/9, 2016 at 13:16
2
The following is an attempt at implementing a shared pointer with a modified semantics of operator==:
template <typename T>
struct deref_shared_ptr: private std::shared_ptr<T> {
using...
Scibert asked 31/7, 2016 at 8:14
2
Solved
please see the following code
struct A { using type = int; };
struct B : private A {};
struct C : B { using base_type = A; };
All of gcc 6.1, clang 3.8, and msvc 2015 update 3 refuse to compile ...
Caesarea asked 4/7, 2016 at 8:13
1
Solved
I'd like to std::bind to a member function from a private base class, made "public" with a using-declaration in the derived class. Calling the function directly works, but it seems binding or using...
Bulwark asked 28/3, 2016 at 13:14
2
Solved
Could I use SFINAE (or another technique) for using declaration while private deriving from template class?
For better understanding see code below:
#include <iostream>
struct S1 {
void f(...
Brendon asked 30/1, 2015 at 9:24
3
Solved
I'm wondering why a call to a static function is ambiguous, even when one of the two is obviously impossible to call as it is private.
I was hoping I could use private / protected inheritance to he...
Laborsaving asked 28/12, 2014 at 18:56
1
Solved
Background information: This was detected on Visual Studio 2008, and confirmed again on Visual Studio 2013. G++ screamed at the code, while Visual accepted the private inheritance breach silently.
...
Footman asked 19/6, 2014 at 9:54
3
Solved
Can I do this?
class A { ... };
class B : private A
{
const A &foo() const
{
return *((const A *)this);
}
};
Can I take a subclass that inherits privately from a base class and cast it ...
Steno asked 29/7, 2013 at 13:16
2
Solved
The following code compiles using GCC 4.4.6 and Comeau 4.3.10.
#include <iostream>
struct A { int name; };
template<typename T> struct C : T { using T::name; };
struct B : private A {...
Quelpart asked 6/9, 2012 at 6:49
3
Solved
Can you give me a concrete example when is preferable to use private inheritance over composition? Personally, I will use composition over private inheritance, but there might be the case that usin...
Jonniejonny asked 9/6, 2011 at 18:13
3
Solved
Could someone please explain the following compiler error to me:
struct B
{
};
template <typename T>
struct A : private T
{
};
struct C : public A<B>
{
C(A<B>); // ERROR HER...
Viceregal asked 10/2, 2012 at 5:28
3
Solved
The compilation of the next example :
class A
{
public:
void foo()
{
}
};
class B : private A
{
public:
using A::foo;
};
int main()
{
typedef void (B::*mf)();
mf func = &B::foo;
B...
Flagwaving asked 15/9, 2011 at 7:20
3
The following code yields a compile time error:
'base::print' : cannot access private member declared in class 'base_der'
However, I have made the member public in the derived class. Why doesn...
Zucker asked 4/8, 2011 at 14:11
1
Solved
I have the following code example that doesn't compile:
#include <stdio.h>
namespace my
{
class base1
{ // line 6
};
class base2: private base1
{
};
class derived: private base2
{...
Thirza asked 12/4, 2011 at 11:44
3
Solved
Compiling this code using g++ 4.2.1:
struct S { };
template<typename T> struct ST { };
template<typename BaseType>
class ref_count : private BaseType { };
template<typename RefCou...
Pocky asked 12/7, 2010 at 3:24
2
Solved
Given this sample code:
#include <iostream>
#include <stdexcept>
class my_exception_t : std::exception
{
public:
explicit my_exception_t()
{ }
virtual const char* what() const thr...
Ingratitude asked 3/4, 2010 at 0:2
3
Solved
In the following code, it seems class C does not have access to A's constructor, which is required because of the virtual inheritance. Yet, the code still compiles and runs. Why does it work?
clas...
Gillian asked 3/3, 2010 at 12:29
1
© 2022 - 2024 — McMap. All rights reserved.