Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Constructors
Qt 6.11 is out! See what's new in the release blog

Constructors

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.1k 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.
  • M Offline
    M Offline
    magda
    wrote on last edited by
    #1

    Hi, When trying to run the program with these classes, the compiler says" No matching function to call Coordinate::Coordinate - I am not sure where are the mistakes:

    @#ifndef GPSCOORD_H
    #define GPSCOORD_H
    #include <QString>
    #include "coordinate.h"

    class GPSCoord :public Coordinate {
    public:
    GPSCoord();
    void setCoord(int d, int m, int s, char cd);
    QString toString(bool decimal) const;

    private:
    Coordinate latitude;
    Coordinate longitude;
    };
    #endif // GPSCOORD_H

    //coordinate.cpp
    #include <QString>
    #include "coordinate.h"
    #include <iostream>
    using namespace std;

    // constructor
    Coordinate::Coordinate(int d, int m, int s, char cd){
    degrees = d;
    minutes = m;
    seconds = s;
    cardinalDirection = cd;
    }
    //gpscoord.cpp
    #include <QString>
    #include "gpscoord.h"
    #include "coordinate.h"

    //no-arg constructor which initialize
    GPSCoord::GPSCoord(): Coordinate(0,0,0,'N'){}

    void GPSCoord::setCoord(int d, int m, int s, char cd){
    degrees = d;
    minutes = m;
    seconds = s;
    cardinalDirection = cd;

    //main.cpp
    #include <QTextStream>
    #include "coordinate.h"
    #include "gpscoord.h"
    #include <iostream>

    int main(){

        QTextStream cout(stdout);
        Coordinate coord1(20,25,23,'N');
        cout<<coord1<<endl;,
        coord1.degrees = (20);
        coord1.minutes = (21);
        coord1.seconds = (30);
        coord1.cardinalDirection = 'N';
        coord1.toString();
        coord1.toDecimal();
        coord1.toString();
    
        GPSCoord gpscoord1;
        gpscoord1.setCoord(15,30,29,'N');
        gpsCoord1.toString();
        gpscoord1.latitude = (25.23676);
        gpscoord1.longitude = (23.4567);
        //cout << strbuf.str;
    

    return 0;
    }

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      There is no default constructor for class Coordinate ... The Coordinate constructor expects values and creating a GPSCoord tries to create two Coordinate member variables without the arguments.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        magda
        wrote on last edited by
        #3

        I have added a default constructor, but now the compiler says int Coordinate::degrees are private in gpscoord.cpp. This is an assignment - the data members are private

        @//coordinate.cpp
        #include <QString>
        #include "coordinate.h"
        #include <iostream>
        using namespace std;

        // default constructor

        Coordinate::Coordinate():degrees(0),minutes(0),seconds(0),cardinalDirection('N'){};

        //gpscoord.cpp
        #include <QString>
        #include "gpscoord.h"
        #include "coordinate.h"
        #include <iostream>

        //no-arg constructor which initialize
        GPSCoord::GPSCoord(): Coordinate(degrees, minutes, seconds, cardinalDirection){}@

        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