Home > front end >  Expression must have class type but it has type "*shape"
Expression must have class type but it has type "*shape"

Time:04-08

I am trying to create a vector as show below:

std::vector<double> dimensions_data_vec{input_shape_pointer.get_dimensions()};

In this code, input_shape_pointer is a pointer to a shape such as a rectangle. A shape has dimensions associated with it, eg. length and width. I now have to create another, separate class which takes a pointer to a shape and accesses its dimensions. To do this I am using the code snippet.

The get_dimensions() function is a part of the shape class and returns the dimensions of a shape in a vector which has a type double.

My code issues the error

Expression must have class type but it has type "*shape" (please note the asterisk here)

My question is, how do I have get_dimensions() work on the shape before the vector is initialised so that there is no mismatch, and dimensions_data_vec just takes in the vector double of shape dimensions? I think there may be an issue with initializing a vector with another vector anyway, but I want to work on one problem at a time.

CodePudding user response:

If input_shape_pointer is a pointer to a shape then use -> instead of .. For example, the expression

input_shape_pointer.get_dimensions()

should be replaced by:

input_shape_pointer->get_dimensions()

Note the use of -> instead of . in the above expression

  • Related