Reputation: 1245
Hi Everyone i have a class Foo having a fooAddress member variable
Code in foo.h
Class Foo
{
String fooAddress() const;
void setFooAddress(String fooAddress)
....
String m_fooAddress;
}
Code in foo.cpp
String Foo::fooAddress() const
{
return m_fooAddress;
}
void Foo::setFooAddress(String fooAddress)
{
m_fooAddress = fooAddress;
}
Now i have a FooList Class which has a list of foos
Code in FooList.h
class FooList
{
editFooList(Foo foo,int index);
...
private:
List<Foo> m_fooArray;
}
Now my code in FooList.cpp is
void FooList::editFooList(Foo foo, int index)
{
m_fooArray.at(index).setFooAddress(foo.fooAddress());
}
but i am getting the error error: C2662: 'void Foo::setFooAddress(String)' : cannot convert 'this' pointer from 'const Foo' to 'Foo &'
Since i have not defined editFooList as a const function,i am not sure why the compiler is complaining when i am trying to modify m_fooArray.Can someone please point me what i am doing wrong ?
Upvotes: 0
Views: 1205
Reputation: 1245
i changed my code to
void FooList::editFooList(Foo foo, int index)
{
m_fooArray[index].setFooAddress(foo.fooAddress());
}
and it is compiling now
Upvotes: 0