Converting shared pointer to object

Write your question here.
Hi guys. I am working on an assignment and I only have to convert a shared pointer to an object to finish it. I am not supposed the change the parameter in these code. I just want to convert my shared_pointer spec to a TownSpec object.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void Inventory::add_city(std::string const& name, std::shared_ptr<const TownSpec> spec)
{
	Town new_city(name, spec);
	Town& i = find_city(spec); //check if the city already exists but takes
                                     //as parameter a TownSpec object
	if (i.get_name() != name)
	{
		_cities[_count] = new_city;
		_count++;
	}
}

Town Inventory::find_city(const TownSpec& otherSpec) const//returns just one city
{
	for (size_t i(0); i < _count; i++)
	{
		if (!(_cities[i].get_specification()->matches(otherSpec)))
			continue;

		return _cities[i];
	}
	return Town();
}
Last edited on
You can't convert a shared pointer to an object. You can use the shared pointer to get the object it's pointing at.

ere is how to get the object a pointer is pointing at:

*the_pointer

* is the dereference operator.
Topic archived. No new replies allowed.