ambiguous function call error

This is a discussion on ambiguous function call error within the C++ Programming forums, part of the General Programming Boards category; I am getting this error and I don't know why...could someone help? Code: #include <stdlib.h> #include <iostream> #include <vector> #include ...

  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,136
    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, 10:09 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 09:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21