Error on getValue
I have written this class. This is not complete description of original class to make my problem statement concise i am giving what is required
template < class T>
class RB
{
class Child
{
members are Child are
T getValue() const , Child* getRightChild() const , Child* getLeftChild() const , void setLeftChild(Child *i_leftChild) , void setRightChild(Child *i_rightChild)
}
//Problematic function
void levelOrder(Child *root);
};
Can you point out why my compiler is saying "137 getValue' has not been declared "
template < typename T>
void RB< T>::levelOrder(Child *root)
{
std::vector< RB< int>::Child* > vec1 , vec2;
vec1.push_back(root);
vector< RB< int>::Child* >::iterator vec1start ,vec1end , vec2start, vec2end;
while(vec1.size() != 0 && vec2.size() != 0 )
{
vec1start = vec1.begin();
vec1end = vec1.end();
for( ; vec1start != vec1end ; ++vec1start)
{
std::cout<<"\n node value = "<< vec1start开发者_运维技巧->getValue();
I think i have not defined vector also correctly, my vector needs to hold inner class element, any help with that is also appreciated
One issue is that you are not initializing vec1start
. Also, why is RB
a template if you never use the template argument and only ever use RB<int>
? The error you get is because vec1start
is an iterator which when dereferenced returns a pointer; thus, you need to do (*vec1start)->getValue()
to do what you want.
精彩评论