Thread: Error: no appropriate default constructor available

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    Error: no appropriate default constructor available

    C++ can be quite confusing for me... Haven't touched this file in weeks and it has been compiling with no probs,now today after having been growing my project by modifying other classes, i get an error from a class which hasn't been modified and has been compiling

    here's part of the class

    Code:
    #include "Fleet.h"
    #include <fstream>
    #include <iostream>
    #include <algorithm>
    #include <conio.h>
    
    using namespace std;
    
    struct CAR_MAKE 
    { 
        string make; 
        string model;
    };
    
    Fleet::Fleet(): fleet() {}
    
    Fleet::CarFleet Fleet::getFleet()
    {
    	return fleet;
    }
    
    // ---------------------------------------------------------------
    // Implementing function to read fleet of cars from text file
    
    void Fleet::ReadFleetFromFile()
    {					
    	char filename[MAX_PATH] ;
    
    	puts("\n\nPlease enter the text file to open:\n");
    	cin >> filename;
    
    	istream fleetin; // Problem is here
    	fleetin.open (filename);
    
    	/* Ensure file was openned, otherwise send an error */
    	if ( fleetin.fail() )
    	{
    		puts("");
    		perror("ERROR! while trying to open file");
    		exit(1);
    	}
    	else
    	{
    		Car car;	
    		
    		// Read in fleet records
    		while ( !car.Read(fleetin) )
    		{
    			fleet.push_back(car);
    			SortAlpha();		
    		}
    		
    		// Did we read something?
    		if( fleet.size()==0) {
    			puts("\nData was unsuccessfully read !!...");
    		}
    		else
    			puts("\nProcessed reading...");
    	}
    
    	fleetin.close();
    
    }
    
    /* ERROR 
    
    : error C2512: 'std::basic_istream<_Elem,_Traits>' : no appropriate default constructor available
            with
            [
               _Elem=char,
               _Traits=std::char_traits<char>
            ]
    : error C2039: 'open' : is not a member of 'std::basic_istream<_Elem,_Traits>'
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>
            ]
    : error C2039: 'close' : is not a member of 'std::basic_istream<_Elem,_Traits>'
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>
            ]
    */
    I mean i never this problem, and this stream has been used this way

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by csonx_p View Post
    C++ can be quite confusing for me... Haven't touched this file in weeks and it has been compiling with no probs,now today after having been growing my project by modifying other classes, i get an error from a class which hasn't been modified and has been compiling

    here's part of the class

    Code:
    #include "Fleet.h"
    #include <fstream>
    #include <iostream>
    #include <algorithm>
    #include <conio.h>
    
    using namespace std;
    
    struct CAR_MAKE 
    { 
        string make; 
        string model;
    };
    
    Fleet::Fleet(): fleet() {}
    
    Fleet::CarFleet Fleet::getFleet()
    {
    	return fleet;
    }
    
    // ---------------------------------------------------------------
    // Implementing function to read fleet of cars from text file
    
    void Fleet::ReadFleetFromFile()
    {					
    	char filename[MAX_PATH] ;
    
    	puts("\n\nPlease enter the text file to open:\n");
    	cin >> filename;
    
    	istream fleetin; // Problem is here
    	fleetin.open (filename);
    
    	/* Ensure file was openned, otherwise send an error */
    	if ( fleetin.fail() )
    	{
    		puts("");
    		perror("ERROR! while trying to open file");
    		exit(1);
    	}
    	else
    	{
    		Car car;	
    		
    		// Read in fleet records
    		while ( !car.Read(fleetin) )
    		{
    			fleet.push_back(car);
    			SortAlpha();		
    		}
    		
    		// Did we read something?
    		if( fleet.size()==0) {
    			puts("\nData was unsuccessfully read !!...");
    		}
    		else
    			puts("\nProcessed reading...");
    	}
    
    	fleetin.close();
    
    }
    
    /* ERROR 
    
    : error C2512: 'std::basic_istream<_Elem,_Traits>' : no appropriate default constructor available
            with
            [
               _Elem=char,
               _Traits=std::char_traits<char>
            ]
    : error C2039: 'open' : is not a member of 'std::basic_istream<_Elem,_Traits>'
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>
            ]
    : error C2039: 'close' : is not a member of 'std::basic_istream<_Elem,_Traits>'
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>
            ]
    */
    I mean i never this problem, and this stream has been used this way
    Oh! flip, should be ifstream ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Utilizing another compiled program for a task.
    By kotoroshinoto in forum C Programming
    Replies: 6
    Last Post: 06-03-2008, 01:43 PM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. constructors
    By shrivk in forum C++ Programming
    Replies: 7
    Last Post: 06-24-2005, 09:35 PM
  4. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM
  5. Switching Default Buttons :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 07-02-2002, 04:08 PM