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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:55:00+00:00 2026-06-17T05:55:00+00:00

I’m working on compiling the code for Acellerated c++ chapter 15. I more or

  • 0

I’m working on compiling the code for Acellerated c++ chapter 15. I more or less copied the code straight out of the book, except in some places they defined things like constructors in the class body in the header file, and I separated them out to avoid link errors.

Below is the code; I attempted to compile it in Visual Studio 2010, but unfortunately it fails. It tells me it cannot create instances of the “String_Pic” and the other derived classes (Frame_Pic, HCat_Pic, and VCat_Pic) because it says they are still abstract classes. It says the culprit is the “display” function, which it says is undefined. However, I clearly define it for each derived class, as you can see below.

What’s going on here?

Header:

#ifndef _GUARD_PIC_BASE_H
#define _GUARD_PIC_BASE_H

    #include "Ptr.h"
    #include <iostream>
    #include <string>
    #include <vector>


    class Picture;

    class Pic_base {
        friend std::ostream& operator<<(std::ostream&, const Picture&);
        friend class Frame_Pic;
        friend class HCat_Pic;
        friend class VCat_Pic;
        friend class String_Pic;


        typedef std::vector<std::string>::size_type ht_sz;
        typedef std::string::size_type wd_sz;


        virtual wd_sz width() const = 0;
        virtual ht_sz height() const = 0;
        virtual void display(std::ostream, ht_sz, bool) const = 0;

    public:
        virtual ~Pic_base(){ }

    protected:
        static void pad(std::ostream&, wd_sz, wd_sz);
    };

    // public interface class and operations
    class Picture {
        friend std::ostream& operator<<(std::ostream&, const Picture&);
        friend Picture frame(const Picture&);
        friend Picture hcat(const Picture&, const Picture&);
        friend Picture vcat(const Picture&, const Picture&);

    public:
        Picture(const std::vector<std::string>& =
            std::vector<std::string>());
    private:
        Picture(Pic_base* ptr);  //here's one difference
        Ptr<Pic_base> p;
    };


    Picture frame(const Picture&);
    Picture hcat(const Picture&, const Picture&);
    Picture vcat(const Picture&, const Picture&);
    std::ostream& operator<<(std::ostream&, const Picture&);

    class String_Pic: public Pic_base {
        friend class Picture;
        std::vector<std::string> data;
        String_Pic(const std::vector<std::string>&);

        wd_sz width() const;
        ht_sz height() const;
        void display(std::ostream&, ht_sz, bool) const;
    };

    class VCat_Pic: public Pic_base {
        friend Picture vcat(const Picture&, const Picture&);
        Ptr<Pic_base> top, bottom;
        VCat_Pic(const Ptr<Pic_base>&, const Ptr<Pic_base>&);

        wd_sz width() const;
        ht_sz height() const;
        void display(std::ostream&, ht_sz, bool) const;
    };

    class HCat_Pic: public Pic_base {
        friend Picture hcat(const Picture&, const Picture&);
        Ptr<Pic_base> left, right;
        HCat_Pic(const Ptr<Pic_base>&, const Ptr<Pic_base>&);

        wd_sz width() const;
        ht_sz height() const;
        void display(std::ostream&, ht_sz, bool) const;
    };

    class Frame_Pic: public Pic_base {
        friend Picture frame(const Picture&);
        Ptr<Pic_base> p;
        Frame_Pic(const Ptr<Pic_base>& pic);

        wd_sz width() const;
        ht_sz height() const;
        void display(std::ostream&, ht_sz, bool) const;
    };

#endif

.cpp/implementation file:

#include "Ptr.h"
#include "Pic_Base.h"
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

//Picture-Specific Functions:

Picture::Picture(Pic_base* ptr):p(ptr) {}

Picture::Picture(const vector<string>& v): p(new String_Pic(v)) { }

//Frame-Specific Functions:

Frame_Pic::Frame_Pic(const Ptr<Pic_base>& pic): p(pic) {}

Pic_base::wd_sz Frame_Pic::width() const { return p->width() + 4; }

Pic_base::ht_sz Frame_Pic::height() const { return p->height() + 4; }

void Frame_Pic::display(ostream& os, ht_sz row, bool do_pad) const{
    if (row >= height()) {
        // out of range
        if (do_pad)
            pad(os, 0, width());
    } else {
        if (row == 0 || row == height() - 1) {

            // top or bottom row
            os << string(width(), '*');
        } else if (row == 1 || row == height() - 2) {

            // second from fop or bottom row
            os << "*";
            pad(os, 1, width() - 1);
            os << "*";
        } else {
            // interior row
            os << "* ";
            p->display(os, row - 2, true);
            os << " *";
        }
    }
}

Picture frame(const Picture& pic){
    return new Frame_Pic(pic.p);
}

//HCat-Specific Functions:

HCat_Pic::HCat_Pic(const Ptr<Pic_base>& l, const Ptr<Pic_base>& r): left(l), right(r) { }

HCat_Pic::HCat_Pic(const Ptr<Pic_base>& l, const Ptr<Pic_base>&r):
left(l), right(r) { }

Pic_base::wd_sz width() const { return left->width() + right->width(); }

Pic_base::ht_sz height() const { return max(left->height(), right->heigth()); }

void HCat_Pic::display(ostream& os, ht_sz row, bool do_pad) const{
    left->display(os, row, do_pad || row < right->height());
    right->display(os, row, do_pad);
}

Picture hcat(const Picture& l, const Picture& r){
    return new HCat_Pic(l.p, r.p);
}

//VCat-Specific Functions:

VCat_Pic::VCat_Pic(const Ptr<Pic_base>& t, const Ptr<Pic_base>& b): top(t), bottom(b) { }

Picture vcat(const Picture& t, const Picture& b){
    return new VCat_Pic(t.p, b.p);
}

Pic_base::wd_sz VCat_Pic::width() const {
    return max(top->width(), bottom->width());
}

Pic_base::ht_sz VCat_Pic::height() const{
    return top->height() + bottom->height();
}

void VCat_Pic::display(ostream& os, ht_sz row, bool do_pad) const{
    wd_sz w = 0;
    if (row < top->height()) {
        // we are in the top subpicture
        top->display(os, row, do_pad);
        w = top->width();
    } else if (row < height()) {
        // we are in the bottom subpicture
        bottom->display(os, row - top->height(), do_pad);
        w = bottom->width();
    }
    if (do_pad)
        pad(os, w, width());
}

//String_Pic-Specific Functions:

String_Pic::String_Pic(const std::vector<std::string>& v): data(v) { }

Pic_base::ht_sz String_Pic::height() const { return data.size(); }

Pic_base::wd_sz String_Pic::width() const{
    Pic_base::wd_sz n = 0;
    for (Pic_base::ht_sz i = 0;  i != data.size(); ++i)
        n = max(n, data[i].size());
    return n;
}

void String_Pic::display(ostream& os, ht_sz row, bool do_pad) const{
    wd_sz start = 0;

    // write the row if we're still in range
    if (row < height()) {
        os << data[row];
        start = data[row].size();
    }

    // pad the output if necessary
    if (do_pad)
        pad(os, start, width());
}

//Pic_base-Specific functions:
void Pic_base::pad(std::ostream& os, wd_sz beg, wd_sz end) {
    while (beg != end) {
        os << " ";
        ++beg;
    }
}


//Non-Specific Functions:

ostream& operator<<(ostream& os, const Picture& picture){
    const Pic_base::ht_sz ht = picture.p->height();
    for (Pic_base::ht_sz i = 0; i != ht; ++i) {
        picture.p->display(os, i, false);
        os << endl;
    }
    return os;
}
  • 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-17T05:55:01+00:00Added an answer on June 17, 2026 at 5:55 am

    You declare the pure virtual function as taking a ofstream object by value, while all your subclasses define it as taking a reference to one.

    virtual void display(std::ostream, ht_sz, bool) const = 0;
    

    vs

    void display(std::ostream&, ht_sz, bool) const;
                             ^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.