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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:40:28+00:00 2026-05-26T05:40:28+00:00

#ifndef SLIST_H #define SLIST_H #include llist.h using namespace std; class slist:public llist{ public: slist();

  • 0
#ifndef SLIST_H
#define SLIST_H
#include "llist.h"

using namespace std;

class slist:public llist{

 public:
  slist();
  int search(el_t Key);
  void replace(el_t Elem, int I);
};
#endif

That is my new class I just made that gives me the search and replace function, on top of all the inherited functions contained in llist.h

In my main…

#include "slist.h"
#include <iostream>

using namespace std;

int main(){
  slist list;
  list.addFront(4);
  cout<<list.search(4);
}

I’m trying to call addfront() which is a public function in the llist class. Then I want to call search() which is an inherited public function of the slist class. g++ gives me a few errors that I don’t understand.

slist.h: In function âint main()â:
slist.h:10: error: âslist::slist()â is protected
main.cpp:7: error: within this context

slist() is protected? Why’s that? I put it under public:

Also whats up with the this context, I’m guessing I’m just doing the whole inheritance thing totally wrong. Any help would be appreciated!

Edit: Here’s the llist class, if it helps

#ifndef LIST_H
#define LIST_H
#include <iostream>
using namespace std;

class llist{
 protected:

   typedef int el_t;
   el_t total;

  struct Node{
    int Elem;
    Node *Next;
  };

  Node *Front;
  Node *Rear;
  Node * Curr;

public:
 class Overflow{};
 class Underflow{};
 class Range{};
 llist();
 ~llist();
 bool isEmpty();
 void displayAll();
 void addRear(el_t NewNum);
 void deleteFront(el_t& OldNum);
 void addFront(el_t NewNum);
 void deleteRear(el_t& OldNum);
 void deleteIth(int I, el_t& OldNum);
 void addbeforeIth(int I, el_t newNum);
 class Overflow;

};
#endif

This is llist.cpp with only the relevant functions pasted

#include "llist.h"
#include <iostream>

using namespace std;
int total=0;

llist::llist(){
    Front=NULL;
    Rear=NULL;
    total=0;
}

llist::~llist(){
  while(Front!=NULL){
    int z;
    deleteFront(z);
  }
}
bool llist::isEmpty(){
if(Front==NULL){
  return true;
}
return false;
}
void llist::displayAll(){
 Curr=Front;
 if(isEmpty()){
   cout<<"[ empty ]"<<endl;
 }else{
  while(Curr!=NULL){\
    cout<<"curr != NuL"<<endl;
    cout<<Curr->Elem<<endl;
    Curr=Curr->Next;
  }
 }
 }



void llist::addFront(el_t NewNum){
    if(isEmpty()){
       Node *x=new Node;
       x->Next=Front;
       Rear=Front;
       Front=x;
       Front->Elem=NewNum;
        }else{
      Node *x=new Node;
      x->Next=Front;
      Front=x;
      Front->Elem=NewNum;
      ++total;
  }
  }
  • 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-26T05:40:28+00:00Added an answer on May 26, 2026 at 5:40 am

    I honestly can’t see the problem but not every compiler is standard-compliant, so I would try the following:

    1) Rename your class – if it works, that means it’s a because of a naming conflict.

    2) Remove the using directives.

    3) Remove the inheritance. If it works after this… you really need to change compilers.

    4) Try #undef public before your class declaration. If it works after this… well, someone’s in for a talk with the manager.

    5) Pray…

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

Sidebar

Related Questions

#ifndef MIGRATINGUSER_H #define MIGRATINGUSER_H #include <iostream> using namespace std; class MigratingUser { public: void
I have the following class #ifndef Container_H #define Container_H #include <iostream> using namespace std;
I have this main function: #ifndef MAIN_CPP #define MAIN_CPP #include dsets.h using namespace std;
#ifndef DELETE #define DELETE(var) delete var, var = NULL #endif using namespace std; class
#ifndef __DynTex_H__ #define __DynTex_H__ #include SdkSample.h using namespace Ogre; using namespace OgreBites; class _OgreSampleClassExport
I have a file GetL.hxx #ifndef GetL_included #define GetL_included #include <iostream> using namespace std;
I have a file GetL.hxx #ifndef GetL_included #define GetL_included #include <iostream> using namespace std;
#ifndef IMAGEDATA_H #define IMAGEDATA_H #include <iostream> #include <vector> class ImageData { public: std::string foo;
//// header file #ifndef _SECTION_ #define _SECTION_ #include <map> #include Employee.h using namespace std;
Header file is graph.h #ifndef _GRAPH_H_ #define _GRAPH_H_ #include <map> #include <vector> using namespace

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.