Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Got a Problem with abstract classes in my map Programm
Forum Updated to NodeBB v4.3 + New Features

Got a Problem with abstract classes in my map Programm

Scheduled Pinned Locked Moved Unsolved C++ Gurus
2 Posts 2 Posters 891 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • TrockzorT Offline
    TrockzorT Offline
    Trockzor
    wrote on last edited by
    #1

    Hello guys,

    i got a task from university, in which i should use a given abstract class in order to create and display a map with cities and streets.
    This is the given abstract class:
    /**
    ///
    #ifndef ABSTRACTMAP
    #define ABSTRACTMAP

    #include "city.h"
    #include "street.h"

    class AbstractMap {
    public:
    typedef std::vector<city *> CityList;
    typedef std::vector<Street *> StreetList;

    /// Adds the provided city to this map.
    virtual void addCity(city *) = 0;
    
    /** Adds the provided street to this map. If the cities linked by the street
     *  have not been added to this map before, the street is not added.
     *
     * Return true if the street has beed added.
     */
    virtual bool addStreet(Street *) = 0;
    
    /**
     * @brief Search for a city in this map by given name.
     * @param name
     * @return the city pointer, if city not found NULL
     */
    

    // virtual City* find_city(const QString city_name) const = 0;

    /**
     * @brief Search for streets in this map.
     * @param city where you want the street_list from
     * @return a list of all streets in this map connected to provided city.
     */
    

    // virtual StreetList get_street_list(const City* city) const = 0;

    /**
     * @brief Look for opposite city.
     * @param street
     * @param city
     * @return opposite city of the street. If city has no connection to street returns NULL.
     */
    

    // virtual City * get_opposite_city(const Street* street, const City* city) const = 0;

    /**
     * @brief Calculate the street length.
     * @param street
     * @return length of the street
     */
    

    // virtual double get_length(const Street* street) const = 0;
    };

    #endif // ABSTRACTMAP

    *//
    The next one is also given:

    #ifndef MAPIO_H
    #define MAPIO_H

    #include "abstractmap.h"

    /// This class adds Cities and Streeds to a Map.
    class MapIo
    {
    public:
    /// this method adds Cities and Streets to the provided Map.
    virtual void fillMap(AbstractMap &map) = 0;
    };

    #endif // MAPIO_H

    **This is the class used to add streets and cities to the map.

    Now my Problem**

    void MainWindow::on_pushButton_2_clicked()
    {
    MapIo::fillMap(&AbstractMap );
    }

    How can i give an &AbstractMap object from a class which is abstract so no object can be created from it? How can i solve this? The Parameters are given so i cant change them?

    Would be really nice if some one could help me.
    If you need further information just ask me.
    Regards

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Implement your own subclass of these abstract classes.

      From your code sample, it looks like you are fairly new to C++. You should first study the language basics before going further.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved