CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2009
    Posts
    2

    Error with function call.

    I'm writing a program for my CS class in which names are to be taken from a text file, put into Lastname, Firstname format, inserted into a list, and sorted. CStrings are to be used.

    The problem I've run into is when trying to call the function GetList on line 41. The compiler (Bloodshed Dev-C++, if this is relevant) generates a lengthy error related to ios_base.h

    I'm attatching the implementation file, header, and main program.

    I'm confused as to why this is happening, but I can't figure it out. If someone could help me, I would greatly appreciate it.


    Here is a copy/paste of the error.

    In copy constructor `std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)':
    738 C:\Dev-Cpp\include\c++\3.4.2\bits\ios_base.h `std::ios_base::ios_base(const std::ios_base&)' is private
    40 C:\Documents and Settings\Logar\Desktop\Program 4\Program4.cpp within this context
    40 C:\Documents and Settings\Logar\Desktop\Program 4\Program4.cpp In copy constructor `std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)':
    769 C:\Dev-Cpp\include\c++\3.4.2\streambuf `std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]' is private
    40 C:\Documents and Settings\Logar\Desktop\Program 4\Program4.cpp within this context
    C:\Documents and Settings\Logar\Desktop\Program 4\Program4.cpp In function `int main()':
    40 C:\Documents and Settings\Logar\Desktop\Program 4\Program4.cpp initializing argument 1 of `void GetList(std::ifstream, List&)'
    Attached Files Attached Files

  2. #2
    Join Date
    Dec 2008
    Posts
    56

    Re: Error with function call.

    This issue lies with the declarations of your functions. You really want to pass all of your parameters by reference, not by value. The error that you are getting is caused by your attempt to copy (ie. pass by value) the fstream object in GetList().

    Also, the main() function should be declared to return an int, not what you think the compiler thinks it ought to return. In other words, be specific.

    Lastly, use the STL string in lieu of char arrays; using the latter to read in variable length text makes your program look very amateurish and prone to bugs. For instance, consider what would happen if a name is longer than 30 bytes, or if a lastname/firstname combo is longer than 30 bytes.

    P.S. If you continue to use strcpy(), strcat() etc, include <cstring>.

  3. #3
    Join Date
    Aug 2008
    Posts
    112

    Re: Error with function call.

    String operations ending with _s are more secure
    hi,,,

  4. #4
    Join Date
    May 2009
    Posts
    2

    Re: Error with function call.

    It's working now, thanks for the advice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured