C ++错误:没有匹配函数来调用'Track :: Track(char,char)'

时间:2013-10-17 02:30:53

标签: c++ class compiler-errors

我正在尝试将一维数组分配给我的默认构造函数,但我不断收到此错误消息。有没有办法为同一个类创建两个默认构造函数,一个没有参数,另一个带参数?

标题

#include <iostream>
#include <string>


using namespace std; 

#ifndef SUBWAY_H
#define SUBWAY_H


class Track
{
    public:
    //Default Constructor 
    Track();                      //error here 

    //Destructor 
    ~Track();

    //Member variables 
    char node_1; 
    char node_2; 
    bool visited; 
};


class Station
{
    public:
    //Default Constructor 
    Station();

    //Destructor 
    ~Station();

    //Member variables 
    char station_name; 
    int track_starting_ID;
    int track_size; 
};


class SubwaySystem
{
    public:
    //Default Constructor
    SubwaySystem();

    //Destructor 
    ~SubwaySystem();

    //Member variables 
    Track my_track[34];
    Station my_station[12];

    int count_routes; 
};



#endif

CPP

#include "subway.h"

SubwaySystem::SubwaySystem()
{
    my_track[0] = Track('a', 'b'); //error here 
    ...

}

1 个答案:

答案 0 :(得分:2)

我没有看到类Track的任何构造函数接受两个参数。因此,您将收到编译器错误。您需要为类Track定义一个2参数构造函数。

相关问题