0
class A
{
public:

};

class B
{
  public:
  operator A()
  {
   // code here
  }
};


int main ()
{
  A foo;
  B bar;
  foo=bar;
}

i am proceeding with this idea , that bar will typecast into A which will be assigned to foo as due to by default assignment operator in class A, but i receive error no proper conversion exist.

  • The whole program and your concept about **typecasting** is wrong is wrong. Please **research** about the subject before you ask a question. – Pavan Apr 16 '16 at 17:23
  • Class are **user defined** objects. They can't be **typecasted**.And **operator** is to overload an **operator** for an **object** of user defined **class**. Not as a **constructor**. – Pavan Apr 16 '16 at 17:27
  • i am typecasting object of class....... – Arslan Aslam Apr 16 '16 at 18:19
  • please explain it further – Arslan Aslam Apr 16 '16 at 18:24
  • default **data types** like int ,double,char,float,etc can be type casted because that is provided/included by/in compiler. But unexpected user defined object can't be typecasted as the compiler is not designed to take it. It gets very complicated it you want to write a code to typecast **n** number different object defined by **n** number of users. – Pavan Apr 17 '16 at 04:13
  • i need your email id............i want to discuss further issue – Arslan Aslam Apr 17 '16 at 16:31

0 Answers0