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

  • Home
  • SEARCH
  • 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 6024311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:08:12+00:00 2026-05-23T04:08:12+00:00

I have Packet class contains virtual method and I have LogInRequest class which extends

  • 0

I have Packet class contains virtual method and I have LogInRequest class which extends the packet class

Packet.h file

class Packet {

public:
    Packet();
    virtual ~Packet();

protected:
    virtual char* toByte() = 0;
    virtual void fromByte(char *d) = 0;
    virtual Packet* handle() = 0;

    short m_bodySize;
    int64_t m_deviceId;
};


/*
 * LogInRequestPacket
 */
class LogInRequestPacket: public Packet{

public:

    LogInRequestPacket();
    virtual ~LogInRequestPacket();

    virtual char* toByte();
    virtual void fromByte(char *d);
    virtual Packet* handle();
};

Packet.cpp file

#include "Packet.h"

Packet::Packet() {
    // TODO Auto-generated constructor stub

}

Packet::~Packet() {
    // TODO Auto-generated destructor stub
}

/*
 * LogInRequestPacket
 */
LogInRequestPacket::LogInRequestPacket(){
    printf("LogInRequestPacket is being created... \n");
}

LogInRequestPacket::~LogInRequestPacket(){

}

char* LogInRequestPacket::toByte(){

}

void LogInRequestPacket::fromByte(char *d){

}

Packet* LogInRequestPacket::handle(){

}

I am trying to create this LogInRequestPacket from factory like this

Packet *packet = m_packetFactory->createInstance(static_cast<PACKET_TYPES>(type));
packet->fromByte(pdata);

And it seems like trying to call the protected virtual fromByte function instead of the child class’s fromByte function.

I am getting a red line at the line declaring “virtual void fromByte(char *d) = 0” in Packet class scope in Packet.h file and it complains “… is protected”

Also, it complains too with x within context

packet->fromByte(pdata);

How do I fix this problem. Thanks in advance…

  • 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-05-23T04:08:13+00:00Added an answer on May 23, 2026 at 4:08 am

    When you try to call a method through a pointer or reference, the compiler will verify the access specifier of the function in the static type of the object, even if it will dispatch the call to the dynamic type.

    In your Packet class you have stated that you don’t want user code (other than Packet, friends and derived classes) to be able to call the methods, and the compiler is just telling you that. If those functions should be accessible from other code, make them public:

    class Packet {
    public:
        Packet();
        virtual ~Packet();
    
        virtual char* toByte() = 0;
        virtual void fromByte(char *d) = 0;
        virtual Packet* handle() = 0;
    protected:
        short m_bodySize;
        int64_t m_deviceId;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an class which should send/receive data in packet form. This class contains
I have, for my game, a Packet class, which represents network packet and consists
I have a class that my client uses to Get() a packet. The packet
I am working with a wrapper class for CFHTTPMessage , which contains a CFHTTPMessageRef
In my application I have a PacketList class and Packet class. I'd like to
Lets say I have this class (just as an example): internal class Packet {
Let's say I have the following class: class Foo { public: Foo() { Bar();
I have a login.jsp page which contains a login form. Once logged in the
I have a byte array that represents a complete TCP/IP packet. For clarification, the
Say I have a fairly hefty JavaScript file, packed down to roughly 100kb or

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.