what you report is the class definition, in the definition as logic you need to specify the type(in this case the class) of the object you want inside the class. (EDIT + other typedef)
public:
std_msgs::Header header; //declare header of type std_msgs::Header
std::string encoding;
cv::Mat image;
to decalre (made know to the program that he need to reserve a memory space for an object) an object of class cv_bridge::CvImage
, you need to do:
cv_bridge::CvImage this_is_an_object; //declaring an object of type CvImgage
EDIT: in your case cv_bridge::CvImgPtr
is a shared_ptr
so a pointer ( typedef boost::shared_ptr<CvImage> CvImgPtr;
) so it need to be used like a pointer.
(simplified: a pointer is a variable that contain the memory address of another variable or object, pointer is a variable that point to another, used to reduce memory copying when pass object to function for example)
so: to declare an object you type the name of the class (EDIT the name of a pointer of the class in this case CvImgPtr
is a pointer for CvImage
) (the name is useful to the compiler that with this declaration know how the memory reserved need to be structed, accoding to class CvImage
definition) cv_bridge::CvImgPtr
followed by the name of the object you want (that is called in this case this_is_an_object
).
is like writing basic variable declaration (int j , double a, char f
)
doing cv_bridge::CvImgPtr.header.seq
has no meaning as you are mixing a variable declaration with invocation of name of an object of the class, and even a pointer in the half.
to call the object seq
you need to type this_is_an_object.header.seq
like if it is a struct.
struct foo{ //definition : teach the compiler how is made struct foo.
char bar;
};
foo aaa; //aaa is the name of the variable/object/instance of the struct
aaa.bar = "a"; //call the member bar of the struct and assign value "a"
std::cout<<aaa.bar; //print aaa.bar
similar in your case with classes:
class CvImage //definition
{
public:
std_msgs::Header header;
std::string encoding;
cv::Mat image;
};
cv_bridge::CvImage this_is_an_object; //declare the variable / object this_is_an_object of class cv_bridge::CvImage
std::cout<< this_is_an_object.header.seq; //access the value of seq from object header of object this_is_an_object,
//this_is_an_object is an object of class cv_bridge::CvImage
or:
typedef boost::shared_ptr<CvImage> CvImgPtr;
cv_bridge::CvImgPtr this_is_a_pointer_to_object;
std::cout<< (*this_is_a_pointer_to_object).header.seq;
equivalent to:
std::cout<< this_is_a_pointer_to_object -> header.seq;
the operator (*object).member
is equal to object->member