C++ classes and nested members
By : Basap
Date : March 29 2020, 07:55 AM
I hope this helps you . I'm not sure how to call this. Basically I want to make a class with nested members. , Something like this: code :
class Plass
{
public:
Plass(Point *newPoint, Way *newWay)
{
moint = newPoint;
bay = newWay;
// or instantiate here:
// moint = new Point();
// bay = new Way();
// just don't forget to mention it in destructor
}
Point *moint;
Way *bay;
}
Plass *doxy = new Plass();
doxy->moint->x;
doxy->bay->path->getPath();
|
Members of a nested namespace
By : user2145859
Date : March 29 2020, 07:55 AM
hop of those help? Assuming namespace A2 is nested within namespace A1, then A2 is a member of enclosing A1. But members of A2 ( thus types declared within A2 ) are not members of A1. , Consider the following code :
namespace A1
{
namespace A2 // A1.A2
{
class C2 // full name: A1.A2.C2
{
private A1.C1 c1b; // full name
private C1 c1b; // shortest form. A1 is in scope here
}
}
class C1 // full name: A1.C1
{
private A1.A2.C2 c2a; // full name
private A2.C2 c2b; // shortest form. We can omit the A1 prefix but not A2
}
}
|
Access members of nested class
By : Patrick Faria
Date : March 29 2020, 07:55 AM
this one helps. , it either tells me I need an object [...] code :
class A
{
class B
{
public:
int x;
} mB;
public:
void printX() { std::cout << mB.x; }
};
|
Kotlin visibility of nested members
By : Kassius
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have a class with a nested, private class. I have a Builder, standard Java builder pattern, that constructs instances of this class. I don't want anyone outside of my class to be able to see my hidden class. , I see two viable options: code :
class Example private constructor(builder: Builder) {
private val doNotExposeThis: SneakyType
init {
doNotExposeThis = builder.doNotExposeThis
}
internal class SneakyType(x: String)
class Builder {
internal lateinit var doNotExposeThis: SneakyType
fun addFoo(something: String) {
doNotExposeThis = SneakyType(something)
}
fun build(): Example {
return Example(this)
}
}
}
class Example private constructor(private val doNotExposeThis: SneakyType) {
private class SneakyType(x: String)
class Builder {
private lateinit var doNotExposeThis: SneakyType
fun addFoo(something: String) {
doNotExposeThis = SneakyType(something)
}
fun build(): Example {
return Example(doNotExposeThis)
}
}
}
|
std::void_t and nested non type members
By : jks
Date : March 29 2020, 07:55 AM
I hope this helps you . I have the following code where I get unexpected result (second static_assert fails): , Is there a nicer way to do what I want? code :
template <auto...>
using value_void_t = void;
template <typename T>
struct is_bananas<T, value_void_t<T::config::num_items>>
: std::true_type {};
|