我有一个班级
class MAC {
private :
int mac_address;
public:
int mac_access;
MAC() {mac_address = 10;}
MAC(int m_add,int m_axs):mac_address(m_add),mac_access(mac_access) {};
};
我想创建这个类的向量,并像这样进行初始化
int main()
{
C m_c;
std::cout<<m_c.m_a.a << std::endl;
MAC a(9,3),b(4,5);
std::vector<MAC> m_arr;
m_arr(4,5);
}
当我编译时,我收到此错误
constructor.cpp: In function ‘int main()’:
constructor.cpp:63:12: error: no match for call to ‘(std::vector<MAC>) (int, int)’
基本上我很困惑如何才能给出int
或char
的向量给出的大部分功能?
为了清除这种混乱,我希望我的班级表现得和我们这样做的时候一样
std::vector<int> a (4,100);
但目前我无法做到
std::vector<MAC> m_mac(4,100);
答案 0 :(得分:-3)
class MAC {
private :
int mac_address;
public:
int mac_access;
MAC(int arg_mac_address = 10):mac_address(arg_mac_address){}
MAC(int m_add,int m_axs):mac_address(m_add),mac_access(mac_access) {};
};
int main()
{
/*C m_c;
std::cout<<m_c.m_a.a << std::endl;*/
MAC a(9,3),b(4,5);
std::vector<MAC> m_arr(4, 5);
}