You need to initliaze it. But if you would like to conditionally initialize it, you can do something like this:
MyObject& ref = (condition) ? MyObject([something]) : MyObject([something else]);
More Related Contents:
- When to use references vs. pointers
- When should I use the new keyword in C++?
- What is a reference variable in C++?
- How to “return an object” in C++?
- Pointer vs. Reference
- Can we reassign the reference in C++?
- Is null reference possible?
- How does a C++ reference look, memory-wise?
- One VS2010 bug ? Allowing binding non-const reference to rvalue WITHOUT EVEN a warning?
- C++11 auto: what if it gets a constant reference?
- how to initialize a constexpr reference
- Passing references to pointers in C++
- Should I pass an std::function by const-reference?
- C++ constant reference lifetime (container adaptor)
- C++ auto vs auto&
- What is a dangling reference? [duplicate]
- Is there a platform or situation where dereferencing (but not using) a null pointer to make a null reference will behave badly?
- Difference between const. pointer and reference?
- Two classes that refer to each other
- C++ Return value, reference, const reference
- Confusion about pointers and references in C++
- Returning non-const reference from a const member function
- Modifying reference member from const member function in C++
- Where ampersand “&” can be put when passing argument by reference?
- prolonging the lifetime of temporaries
- Why is a c++ reference considered safer than a pointer?
- STL map containing references does not compile
- What does it mean to return a reference?
- Meaning of *& and **& in C++
- Is returning references of member variables bad practice?