Click here to Skip to main content
15,911,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create dynamic name for object
for example:-
#include <iostream>
class W1 {....};
int main (){
string n;
cin>>n;
//here I want create object from class W1 and make it's name value of n
}

What I have tried:

I search about this but I don't found anything
Posted
Updated 28-Apr-20 3:53am
Comments
jeron1 28-Apr-20 9:57am    
I don't believe that its possible in C++, but I believe you could simulate it using std::map or std::unordered_map. Where you could save an object of a certain type and access it using an object of a different type (string in your case).

1 solution

It should look something similar to:

C++
#include <iostream>
#include <string>

class W1{
public:
   std::string Name;
};

int main(){
   W1 a;
   std::cin >> a.Name;

   std::cout << "The name of W1 is :" << a.Name;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900