Thread: what does this error mean?

  1. #1
    Unregistered
    Guest

    what does this error mean?

    The error:
    Code:
    CFileInfo.cpp: In method `CFileInfo::CFileInfo(const CFileInfo &)':
    CFileInfo.cpp:26: passing `const CFileInfo' as `this' argument of `void CFileInfo::getFileName(string *)' discards qualifiers
    CFileInfo.cpp:27: passing `const CFileInfo' as `this' argument of `size_t CFileInfo::getFileSize()' discards qualifiers
    And the function in question (it's a copy constructor):
    Code:
    CFileInfo::CFileInfo(const CFileInfo &CopySource)
    {
      CopySource.getFileName(&FileName);  // sets FileName equal to string FileName in CopySource
      FileSize = CopySource.getFileSize();  // sets FileSize equal to size_t FileSize in CopySource
    }  // end CFileInfo(CFileInfo const &CopySource)

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    getFileName() and getFileSize() need to be const.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Unregistered
    Guest
    It works now. . .can anyone tell me why?

  4. #4
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    You took CopySource as a const parameter, meaning that only const functions could be called on CopySource. When non-const member functions are called, a compiler error message is issued.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed