Can't overload i/o operators for private enum in namespaceOverloading operator<< for a private enumCast int to enum in C#How do I enumerate an enum in C#?Should 'using' directives be inside or outside the namespace?What is the preferred syntax for defining enums in JavaScript?How to get an enum value from a string value in Java?Get int value from enum in C#Why is “using namespace std;” considered bad practice?What is the “-->” operator in C++?Comparing Java enum members: == or equals()?What are the basic rules and idioms for operator overloading?
How did Einstein know the speed of light was constant?
How did שְׁלֹמֹה (shlomo) become Solomon?
What is the addition in the re-released version of Avengers: Endgame?
Advice for making/keeping shredded chicken moist?
Has chattel slavery ever been used as a criminal punishment in the USA since the passage of the Thirteenth Amendment?
What happens if the limit of 4 billion files was exceeded in an ext4 partition?
Did Snape really give Umbridge a fake Veritaserum potion that Harry later pretended to drink?
Should I cheat if the majority does it?
Interview Question - Card betting
Show that there are infinitely more problems than we will ever be able to compute
What is the maximum amount of diamond in one Minecraft game?
List comprehensions in Mathematica?
How would an Amulet of Proof Against Detection and Location interact with the Comprehend Languages spell?
Term for a character that only exists to be talked to
Implementing absolute value function in c
Can you use a weapon affected by Heat Metal each turn if you drop it in between?
Boss has banned cycling to work because he thinks it's unsafe
Are there advantages in writing by hand over typing out a story?
What's the big deal about the Nazgûl losing their horses?
How come having a Deathly Hallow is not a big deal?
Is it bad to suddenly introduce another element to your fantasy world a good ways into the story?
Why does mean tend be more stable in different samples than median?
Why is there paternal, for fatherly, fraternal, for brotherly, but no similar word for sons?
What is the difference between a historical drama and a period drama?
Can't overload i/o operators for private enum in namespace
Overloading operator<< for a private enumCast int to enum in C#How do I enumerate an enum in C#?Should 'using' directives be inside or outside the namespace?What is the preferred syntax for defining enums in JavaScript?How to get an enum value from a string value in Java?Get int value from enum in C#Why is “using namespace std;” considered bad practice?What is the “-->” operator in C++?Comparing Java enum members: == or equals()?What are the basic rules and idioms for operator overloading?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a private enum in a class within a namespace. I'm trying to overload the I/O operators, but all I get is the compiler complaining about the Enum being private. The solution from this post did nothing to help me. Here is an isolated version of my problem.
TestClass.h
#include <iostream>
namespace Test
class TestClass
enum Enum : unsigned int a = 0, b;
friend std::ostream& operator<<(std::ostream& os, Enum e);
;
std::ostream& operator<<(std::ostream& os, TestClass::Enum e);
;
TestClass.cpp
#include "TestClass.h"
std::ostream& operator<<(std::ostream& os, Test::TestClass::Enum e)
//do it
The compiler complains about this, but does not complain when I remove the class from the namespace, so how do I get this to compile?
I'm using
g++ -c TestClass.h
to compile this
c++ enums namespaces operator-overloading friend
add a comment |
I have a private enum in a class within a namespace. I'm trying to overload the I/O operators, but all I get is the compiler complaining about the Enum being private. The solution from this post did nothing to help me. Here is an isolated version of my problem.
TestClass.h
#include <iostream>
namespace Test
class TestClass
enum Enum : unsigned int a = 0, b;
friend std::ostream& operator<<(std::ostream& os, Enum e);
;
std::ostream& operator<<(std::ostream& os, TestClass::Enum e);
;
TestClass.cpp
#include "TestClass.h"
std::ostream& operator<<(std::ostream& os, Test::TestClass::Enum e)
//do it
The compiler complains about this, but does not complain when I remove the class from the namespace, so how do I get this to compile?
I'm using
g++ -c TestClass.h
to compile this
c++ enums namespaces operator-overloading friend
add a comment |
I have a private enum in a class within a namespace. I'm trying to overload the I/O operators, but all I get is the compiler complaining about the Enum being private. The solution from this post did nothing to help me. Here is an isolated version of my problem.
TestClass.h
#include <iostream>
namespace Test
class TestClass
enum Enum : unsigned int a = 0, b;
friend std::ostream& operator<<(std::ostream& os, Enum e);
;
std::ostream& operator<<(std::ostream& os, TestClass::Enum e);
;
TestClass.cpp
#include "TestClass.h"
std::ostream& operator<<(std::ostream& os, Test::TestClass::Enum e)
//do it
The compiler complains about this, but does not complain when I remove the class from the namespace, so how do I get this to compile?
I'm using
g++ -c TestClass.h
to compile this
c++ enums namespaces operator-overloading friend
I have a private enum in a class within a namespace. I'm trying to overload the I/O operators, but all I get is the compiler complaining about the Enum being private. The solution from this post did nothing to help me. Here is an isolated version of my problem.
TestClass.h
#include <iostream>
namespace Test
class TestClass
enum Enum : unsigned int a = 0, b;
friend std::ostream& operator<<(std::ostream& os, Enum e);
;
std::ostream& operator<<(std::ostream& os, TestClass::Enum e);
;
TestClass.cpp
#include "TestClass.h"
std::ostream& operator<<(std::ostream& os, Test::TestClass::Enum e)
//do it
The compiler complains about this, but does not complain when I remove the class from the namespace, so how do I get this to compile?
I'm using
g++ -c TestClass.h
to compile this
c++ enums namespaces operator-overloading friend
c++ enums namespaces operator-overloading friend
edited Mar 25 at 19:34
ABernitt
asked Mar 25 at 19:11
ABernittABernitt
155 bronze badges
155 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The operator in your cpp file is not the friend you declared. The friend is a member of the namespace, because the class it's declared in is a member.
So wrap the operator definition in the namespace scope too. Or fully qualify the defintion
std::ostream& Test::operator<<(std::ostream& os, Test::TestClass::Enum e)
//do it
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55344919%2fcant-overload-i-o-operators-for-private-enum-in-namespace%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The operator in your cpp file is not the friend you declared. The friend is a member of the namespace, because the class it's declared in is a member.
So wrap the operator definition in the namespace scope too. Or fully qualify the defintion
std::ostream& Test::operator<<(std::ostream& os, Test::TestClass::Enum e)
//do it
add a comment |
The operator in your cpp file is not the friend you declared. The friend is a member of the namespace, because the class it's declared in is a member.
So wrap the operator definition in the namespace scope too. Or fully qualify the defintion
std::ostream& Test::operator<<(std::ostream& os, Test::TestClass::Enum e)
//do it
add a comment |
The operator in your cpp file is not the friend you declared. The friend is a member of the namespace, because the class it's declared in is a member.
So wrap the operator definition in the namespace scope too. Or fully qualify the defintion
std::ostream& Test::operator<<(std::ostream& os, Test::TestClass::Enum e)
//do it
The operator in your cpp file is not the friend you declared. The friend is a member of the namespace, because the class it's declared in is a member.
So wrap the operator definition in the namespace scope too. Or fully qualify the defintion
std::ostream& Test::operator<<(std::ostream& os, Test::TestClass::Enum e)
//do it
edited Mar 25 at 19:25
answered Mar 25 at 19:20
StoryTellerStoryTeller
113k18 gold badges243 silver badges308 bronze badges
113k18 gold badges243 silver badges308 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55344919%2fcant-overload-i-o-operators-for-private-enum-in-namespace%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown