0

Although this question has been asked previously on the community, however, those other cases are different from mine, and their solutions cannot be applied in my case.

So I have a very big header "rrc_nbiot.h" file with the following struct:

#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

The member function "pack" that is declared in the struct above is defined in another file. "rrc_nbiot.cc"

// SystemInformationBlockType2-NB-r13 ::= SEQUENCE
SRSASN_CODE sib_type2_nb_r13_s::pack(bit_ref& bref) const
{
  /*  some code */
  return SRSASN_SUCCESS;
}

In my main file "main.cpp" I instantiate the struct and try to call the member function as such:

#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);
...

When I compile, I get the error:

" error: no matching function for call to ‘asn1::rrc::sib_type2_nb_r13_s::pack(asn1::bit_ref*)’
sib2_ref->pack(&bref); "

Although as you see in the header file "pack" is clearly declared under "sib_type2_nb_r13_s". Other members of the struct that are not functions I can access and modify without any problems, but calling the member functions like "pack" is giving me this error.

Any help is appreciated

  • 1
    You're trying to pass a `bit_ref*` to a function that takes a `bit_ref&`, which (fairly obviously) doesn't match. Perhaps you need to read about the differences between pointers and references in your favourite C++ book. – molbdnilo Jan 05 '22 at 12:42
  • 1
    You're passing a pointer whereas `asn1::rrc::sib_type2_nb_r13_s::pack` accepts a reference. – G.M. Jan 05 '22 at 12:42
  • Some questions from me : why create sib2 as a global? And why create a pointer to sib2, when you can use sib2 directly? You are adding compleixity where it is not needed. – Pepijn Kramer Jan 05 '22 at 12:45
  • @molbdnilo, no I am passing the reference &bref to the function – Abdallah Sheikh Jan 05 '22 at 12:55
  • @PepijnKramer, no reason I was just making different attempts to make things work. Nevertheless I tried to access the member function with both, using the instance "sib2", and a pointer to the instance "sib2_ref", both attempts gave the same error. – Abdallah Sheikh Jan 05 '22 at 12:57
  • I see :) Usually its best to only put the minimum code here to reproduce the problem. You pass the address of bref, thus a pointer. To pass references to a function you don't have to add the "&" , so the syntex should be : sib2.pack(bref). – Pepijn Kramer Jan 05 '22 at 13:01
  • @AbdallahSheikh No, `&bref` is a pointer; it applies the "address-of" operator `&`to `bref`, and the result is a `bit_ref*`. The ampersand, `&`, designates references when it is part of a type, like `bit_ref&`, not when it is part of an expression. This is all covered in detail in [good books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – molbdnilo Jan 05 '22 at 13:05
  • @molbdnilo, Thanks that resolved the problem. I just thought since the function `pack()` is declared with the argument `bit_ref& bref`, I thought that the ampersand **&** indicated I must pass the address to `bref`, and hence my failed attempts. Now the code compiles – Abdallah Sheikh Jan 05 '22 at 13:12

1 Answers1

0

Thanks to @molbdnilo in the comments, I fixed the error. It was as just as he said.

When I call the member function, I should not pass the argument it as a pointer in my case. The argument should be like this:

  sib2_ref->pack(bref);
ouflak
  • 2,458
  • 10
  • 44
  • 49