What does this nameless object of class mean?

1
2
3
4
5
6
7
8
9
#include <SFML/Graphics.hpp>


int main()
{

sf::Vector2i(30,50);
return 0;
}


As you can see, this compiled. How would I manipulate it if it doesn't have a identifier?
Why not just give it a name?
1
2
3
...
sf::Vector2i v(30,50);
...
Because I would rather manipulate it anonymously.
sf::Vector2i(30,50);

isn't creating a variable it's just saying "Here's a Vector2i with these values"

It's simular to writing int 26;

So you need to do what Duoas said.

sf::Vector2i v(30,50);
is like saying "Assign me some memory for a Vector2i with these values" allowing it to be manipulated.

What is it you mean by manipulate anonymously?
The only way to manipulate anonymously is to do the whole thing in a single statement:

1
2
3
4
5
6
7
8
#include <iostream>
#include <string>

int main()
{
    std::cout << (std::string("This is a ") + "test.").replace(5, 2, "was") << std::endl;
    return 0;
}


The above manipulates the string objects anonymously. Note that these are called temporary objects and die once the statement is over.
Topic archived. No new replies allowed.