Thread: ambiguous function call error

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    126

    Question ambiguous function call error

    I am getting this error and I don't know why...could someone help?

    Code:
    #include <stdlib.h>
    #include <iostream>
    #include <vector>
    #include <string>
    #include <fstream>
    
    using namespace std;
    
    typedef unsigned long u_long;
    typedef unsigned short u_short;
    typedef unsigned char byte;
    
    class CFile
    {
    private:
    
    u_long    fsize, mode;
    char      name[256];
    fstream  *file;
    
    void   GetSize()
           {
               file->close();
               file->open(name, ios::in | ios::ate);
    
               fsize = file->tellg();
                		   
               file->close();
               file->open(name, mode);
           };
    
    public:
    
        CFile(char filename[256])
        {
            file = new fstream;
            strcpy(name, filename);
            mode = ios::in;
    
            file->open(name, mode);
    
            if( file->fail() )
            {
                cout <<"Could not open " <<name;
                exit(0);
            }
    
            GetSize();
        };
    
        CFile(char filename[256], u_long openmode)
        {
            file = new fstream;
            strcpy(name, filename);
            mode = openmode;
    
            file->open(name, mode);
    
            if( file->fail() )
            {
                cout <<"Could not open " <<name;
                exit(0);
            }
    
            GetSize();
        };
    
    u_long   size() {return fsize;};
    
    
       ~CFile()
       {
           file->close();
           delete file;
       };
    
    };
    When I try to compile this, I get the following error messages from MSVC++ 6

    Code:
    d:\bcc55\projects\readfile\readfile.h(42) : error C2668: 'open' : ambiguous call to overloaded function
    d:\bcc55\projects\readfile\readfile.h(53) : error C2668: 'open' : ambiguous call to overloaded function
    d:\bcc55\projects\readfile\readfile.h(70) : error C2668: 'open' : ambiguous call to overloaded function
    Any suggestions would be appreciated.

  2. #2
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Question

    What are you trying to do? Are you trying to read in a text file?

    If so:
    Code:
    #include <fstream>
    
    ...
    
    ifstream file;
    
    file.open("file name");
    ....
    
    
    file.close();
    Mr. C: Author and Instructor

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    Well I am just trying to create a file object that gives me a very simple interface and an easy way to output to the file, input from the file, and get the file's size. As you can probably tell, I don't have all of it's functionality implemented yet. But honestly, I don't really think what I am trying to do matters here, because I could do it in a different way that I know would work. I am just wondering why i get that error with that code.

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    try making the second parameter of open ios::openmode instead of long.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Do not include fstream and iostream in the same project. fstream includes iostream already.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  2. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM