What is the meaning of this error?

This is the function where compiler gives error:
1
2
3
4
5
void addFileToDirectory(directory * dir, const file& f)
{
    dir->addFile(f);
    f.setParent(dir);
}

This is addFile function:
1
2
3
4
5
6
void directory::addFile(const file& f)
{
    file * temp = new file(f);
    files.insert(temp);
}

This is set parent function:
1
2
3
4
void file::setParent(directory * newparent)
{
    parent = newparent;
}

And this is the copy constructor of class file:
1
2
3
4
5
file::file(const file& otherfile)
{
    name = otherfile.name;
    parent = otherfile.parent;
}

And finally, this is the error compiler throws at me:
1
2
3
4
g++ -Wall -c -o functions.o functions.cpp
functions.cpp: In function 'void addFileToDirectory(directory*, const file&)':
functions.cpp:10:20: error: passing 'const file' as 'this' argument of 'void file::setParent(directory*)' discards qualifiers [-fpermissive]
make: *** [functions.o] Error 1
Last edited on
To me, it seems like your passing a file into addFileToDirectory which is a constant and you're trying to alter it.
Ohh, you are right :)
Topic archived. No new replies allowed.