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;








1















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










share|improve this question






























    1















    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










    share|improve this question


























      1












      1








      1








      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










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 19:34







      ABernitt

















      asked Mar 25 at 19:11









      ABernittABernitt

      155 bronze badges




      155 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          3














          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






          share|improve this answer
























            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
            );



            );













            draft saved

            draft discarded


















            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









            3














            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






            share|improve this answer





























              3














              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






              share|improve this answer



























                3












                3








                3







                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






                share|improve this answer















                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







                share|improve this answer














                share|improve this answer



                share|improve this answer








                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


















                    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.



















                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현