This is one of the many cases where the parser thinks that a variable declaration is a function declaration, try writing it as:
B b = A() ; // Now the compiler doesn't think that it's a function declaration
Pergunta
I expected to initialize object of B here, but instead I got function declaration:
#include <iostream>
using namespace std;
class A {};
class B {
public:
B(const A&) {
cout << "B: conversion constructor\n";
}
};
int main()
{
B b( A() ); //function declaration: B b( A(*)() );
b.test();
}
The output is: request for member 'test' in 'b', which is of non-class type 'B( A(*)() )'*
Why isn't the constructor invoked in this situation?
Solução
This is one of the many cases where the parser thinks that a variable declaration is a function declaration, try writing it as:
B b = A() ; // Now the compiler doesn't think that it's a function declaration