#creating an object from another class
21 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
I don't get what you are trying to do.
You can't assign a pointer of incompatible types
um so there is supposed to be 3 algorithm classes and all of them have select method in them and setalgorithm method is supposed to create an object of the selected class so that algorithm will be used
and this line were given to us like this so
this->algorithm = new AlgorithmSortHeap(k);
I dont get whats wrong
I think you are attempting assignment of a polymorphic type.
To understand what is going wrong we need to see more code.
We need to see:
a) the declaration of variable TestBed::algorithm
b) the declaration of class AlgorithmSortHeap
You must have
this->algorithm = new AlgorithmSortHeap(k);
What is TestBed::algorithm?
Show us the header file, please.
```cpp
int main() {
return 0;
}
```
do you mean this?
Yep, as suspected.
Your AlgorithmSortHeap is not a kind of SelectionAlgorithm.
There is no inheritance there, so no polymorphism.
well you could just inherit
but I would recommend Concepts instead if you're allowed to use them
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.