Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8634489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:44:16+00:00 2026-06-12T09:44:16+00:00

Suppose I have the following definitions: namespace test { class Test1 { void someMethod(double

  • 0

Suppose I have the following definitions:

namespace test
{
    class Test1
    {
        void someMethod(double a);
        void someOtherMethod(double a);
        //...
    };

    class Test2
    {
        void someMethod(double a);
        void someOtherMethod(double a);
        //...
    };
}

Here’s an example implementation (method 1):

namespace test
{
    // Test1
    // ----------------

    void Test1::someMethod(double a){
        // do something
    }

    void Test1::someOtherMethod(double a){
        // do something else
    }


    // Test2
    // ----------------

    void Test2::someMethod(double a){
        // do something
    }

    void Test2::someOtherMethod(double a){
        // do something else
    }

}

Here’s an alternative implementation (method 2):

// Test1
namespace test
{
    void Test1::someMethod(double a){
        // do something
    }

    void Test1::someOtherMethod(double a){
        // do something else
    }
}

// Test2
namespace test
{
    void Test2::someMethod(double a){
        // do something
    }

    void Test2::someOtherMethod(double a){
        // do something else
    }
}

The usual way to implement things is via method 1. The upshot of method 2 is that all implementation code for each class can be folded away in many editors, a feature that I’m quite fond of.

I was wondering if there is any more elegant way to do this, e.g., without having to re-open the namespace for each new class? I tried this:

{
    void Test1::someMethod(double a){}
}
{
    void Test2::someMethod(double a){}
}

But that doesn’t work (for reasons that aren’t entirely obvious to me I have to admit…). Is there something valid, similar, without any effect other than make the code foldable?

Obviously, it should be as portable as possible and not depend on any specific editor.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:44:18+00:00Added an answer on June 12, 2026 at 9:44 am

    There is no editor-independent way.1 Just close and re-open the namespace.

    That said, I think foldability is overrated. In particular, your use-case is simply a symptom of another problem: your files are too long. Do not define more than one class per file (unless the classes are quite small or intrinsically related). This is a simple rule of thumb that works quite well and solves your problem.

    If your code files exceed more than a couple hundred lines, split them up.


    1 That said, different editors offer different solutions. For instance, in Vim you could do:

    namespace test {
        // Test 1 {{{
    
        void Test1::someMethod(double a){
            // do something
        }
        …
    
        // }}}
    
    
        // Test2 {{{
    
        void Test2::someMethod(double a){
            // do something
        }
        …
    
        // }}}
    }
    

    ({{{,}}} is the default, but configurable, foldmarker.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

suppose I have following test/ Main.py test/one/ One.py test1.txt test/two/ Two.py test2.txt What I
Suppose I have following code: public class CBase: AbstractC,IRenderable { //code here } public
Suppose you have the following code namespace a{ struct S{}; //void f(int){} } namespace
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Suppose I have the following simple struct: struct Vector3 { double x; double y;
Suppose we have following two classes: class Temp{ public: char a; char b; };
suppose we have following function: void someFunction(int * araye){ for (int i=0;i<5;i++) cout <<araye[i]<<'
Suppose we have following code defined in tester.py class Tester( object ): def method(
I have the following problem: Suppose I have some basic counter class Counter .
Suppose I have an interface: public interface FooInterface { public void someMethod(); } and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.