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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:10:25+00:00 2026-06-14T18:10:25+00:00

I feel like this should be something simple but I have spent tons of

  • 0

I feel like this should be something simple but I have spent tons of time trying to figure out why I cannot make a linked list of different classes that inherit from the same abstract class

each of the classes (i.e. BadCruisingShootingAgent) I am pushing to the front of the linked list are inheriting from the abstract class Agent.

I am getting….
error: cannot declare field ‘Node::data’ to be of abstract type ‘Agent’

my main.cpp file reads:

int main()
{
LinkedList<Agent> *agentList= new LinkedList<Agent>();

agentList->push_front(*(new BadCruisingShootingAgent));
agentList->push_front(*(new BadFollowingDisarmedAgent));
agentList->push_front(*(new BadFollowingShootingAgent));
agentList->push_front(*(new BadStationaryDisarmedAgent));
agentList->push_front(*(new BadStationaryShootingAgent));
agentList->push_front(*(new GoodCruisingDisarmedAgent));
agentList->push_front(*(new GoodCruisingShootingAgent));
agentList->push_front(*(new GoodFollowingDisarmedAgent));
agentList->push_front(*(new GoodFollowingShootingAgent));
agentList->push_front(*(new GoodStationaryDisarmedAgent));
agentList->push_front(*(new GoodStationaryShootingAgent));

for(int i=0; i<agentList->size(); i++)
{
  cout    << agentList->at(i).getType()<<" "<<agentList->at(i).nextMovingDirection(10,10)<<" "<<agentList->at(i).shootingDirection(10,10)<<endl;
}



return(0);
}

I don’t understand why this does not work while if I just manually write there are no problems.

 Agent *a= new BadCruisingShootingAgent;
 cout    << a->getType()<<" "<<a->extMovingDirection(10,10)<<" "<<a->shootingDirection(10,10)<<endl;

Then my linked list’s class function push_front is defined as:

template <typename T>
void LinkedList<T>::push_front(const T& val)
{
    //make a new node
Node<T>* newOne = new Node<T>(val);

//push it onto the front of the list
newOne->next = this->head;
this->head = newOne;

//increase the length of the list by one
this->length++;
}

my node class is defined as:

template <typename T>
class Node
{
public:

    Node(const T& d);

    T data;
    Node<T>* next;
};

template <typename T>
Node<T>::Node(const T& d)
: data(d)
{
    this->next = NULL;
}
  • 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-14T18:10:26+00:00Added an answer on June 14, 2026 at 6:10 pm

    You can’t perform polymorphism on types that aren’t references or pointers. Thus, when you create a LinkedList<Agent>, the underlying nodes are allocating an Agent, which can’t be created because it is an abstract type.

    Thus, using LinkedList<Agent*> lets you polymorphically store different derived types in your linked list.

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

Sidebar

Related Questions

I feel like this should be a no brainer, but clearly I'm missing something...
I feel like this is something I should already know, but I'm just not
Feel like this should be something easy that I'm missing. I have a table
I feel like this should be obvious to me, but for some reason I
I feel like this is easy but I am missing something... Using jQuery, I
I feel like this might be really simple but I'm just not getting it
I feel like this must have been asked before, but I've looked at Knockout
I feel like I should know this but I've been stumped for hours now
I feel like the answer to this question is really simple, but I really
To me it seems like it should be so simple, but I just feel

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.