C++ error: no matching function for call to ''"
C++ error: no matching function for call to ''"
虽然这个问题之前在社区也有人问过,但是其他的case和我的不一样,他们的解决方案不能套用在我的case上
所以我有一个非常大的 header“rrc_nbiot.h”文件,其结构如下:
#include "rrc.h"
namespace asn1 {
namespace rrc {
...
// SystemInformationBlockType2-NB-r13 ::= SEQUENCE
struct sib_type2_nb_r13_s {
struct freq_info_r13_s_ {
bool ul_carrier_freq_r13_present = false;
carrier_freq_nb_r13_s ul_carrier_freq_r13;
uint8_t add_spec_emission_r13 = 1;
};
using multi_band_info_list_r13_l_ = bounded_array<uint8_t, 8>;
struct freq_info_v1530_s_ {
tdd_ul_dl_align_offset_nb_r15_e tdd_ul_dl_align_offset_r15;
};
// member variables
bool ext = false;
bool multi_band_info_list_r13_present = false;
bool late_non_crit_ext_present = false;
rr_cfg_common_sib_nb_r13_s rr_cfg_common_r13;
ue_timers_and_consts_nb_r13_s ue_timers_and_consts_r13;
freq_info_r13_s_ freq_info_r13;
time_align_timer_e time_align_timer_common_r13;
multi_band_info_list_r13_l_ multi_band_info_list_r13;
dyn_octstring late_non_crit_ext;
// ...
// group 0
bool cp_reest_r14_present = false;
// group 1
bool serving_cell_meas_info_r14_present = false;
bool cqi_report_r14_present = false;
// group 2
bool enhanced_phr_r15_present = false;
bool cp_edt_r15_present = false;
bool up_edt_r15_present = false;
copy_ptr<freq_info_v1530_s_> freq_info_v1530;
// sequence methods
SRSASN_CODE pack(bit_ref& bref) const;
SRSASN_CODE unpack(cbit_ref& bref);
void to_json(json_writer& j) const;
};
...
} // namespace rrc
} // namespace asn1
在上述结构中声明的成员函数“pack”在另一个文件中定义。 “rrc_nbiot.cc”
// SystemInformationBlockType2-NB-r13 ::= SEQUENCE
SRSASN_CODE sib_type2_nb_r13_s::pack(bit_ref& bref) const
{
/* some code */
return SRSASN_SUCCESS;
}
在我的主文件“main.cpp”中,我实例化了结构并尝试这样调用成员函数:
#include "srsran/asn1/rrc_nbiot.h"
struct asn1::rrc::sib_type2_nb_r13_s sib2;
struct asn1::rrc::sib_type2_nb_r13_s *sib2_ref = &sib2;
int main(int argc, char** argv)
{
uint8_t buf[1024];
uint32_t nof_bytes = 2;
asn1::bit_ref bref;
sib2_ref->pack(&bref);
...
编译时出现错误:
" error: no matching function for call to
‘asn1::rrc::sib_type2_nb_r13_s::pack(asn1::bit_ref*)’
sib2_ref->pack(&bref); "
尽管如您在 header 文件中所见,“pack”在“sib_type2_nb_r13_s”下明确声明。
结构的其他成员不是我可以毫无问题地访问和修改的函数,但是调用像“pack”这样的成员函数会给我这个错误。
感谢任何帮助
感谢评论中的@molbdnilo,我修复了错误。正如他所说。
当我调用成员函数时,在我的例子中我不应该将参数作为指针传递给它。
参数应该是这样的:
sib2_ref->pack(bref);
虽然这个问题之前在社区也有人问过,但是其他的case和我的不一样,他们的解决方案不能套用在我的case上
所以我有一个非常大的 header“rrc_nbiot.h”文件,其结构如下:
#include "rrc.h"
namespace asn1 {
namespace rrc {
...
// SystemInformationBlockType2-NB-r13 ::= SEQUENCE
struct sib_type2_nb_r13_s {
struct freq_info_r13_s_ {
bool ul_carrier_freq_r13_present = false;
carrier_freq_nb_r13_s ul_carrier_freq_r13;
uint8_t add_spec_emission_r13 = 1;
};
using multi_band_info_list_r13_l_ = bounded_array<uint8_t, 8>;
struct freq_info_v1530_s_ {
tdd_ul_dl_align_offset_nb_r15_e tdd_ul_dl_align_offset_r15;
};
// member variables
bool ext = false;
bool multi_band_info_list_r13_present = false;
bool late_non_crit_ext_present = false;
rr_cfg_common_sib_nb_r13_s rr_cfg_common_r13;
ue_timers_and_consts_nb_r13_s ue_timers_and_consts_r13;
freq_info_r13_s_ freq_info_r13;
time_align_timer_e time_align_timer_common_r13;
multi_band_info_list_r13_l_ multi_band_info_list_r13;
dyn_octstring late_non_crit_ext;
// ...
// group 0
bool cp_reest_r14_present = false;
// group 1
bool serving_cell_meas_info_r14_present = false;
bool cqi_report_r14_present = false;
// group 2
bool enhanced_phr_r15_present = false;
bool cp_edt_r15_present = false;
bool up_edt_r15_present = false;
copy_ptr<freq_info_v1530_s_> freq_info_v1530;
// sequence methods
SRSASN_CODE pack(bit_ref& bref) const;
SRSASN_CODE unpack(cbit_ref& bref);
void to_json(json_writer& j) const;
};
...
} // namespace rrc
} // namespace asn1
在上述结构中声明的成员函数“pack”在另一个文件中定义。 “rrc_nbiot.cc”
// SystemInformationBlockType2-NB-r13 ::= SEQUENCE
SRSASN_CODE sib_type2_nb_r13_s::pack(bit_ref& bref) const
{
/* some code */
return SRSASN_SUCCESS;
}
在我的主文件“main.cpp”中,我实例化了结构并尝试这样调用成员函数:
#include "srsran/asn1/rrc_nbiot.h"
struct asn1::rrc::sib_type2_nb_r13_s sib2;
struct asn1::rrc::sib_type2_nb_r13_s *sib2_ref = &sib2;
int main(int argc, char** argv)
{
uint8_t buf[1024];
uint32_t nof_bytes = 2;
asn1::bit_ref bref;
sib2_ref->pack(&bref);
...
编译时出现错误:
" error: no matching function for call to ‘asn1::rrc::sib_type2_nb_r13_s::pack(asn1::bit_ref*)’
sib2_ref->pack(&bref); "
尽管如您在 header 文件中所见,“pack”在“sib_type2_nb_r13_s”下明确声明。 结构的其他成员不是我可以毫无问题地访问和修改的函数,但是调用像“pack”这样的成员函数会给我这个错误。
感谢任何帮助
感谢评论中的@molbdnilo,我修复了错误。正如他所说。
当我调用成员函数时,在我的例子中我不应该将参数作为指针传递给它。 参数应该是这样的:
sib2_ref->pack(bref);