Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
I don't know what construct 2 is, but I would do something like this:
[email protected]:~/Projects/genobj > cat main.cpp
#include <iostream>
#include <cstdlib>
int main()
{
srand(time(0));
std::cout << ((rand() % 2) ? "Object #1" : "Object #2") << std::endl;
return 0;
}
[email protected]:~/Projects/genobj > g++ main.cpp
[email protected]:~/Projects/genobj > for ((a=0; a < 10; a++)) do ./a.out; sleep 3; done
Object #2
Object #1
Object #2
Object #2
Object #1
Object #1
Object #1
Object #2
Object #2
Object #1
I've been digging a little into this constructor. There, I don’t remember exactly, but there seemed to be a random command. In general, we generate a random number 1 or 2, then we write "if the number is 1, then 1 object is created", otherwise "2 objects are created".
There is an awesome site with a live forum about this constructor. And a slightly outdated tutorial: c2community.ru/doc/tutorials.html .
If you don't find the answer in the tutorial, use the search on the forum or create a new topic with the question.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question