Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ can one turn a string value into a type?
    primarykey
    data
    text
    <p>I am trying to write some generic code:</p> <pre><code>int _pID = _plant-&gt;getPlantInternalID(); std::string _plantName = getPlantBasedUponInternalID(_pID); </code></pre> <p><code>_plantName</code> returns a string of the plant, like <code>Broccoli</code></p> <p>but is there a way to do something like this:</p> <pre><code>for (int f=0; f &lt; _f.getPlants().size(); f++) { std::shared_ptr&lt;Plant&gt; sbas = _f.getPlants().at(f); std::shared_ptr&lt;_plantName&gt; sder2 = std::dynamic_pointer_cast&lt;_plantName&gt;(sbas); } </code></pre> <p>notice I am putting in <code>_plantName</code> but really I need to do something like:</p> <pre><code>std::shared_ptr&lt;Broccoli&gt; sder2 = std::dynamic_pointer_cast&lt;Broccoli&gt;(sbas); </code></pre> <p>what is needing to do something like this called and how do I accomplish it?</p> <p>UPDATE: I am just getting the ID based upon an internal ID I made up:</p> <pre><code>std::string HUDForStatus::getPlantBasedUponInternalID(int _id) { switch (_id) { case 114: // Asparagus return ASPARAGUS::plantName.c_str(); break; case 113: // Beets return BEETS::plantName.c_str(); break; case 115: // Bok Choy return BOKCHOY::plantName.c_str(); break; case 107: // Broccoli return BROCCOLI::plantName.c_str(); break; case 101: // Carrot return CARROT::plantName.c_str(); break; case 110: // Celery return CELERY::plantName.c_str(); break; case 103: // Corn return CORN::plantName.c_str(); break; case 116: // Eggplant return EGGPLANT::plantName.c_str(); break; case 102: // Green Beans return GREENBEANS::plantName.c_str(); break; ... &lt;snip&gt;... } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload