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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:30:25+00:00 2026-05-30T14:30:25+00:00

I have a question about inheritance. From this source: gSpan.h struct Edge { int

  • 0

I have a question about inheritance. From this source:

gSpan.h

struct Edge {
    int from;
    int to;
    int elabel;
    unsigned int id;
    Edge(): from(0), to(0), elabel(0), id(0) {};
};
class Vertex
{
public:
    typedef std::vector<Edge>::iterator edge_iterator;

    int label;
    std::vector<Edge> edge;

    void push (int from, int to, int elabel)    //elabel代表edge label
    {
        edge.resize (edge.size()+1);
        edge[edge.size()-1].from = from;
        edge[edge.size()-1].to = to;
        edge[edge.size()-1].elabel = elabel;
        return;
    }
};

class Graph: public std::vector<Vertex> {
public:
    typedef std::vector<Vertex>::iterator vertex_iterator;

    Graph (bool _directed)
    {
        directed = _directed;
    };
    bool directed;

    Graph(): edge_size_(0), directed(false) {};
};

gSpan.cpp

std::istream &gSpan::read (std::istream &is)
{
    Graph g(directed);
    while (true) {
        g.read (is);
        if (g.empty()) break;
        TRANS.push_back (g);
    }
    return is;
}

graph.cpp

std::istream &Graph::read (std::istream &is)    
{
    std::vector <std::string> result;
    char line[1024];

    while (true) {

        if (result.empty()) {
            // do nothing
        } else if (result[0] == "t") {
                  ...
        } else if (result[0] == "v" && result.size() >= 3) {
            unsigned int id    = atoi (result[1].c_str());
            this->resize (id + 1);
            (*this)[id].label = atoi (result[2].c_str());
               ...

Why we can use (*this)[id].label in graph.cpp? (*this) is a Graph object…. if we want to use (*this)[id].label shouldn’t we have to declare std::vector<Vertex>?

  • 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-30T14:30:27+00:00Added an answer on May 30, 2026 at 2:30 pm
    class Graph: public std::vector<Vertex>
    

    This means that the Graph class inherited std::vector<Vertex>, so you can do anything with it that you’d be able to do if it were a vector. And so by creating an instance of Graph, you’re effectively declaring a new vector.

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

Sidebar

Related Questions

I have a question about using streams in .NET to load files from disk.
I have a question about locking. This doesn't have to be only about record
I have a question about using new[] . Imagine this: Object.SomeProperty = new[] {string1,
I have a question about this question . I posted a reply there but
I have a general question about inheritance in the .NET framework, lets say you
Hello i used of answer in this question : Create new class from a
I've got question about nested inheritance in C++. I have three classes: Base ,
I have a simple basic question about C# and inheritance. In the below example,
I have a question about the following code: class MyClass : private boost::noncopyable {
I have a question based on this question In the section http://www.parashift.com/c%2B%2B-faq-lite/private-inheritance.html#faq-24.3 the following

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.