fork(1) download
  1. #include <memory>
  2.  
  3.  
  4. struct IMoo {};
  5. struct MooA : public IMoo {};
  6. struct MooB : public IMoo {};
  7.  
  8. class Foo
  9. {
  10. public:
  11. Foo() : m_moo(false ? std::make_shared<MooA>() : std::make_shared<MooB>())
  12. {
  13. }
  14. private:
  15. std::shared_ptr<IMoo> m_moo;
  16. };
  17.  
  18.  
  19. int main() {
  20. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In constructor ‘Foo::Foo()’:
prog.cpp:11:77: error: no match for ternary ‘operator?:’ (operand types are ‘bool’, ‘std::shared_ptr<MooA>’, and ‘std::shared_ptr<MooB>’)
     Foo() : m_moo(false ? std::make_shared<MooA>() : std::make_shared<MooB>())
                                                                             ^
prog.cpp:11:77: note: candidate is:
prog.cpp:11:77: note: operator?:(bool, int, int) <built-in>
prog.cpp:11:77: note:   no known conversion for argument 2 from ‘std::shared_ptr<MooB>’ to ‘int’
stdout
Standard output is empty