Shreyas
Shreyas

Reputation: 1937

Error in the program with the private constructor

Even though I've never called function 'Bike::Bike(Bike *)' what is causing the error?

Error : Could not find a match for 'Bike::Bike(Bike *)'


#include<iostream.h>
#include<conio.h>

class Bike
{
    Bike()
    {
        cout<<"\nIn Bike const.";
    }

    public: static Bike * getBike();
};

Bike * Bike :: getBike()
{
    cout<<"\nIn getBike";
    return new Bike();
}

void main()
{
    Bike b = Bike::getBike();
}

Upvotes: 1

Views: 133

Answers (1)

P0W
P0W

Reputation: 47784

You are trying to convert from Bike* to non-scalar type Bike

But getBike() returns a pointer to Bike

So

Bike *b = Bike::getBike();
     ^ use pointer

Looks like you're using some decade old compiler may be Turbo C++

void main is not legal C++ use int main

Also, make sure you delete all memory allocated by new

Upvotes: 4

Related Questions