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 9272045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:46:19+00:00 2026-06-18T15:46:19+00:00

#include <iostream> #include <stdlib.h> #include <sstream> class api { private: void psParser () {

  • 0
#include <iostream>
#include <stdlib.h>
#include <sstream>

class api
{
private:
    void psParser ()
    {
        std::stringstream psOutput;
        psOutput << "ps --no-headers -f -p " << getpid() << " > .txt";

        system (psOutput.str().c_str());

        std::stringstream processInfo;
        processInfo << ":"__FILE__ << ":" << __DATE__ << ":" << __TIME__ << ":";
    }

public:
    static std::stringstream message;
};

namespace sstreamss
{
    std :: stringstream api :: message;
};

int main ()
{
    api::message << "zxzx";

    return 0;
}

Output:

error: definition of ‘api::message’ is not in namespace enclosing ‘api’

I want that static std::stringstream message should be accessible at a global scope, so I want this under a namespace.

What’s the way out?

  • 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-18T15:46:20+00:00Added an answer on June 18, 2026 at 3:46 pm

    I am guessing that you want to have the same instance of api::message accessible across all translation units that have access to api. Unlike plain, non-class static data, which have internal linkage, static class members have external linkage. This means the same instance is seen everywhere. So you do not have to play any games with namespaces. A namespace wouldn’t change anything here, but it would have to enclose the whole api class anyway.

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

Sidebar

Related Questions

#include <stdlib.h> #include <iostream> #include <vector> #include <string> class A { public: std::string s;
#include<iostream> #include<stdlib.h> #include<string.h> #include<stdio.h> using namespace std; union type{ int a; char b; int
#include<iostream> #include<time.h> #include<list> #include<stdlib.h> #include<fstream> using namespace std; typedef struct diskBtNode { int parent;
Here is my code: #include <iostream> #include <stdlib.h> #include <fstream> using namespace std; int
I created a program called test: #include<stdlib.h> #include<iostream> int main() { std::cout<<system(..\\add\\debug\\add.exe 4 8);
Please see the code below: #include <iostream> #include <stdlib.h> #include <time.h> using namespace std;
Is there anyway I can modify this code example #include <stdlib.h> #include <iostream> class
Consider the following example: #include <iostream> #include <sstream> #include <vector> #include <wchar.h> #include <stdlib.h>
#include <stdlib.h> #include <stdio.h> #include <iostream> #include <string.h> using namespace std; int main() {
#include <iostream.h> #include <fstream.h> #include <stdlib.h> void vowel(fstream a){ char ch; int ctr =

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.