0

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 ?

8
  • 2
    Is your C++ reproduced in this posting accurately? Your code has foo:: rather than Foo::. Also I'm seeing QString rather than String in places. Are you using Qt instead of the STL? Commented Nov 18, 2014 at 0:09
  • also "editFooList(foo foo, int index);" should not compile. Commented Nov 18, 2014 at 0:09
  • "Foo"bar springs to mind. Commented Nov 18, 2014 at 0:13
  • Yes i am using Qt ,i have corrected everything now Commented Nov 18, 2014 at 0:13
  • 2
    Is List<> and alias for QList<>. QList.at() returns a const reference. Commented Nov 18, 2014 at 0:23

1 Answer 1

0

i changed my code to

void FooList::editFooList(Foo foo, int index) { m_fooArray[index].setFooAddress(foo.fooAddress()); } 

and it is compiling now

Sign up to request clarification or add additional context in comments.

1 Comment

This will copy the foo object, which doesn't seem very efficient.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.