Hi, i am building 2 classes:
ChainItemBase --> the collection of item
CI --> any type derived from ChainItemBase class
ChainCollection --> the container of item(s)
here the working code.
written in c#.
please help me translate it to c++
i'm bit unfamiliar with c++
abstract class ChainItemBase
{
public string name;
public ChainItemBase next = null;
}
class ChainItemCollection<CI>
where
CI : ChainItemBase // CI must derived from ChainItemBase
{
public CI first = null;
public CI find(string name)
{
for (var find = first; find != null; find = find->next)
{
if (string.Compare(find.name, name) == 0) return find; // found
}
return null; // not found
}
}
c++ code (not working):
typedef char *tinyString;
protected:
class ChainItemBase {
public:
const tinyString name;
public:
ChainItemBase* next = nullptr;
};
protected:
template<typename CI>
class ChainCollection<CI> {
public:
CI* first = nullptr;
public: CI* find(const tinyString &name) {
for (CI *find = first; find != nullptr; find = find->next) {
if (strcmp(find->name, name) == 0)) return find; // found
}
return nullptr; // not found
}
};