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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:24:01+00:00 2026-06-13T13:24:01+00:00

So im a beginner at C++ and i’m working with an abstract class called

  • 0

So im a beginner at C++ and i’m working with an abstract class called VBot in which i inherit to other bot classes. Now I know i need to override the pure virtual code in the VBot class which i do so i don’t think that is the problem. I think because im so inexperienced at C++ I am doing some thing wrong with the constructors because i keep getting the cannot instantiate abstract class.
This is the VBot.h file

class VBot
{
public:

    VBot( int startX, int startY, Panel ^ drawingPanel ) : 
      x(startX), y(startY), panel(drawingPanel), energy(100), image(NULL) { };

virtual ~VBot() { };


virtual void Move() = 0;

virtual int EnergyToFightWith() = 0;

bool IsDead() const { return energy <= 0; }

virtual void Show();

bool CollidedWith ( VBot * b ) const;

void DoBattleWith ( VBot * b );

protected:
     int x, y;                           // Current position of the VBot
     gcroot<Drawing::Bitmap ^> image;    // Image displayed for the VBot
     gcroot<Panel ^> panel;              // Panel on which to show the VBot.
     int energy                          // Current energy of the VBot

};
class CNNBot : public VBot
{
public:
CNNBot( int startX, int startY, Panel ^ drawingPanel ){
    VBot::VBot(startX,startY,drawingPanel);
    image = gcnew Drawing::Bitmap("HappyBot.bmp");}
~CNNBot(){};

void Move();

int EnergyToFightWith();
bool IsDead() { return (VBot::IsDead()); }
virtual void Show() { VBot::Show();}
bool CollidedWith ( VBot * b ) { return VBot::CollidedWith(b);}
void DoBattleWith ( VBot * b ){ VBot::DoBattleWith(b);}

private:
static const int MOVE_VAL = 55;
static const int RIGHT_BOUND = 490;
static const int DOWN = 40;
static const int MAXY = 379;
bool switcher;

};

And this will be the VBot.cpp

#include "stdafx.h"     

#include "Vbot.h"

void VBot::Show()
{ 
  Graphics ^ g = panel->CreateGraphics();
  g->DrawImageUnscaled( image, x, y );
  g->~Graphics();
}


bool VBot::CollidedWith ( VBot * b ) const
{
if (  b == NULL )
  return false;

return   ( x + image->Width ) >= b->x
     && ( b->x + b->image->Width ) >= x
     && ( y + image->Height ) >= b->y
     && ( b->y + b->image->Height ) >= y;

}


void VBot::DoBattleWith ( VBot * b )
{
   int mine = EnergyToFightWith();
   int yours = b->EnergyToFightWith();
   if( mine == yours )
{
   energy = energy - mine / 2;
   b->energy = b->energy - yours / 2;
}
else if ( mine > yours )
{
   if ( b->energy > 1 )
   {
      b->energy = b->energy - yours;
      energy = energy + yours / 2;
   }
   else
   {
      b->energy = b->energy - 1;
      energy = energy + 1;
   }
}
else
{
    if ( energy > 1 )
    {
       energy = energy - mine;
       b->energy = b->energy + mine / 2;
    }
    else
    {
       b->energy = b->energy + 1;
       energy = energy - 1;
    }
  }
}
int CNNBot::EnergyToFightWith()
{
return this->energy;
}

So the error is the cannot instantiate a abstract class so i think it is trying to construct VBot and not CNNBot because in the output it is giving me
void VBot::Move(void)’ : is abstract
and
‘int VBot::EnergyToFightWith(void)’ : is abstract

Sorry i forgot to add that part here is Move()

 void CNNBot::Move()
{
if (this->switcher)
{
    this->x += MOVE_VAL;
    if( this->x >= RIGHT_BOUND)
    {
        this->x = 0;
        this->y += DOWN;
        if(this->y > MAXY)
        {
            this->switcher = false;
            this->y = MAXY;
        }
    }
}
else
{
    this->x += MOVE_VAL;
    if( this->x >= RIGHT_BOUND)
    {
        this->x = 0;
        this->y -= DOWN;
        if(this->y < 0)
        {
            this->switcher = true;
            this->y = 0;
        }
    }
}
panel->Invalidate();
}

Whatever help you guys can give will be greatly appreciated to this novice programer.

  • 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-13T13:24:02+00:00Added an answer on June 13, 2026 at 1:24 pm

    To call a parent class’s constructor you need to put it in the initialization list:

    CNNBot( int startX, int startY, Panel ^ drawingPanel ):
        VBot(startX, startY, drawingPanel)
    {
        image = gcnew Drawing::Bitmap("HappyBot.bmp");
    }
    

    You had this, which tried to create and then throw away a nameless VBot object:

    CNNBot( int startX, int startY, Panel ^ drawingPanel ){
        VBot::VBot(startX,startY,drawingPanel);
        image = gcnew Drawing::Bitmap("HappyBot.bmp");}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner here trying to get a pipeline working in bash. If somebody can see
Beginner help needed :) I am doign an example form a php book which
JS beginner here. I need help with a script to place different content in
Beginner in python, but been programming for about 5 years now. I suspect I
A beginner question: I don't know how best to structure this bit of code,
Beginner to assembly programming for x86. I have a simple asm file which I
A beginner question I am sure, but I have just started working with a
total beginner to spring mvc. I need to prepopulate edit form in springmvc frame-work.
Beginner programmer here. after a bunch of reading about 'variables' which dont exist in
another beginner problem. Why isn't the following code with an asp.net page not working?

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.