奇怪的构造函数语法

时间:2019-07-08 12:39:21

标签: c++ struct constructor nfc mbed

我试图理解ARM Mbed的NFC EEPROM示例,但是作为C ++新手,我跌跌撞撞地采用了一些奇怪的C ++语法。我有一个带有此构造函数的类:

public class specie extends Fragment {

View v;

private RecyclerView myrecyclerview;
private List<specieList> lstspecie;


// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;

private OnFragmentInteractionListener mListener;



public specie() {
    // Required empty public constructor
}

/**
 * Use this factory method to create a new instance of
 * this fragment using the provided parameters.
 *
 * @param param1 Parameter 1.
 * @param param2 Parameter 2.
 * @return A new instance of fragment specie.
 */
// TODO: Rename and change types and number of parameters
public static specie newInstance(String param1, String param2) {
    specie fragment = new specie();
    Bundle args = new Bundle();
    args.putString(ARG_PARAM1, param1);
    args.putString(ARG_PARAM2, param2);
    fragment.setArguments(args);
    return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    lstspecie = new ArrayList<>();
    lstspecie.add(new specieList("Nile Tilapia", "Oreochromis niloticus", R.drawable.tilapia));
    lstspecie.add(new specieList("Ayungin (Silver Perch)", "Bidyanus bidyanus", R.drawable.ayungin));
    lstspecie.add(new specieList("Sugpo (Tiger Prawn)", "Penaeus monodon", R.drawable.hipon));
    lstspecie.add(new specieList("Hito (Catfish)", "Siluriformes", R.drawable.hito));
    lstspecie.add(new specieList("Giant Gourami", "Osphronemus goramy", R.drawable.giant));
    lstspecie.add(new specieList("Bangus (Milkfish)", "Chanos chanos", R.drawable.bangus));


    if (getArguments() != null) {
        mParam1 = getArguments().getString(ARG_PARAM1);
        mParam2 = getArguments().getString(ARG_PARAM2);

    }
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    v = inflater.inflate(R.layout.fragment_specie, container, false);
    myrecyclerview = (RecyclerView)v.findViewById(R.id.specie_recycleview);
    RecyclerViewAdapter recyclerAdapter = new RecyclerViewAdapter(getContext(), lstspecie);
    myrecyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
    myrecyclerview.setAdapter(recyclerAdapter);
    return v;
}


// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
    if (mListener != null) {
        mListener.onFragmentInteraction(uri);
    }
}

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    if (context instanceof OnFragmentInteractionListener) {
        mListener = (OnFragmentInteractionListener) context;
    } else {
        throw new RuntimeException(context.toString()
                + " must implement OnFragmentInteractionListener");
    }
}

@Override
public void onDetach() {
    super.onDetach();
    mListener = null;
}

/**
 * This interface must be implemented by activities that contain this
 * fragment to allow an interaction in this fragment to be communicated
 * to the activity and potentially other fragments contained in that
 * activity.
 * <p>
 * See the Android Training lesson <a href=
 * "http://developer.android.com/training/basics/fragments/communicating.html"
 * >Communicating with Other Fragments</a> for more information.
 */
public interface OnFragmentInteractionListener {
    // TODO: Update argument type and name
    void onFragmentInteraction(Uri uri);
}
}

据我了解,构造函数签名后class EEPROMExample : mbed::nfc::NFCEEPROM::Delegate { public: EEPROMExample(events::EventQueue& queue, NFCEEPROMDriver& eeprom_driver) : _ndef_buffer(), _eeprom(&eeprom_driver, &queue, _ndef_buffer), _queue(queue) { } 之后的参数用于将参数传递给父构造函数,但是this是委托结构的文档,它没有构造函数,也没有它的父结构。

有人知道该代码是什么意思吗?

0 个答案:

没有答案
相关问题