Using auto to instance private classes [duplicate]
This question already has an answer here:
Why can I use auto on a private type?
4 answers
What's the difference between type and name in C++?
3 answers
Consider the following code:
struct A
private:
struct B;
public:
B make() constreturn B;
;
int main()
A a;
auto b1 = a.make(); (void)b1;
// A::B b2 = a.make(); (void)b2; // compile error: B is a private class
What is the logic behind being able to compile b1
line while the second b2
line? After all auto
is supposed equivalent to replace the name of the class.
If it is what I think, this shows that auto
is not simply syntax sugar.auto
on private classes can be used force the user not know about certain types but still be able to use instance of them! (and this was not possible in C++98?)
Am I mistaken in this interpretation?
c++11 private auto
marked as duplicate by R Sahu
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 12 '18 at 2:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Why can I use auto on a private type?
4 answers
What's the difference between type and name in C++?
3 answers
Consider the following code:
struct A
private:
struct B;
public:
B make() constreturn B;
;
int main()
A a;
auto b1 = a.make(); (void)b1;
// A::B b2 = a.make(); (void)b2; // compile error: B is a private class
What is the logic behind being able to compile b1
line while the second b2
line? After all auto
is supposed equivalent to replace the name of the class.
If it is what I think, this shows that auto
is not simply syntax sugar.auto
on private classes can be used force the user not know about certain types but still be able to use instance of them! (and this was not possible in C++98?)
Am I mistaken in this interpretation?
c++11 private auto
marked as duplicate by R Sahu
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 12 '18 at 2:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
You are right in your assessment of the situation. I have seen a question on SO regarding that. The main point is that the nameA::B
isprivate
but not the type, if that makes sense. I'll try to find the duplicate.
– R Sahu
Nov 12 '18 at 2:54
2
stackoverflow.com/questions/13532784/…
– rmawatson
Nov 12 '18 at 2:55
@RSahu, thanks. I find interesting that this was no possible in C++98.
– alfC
Nov 12 '18 at 3:21
1
@alfC, in C++98, it was possible to access the type in the sense that you could use thepublic
member functions/variables of the returned object without assigning it to a variable. Somethink likea.make().b_func()
.
– R Sahu
Nov 12 '18 at 3:26
add a comment |
This question already has an answer here:
Why can I use auto on a private type?
4 answers
What's the difference between type and name in C++?
3 answers
Consider the following code:
struct A
private:
struct B;
public:
B make() constreturn B;
;
int main()
A a;
auto b1 = a.make(); (void)b1;
// A::B b2 = a.make(); (void)b2; // compile error: B is a private class
What is the logic behind being able to compile b1
line while the second b2
line? After all auto
is supposed equivalent to replace the name of the class.
If it is what I think, this shows that auto
is not simply syntax sugar.auto
on private classes can be used force the user not know about certain types but still be able to use instance of them! (and this was not possible in C++98?)
Am I mistaken in this interpretation?
c++11 private auto
This question already has an answer here:
Why can I use auto on a private type?
4 answers
What's the difference between type and name in C++?
3 answers
Consider the following code:
struct A
private:
struct B;
public:
B make() constreturn B;
;
int main()
A a;
auto b1 = a.make(); (void)b1;
// A::B b2 = a.make(); (void)b2; // compile error: B is a private class
What is the logic behind being able to compile b1
line while the second b2
line? After all auto
is supposed equivalent to replace the name of the class.
If it is what I think, this shows that auto
is not simply syntax sugar.auto
on private classes can be used force the user not know about certain types but still be able to use instance of them! (and this was not possible in C++98?)
Am I mistaken in this interpretation?
This question already has an answer here:
Why can I use auto on a private type?
4 answers
What's the difference between type and name in C++?
3 answers
c++11 private auto
c++11 private auto
asked Nov 12 '18 at 2:49
alfC
4,94722858
4,94722858
marked as duplicate by R Sahu
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 12 '18 at 2:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by R Sahu
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 12 '18 at 2:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
You are right in your assessment of the situation. I have seen a question on SO regarding that. The main point is that the nameA::B
isprivate
but not the type, if that makes sense. I'll try to find the duplicate.
– R Sahu
Nov 12 '18 at 2:54
2
stackoverflow.com/questions/13532784/…
– rmawatson
Nov 12 '18 at 2:55
@RSahu, thanks. I find interesting that this was no possible in C++98.
– alfC
Nov 12 '18 at 3:21
1
@alfC, in C++98, it was possible to access the type in the sense that you could use thepublic
member functions/variables of the returned object without assigning it to a variable. Somethink likea.make().b_func()
.
– R Sahu
Nov 12 '18 at 3:26
add a comment |
1
You are right in your assessment of the situation. I have seen a question on SO regarding that. The main point is that the nameA::B
isprivate
but not the type, if that makes sense. I'll try to find the duplicate.
– R Sahu
Nov 12 '18 at 2:54
2
stackoverflow.com/questions/13532784/…
– rmawatson
Nov 12 '18 at 2:55
@RSahu, thanks. I find interesting that this was no possible in C++98.
– alfC
Nov 12 '18 at 3:21
1
@alfC, in C++98, it was possible to access the type in the sense that you could use thepublic
member functions/variables of the returned object without assigning it to a variable. Somethink likea.make().b_func()
.
– R Sahu
Nov 12 '18 at 3:26
1
1
You are right in your assessment of the situation. I have seen a question on SO regarding that. The main point is that the name
A::B
is private
but not the type, if that makes sense. I'll try to find the duplicate.– R Sahu
Nov 12 '18 at 2:54
You are right in your assessment of the situation. I have seen a question on SO regarding that. The main point is that the name
A::B
is private
but not the type, if that makes sense. I'll try to find the duplicate.– R Sahu
Nov 12 '18 at 2:54
2
2
stackoverflow.com/questions/13532784/…
– rmawatson
Nov 12 '18 at 2:55
stackoverflow.com/questions/13532784/…
– rmawatson
Nov 12 '18 at 2:55
@RSahu, thanks. I find interesting that this was no possible in C++98.
– alfC
Nov 12 '18 at 3:21
@RSahu, thanks. I find interesting that this was no possible in C++98.
– alfC
Nov 12 '18 at 3:21
1
1
@alfC, in C++98, it was possible to access the type in the sense that you could use the
public
member functions/variables of the returned object without assigning it to a variable. Somethink like a.make().b_func()
.– R Sahu
Nov 12 '18 at 3:26
@alfC, in C++98, it was possible to access the type in the sense that you could use the
public
member functions/variables of the returned object without assigning it to a variable. Somethink like a.make().b_func()
.– R Sahu
Nov 12 '18 at 3:26
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
You are right in your assessment of the situation. I have seen a question on SO regarding that. The main point is that the name
A::B
isprivate
but not the type, if that makes sense. I'll try to find the duplicate.– R Sahu
Nov 12 '18 at 2:54
2
stackoverflow.com/questions/13532784/…
– rmawatson
Nov 12 '18 at 2:55
@RSahu, thanks. I find interesting that this was no possible in C++98.
– alfC
Nov 12 '18 at 3:21
1
@alfC, in C++98, it was possible to access the type in the sense that you could use the
public
member functions/variables of the returned object without assigning it to a variable. Somethink likea.make().b_func()
.– R Sahu
Nov 12 '18 at 3:26