Is there a way to define an object using a function in C++? : <p>I have a function that returns an object after defining it with a class. When I call the function and then attempt to do anything with the object, it tells me that the object is undefined. Is there any way to use a function on it's own and then use the objects defined in that function?</p>

<p>Example code (Assume class has no issues):</p>

<pre><code>Class1 ReturnObject() {
    Class1 Object1(1, 2);
    return Object1;
}



int main() {
    ReturnObject();
    cout &lt;&lt; Object1.ClassVariable1;
}
</code></pre>
