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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:44:44+00:00 2026-06-07T11:44:44+00:00

I’m fairly new to C++ inheritance, and I’m using boost sockets. I want to

  • 0

I’m fairly new to C++ inheritance, and I’m using boost sockets. I want to create something comparable to Java’s DataOutputStream for a synchronous boost socket. Namely, I want methods like SendInt, ReadLong, etc.
I tried making a class that inherits from the socket, but I keep getting errors. Right now, I have something like this:

DataSocketStream.h

#include "boost/asio.hpp"
#include <vector>
namespace Server {
using namespace std;
namespace as = boost::asio;
namespace ip = boost::asio::ip;
class DataSocketStream : public ip::tcp::socket{
public:
    DataSocketStream(as::io_service);
    virtual ~DataSocketStream();
    void WriteInt(int);
    void WriteLong(long);
    int ReadInt(boost::system::error_code);
    long ReadLong(boost::system::error_code);
    void Flush (boost::system::error_code);
    string ReadString(boost::system::error_code);
    double ReadDouble(boost::system::error_code);
    void WriteDouble(double);
private:
    ip::tcp::socket* socketFormPtr
    std::vector<char> Message;
};

DataSocketStream.cpp

#include "DataSocketStream.h"

namespace Server {
namespace as = boost::asio;
namespace ip = boost::asio::ip;
using namespace std;
DataSocketStream::DataSocketStream(as::io_service ios)
: ip::tcp::socket(ios)
{
    socketFormPtr = this;

}

DataSocketStream::~DataSocketStream()
{

}

void DataSocketStream::WriteInt(int toWrite){
    //Implementation that pushes the bytes onto the vector Message
}
void DataSocketStream::WriteLong(long toWrite){
    //...
}

void DataSocketStream::Flush(boost::system::error_code e)
{
    as::write(*socketFormPtr, as::buffer(Message), as::transfer_all(),e);
    delete (&Message);
    std::vector<char> Message;
}

int DataSocketStream::ReadInt(boost::system::error_code e)
{
    char Af[4];
    as::read(*socketFormPtr, as::buffer(Af), e);
    return ((Af[0]<<24)| (Af[1]<<16) | (Af[2]<<8) | (Af[3]));

}

long DataSocketStream::ReadLong(boost::system::error_code e)
{
    //...
}

string DataSocketStream::ReadString(boost::system::error_code e)
{
    //...
}

double DataSocketStream::ReadDouble(boost::system::error_code e)
{
    //...
}
void DataSocketStream::WriteDouble(double val)
{
    //...
}
} 

However, when I try something like
as::io_service io_service;
DataSocketStream CLsocket(io_service);

The compiler gives me an error, error: ‘boost::noncopyable_::noncopyable::noncopyable(const boost::noncopyable_::noncopyable&)’ is private
I figured that has something to do with my class not being a part of the boost library.

I tried inheriting from other boost::asio::basic_stream_socket, but I got errors doing that too. (It was a very strange ‘Invalid use of “::” ‘ error)
I also tried creating a normal boost::asio::ip::tcp::socket and then casting the pointer to a pointer of DataSocketStream, but that didn’t work either.

I know that I could do all this in the form of helper methods like:

int ReadInt(boost::asio::ip::tcp::socket* S, boost::system::error_code e)
{
    char Af[4];
    as::read(*S, as::buffer(Af), e);
    return ((Af[0]<<24)| (Af[1]<<16) | (Af[2]<<8) | (Af[3]));

}

but the inheritance way seems to be the better design. Is there something I am missing, or is the boost library really not designed to be extended in the way I am trying?
Thanks!

  • 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-07T11:44:49+00:00Added an answer on June 7, 2026 at 11:44 am

       

    DataSocketStream(as::io_service);
    

    An io_service is noncopyable as the error suggests, pass it by reference

    DataSocketStream(as::io_service&);
                                   ^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... 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.