Questions tagged [member-access]
63 questions
38
votes
3 answers
Does the C# compiler get the Color Color rule wrong with const type members?
Okay, so the C# Language Specification has a special section (old version linked) on the Color Color rule where a member and its type has the same name. Well-known guru Eric Lippert once blogged about it.
The question I am going to ask here is in a…

Jeppe Stig Nielsen
- 60,409
- 11
- 110
- 181
13
votes
0 answers
Neither clang nor g++ compile the snippet below. Why?
Neither clang nor g++ compile this snippet:
struct A{
protected:
struct B{};
};
struct D: A::B, A{};
According to [class.access]/7, we have:
Similarly, the use of A::B as a base-specifier is well-formed because
D is derived from A, so…

João Afonso
- 1,934
- 13
- 19
13
votes
2 answers
In C++11, protected means public?
Continuing something learned in C++ error: base function is protected ...
The C++11 pointer-to-member rules effectively strip the protected keyword of any value, because protected members can be accessed in unrelated classes without any evil/unsafe…

Ben Voigt
- 277,958
- 43
- 419
- 720
8
votes
1 answer
What exactly is the meaning of the footnote mentioned in [expr.ref]/1?
[expr.ref]/1:
A postfix expression followed by a dot . or an arrow ->, optionally followed by the keyword template (17.2),
and then followed by an id-expression, is a postfix expression. The postfix expression before the dot or arrow
is evaluated;67…

Alexander
- 2,581
- 11
- 17
8
votes
3 answers
C# combined with MSIL - JIT Skip Verification
I'm trying to call the following MSIL method:
.method public hidebysig static bool IsRuntimeType(class [mscorlib]System.Type 'type') cil managed {
.maxstack 2
ldarg.0
isinst [mscorlib]System.RuntimeType
ldnull
cgt.un
ret
} //…

boaz23
- 118
- 8
8
votes
7 answers
Will the compiler-generated default constructor be public?
When I write a class Widget.java
public class Widget {
int data;
String name;
}
will the compiler-generated constructor be public or default?
public would be like
public class Widget {
int data;
String name;
public Widget()…

towi
- 21,587
- 28
- 106
- 187
5
votes
2 answers
Is taking the address of a member of an uninitialized object well defined?
Consider the following example. When bar is constructed, it gives it's base type (foo) constructor the address of my_member.y where my_member is data member that hasn't been initialized yet.
struct foo {
foo(int * p_x) : x(p_x) {}
int *…

François Andrieux
- 28,148
- 6
- 56
- 87
4
votes
0 answers
Member accessibility when both Base and Derived are template instantiations?
I'm puzzled by a compiler error regarding the visibility of an inherited member variable. I reduced it to this minimal, complete, and verifiable example:
#include
template class Base {
protected:
T m_value =…

Adrian McCarthy
- 45,555
- 16
- 123
- 175
3
votes
1 answer
How to access the member of a template parameter's? "Member access to incomplete type"
I'm trying to declare a class "Lambdas" that would provide lambdas (and their type information) to another class "Test". Lambdas also is holding the "this" reference to concrete Test instance for access of Test public members, inside the lambdas.
I…

barney
- 2,172
- 1
- 16
- 25
3
votes
1 answer
If class Outer is my friend, is class Outer::Inner too?
The following code compiles on MSVC:
#include
class Bob
{
int a;
friend class Outer;
};
class Outer
{
class Inner
{
void f(Bob obj)
{
std::cout << obj.a; //OK
}
…

Armen Tsirunyan
- 130,161
- 59
- 324
- 434
3
votes
2 answers
Why is an object not stongly typed in a foreach with var?
i was writing the following
if(this.tabControl1.TabPages.Count != ImagesList.Count())
{
foreach (var item in this.tabControl1.TabPages)
{
}
}
and i couldn't access the controls inside each item using item.
But with a defining it's type…
user1665612
2
votes
1 answer
Is there a consistent way to force errors on incorrect list or vector indexing
My expectation from other programming languages is that (1:4)[3:5] and list(asdf = 4, qwerty = 5)$asdg should both raise exceptions. Instead, the first silently returns c(3, 4, NA), and the second silently returns NULL (as does or list(asdf = 4,…

Chris Henry
- 55
- 5
2
votes
2 answers
what is the difference between '.' and '->' iOS?
Ok, I am confused!
I used to use -> whenever I accessed my instance objects, but now I see that after I set them in my application:didFinishLaunching like this:
self->counter = [NSNumber numberWithFloat:0.0f];
Down the road I got thrown out with…

Ted
- 3,805
- 14
- 56
- 98
2
votes
1 answer
'Delete' base member?
Is there a way to hide a member of the base-class?
class A
{
public int MyProperty { get; set; }
}
class B : A
{
private new int MyProperty { get; set; }
}
class C : B
{
public C()
{
//this should be an error
this.MyProperty = 5;
…

Shimmy Weitzhandler
- 101,809
- 122
- 424
- 632
1
vote
1 answer
de-referencing pointer using with &->
I have simple the nested structure:
struct abc {
int i;
};
struct milan {
struct abc obj;
};
int main()
{
struct milan *ptr;
ptr = malloc(sizeof(struct milan));
ptr->obj.i = 10;
printf("%d\n", ptr->obj);
}…

Milan
- 1,447
- 5
- 19
- 27