class member is another class' object

前端 未结 2 439
别跟我提以往
别跟我提以往 2021-01-26 01:45

I am a new C++ user...

I have a question regarding how to declare a member of a class \"classA\" that is an object of another class \"classB\", knowing that \"classB\" h

2条回答
  •  别那么骄傲
    2021-01-26 02:20

    If you want a VideoCapture to be a member of the class, you don't want this in your class definition:

    VideoCapture myCapture (string videoFileName /* :  I am not sur what to put here */ )  ;
    

    Instead you want this:

    VideoCapture myCapture;
    

    Then, your constructor can do this:

    myClass::myClass (string PLEASE_GIVE_ME_A_BETTER_NAME)
    : myCapture(PLEASE_GIVE_ME_A_BETTER_NAME),
    videoFileName(PLEASE_GIVE_ME_A_BETTER_NAME)
    {
    }
    

提交回复
热议问题