0

Here is my Code...

class Obj
{
public : 
    int iNum = 100;
};

map<string, tuple<int,Obj*>> maplist;
auto pObj = new Obj();
auto pObj1 = new Obj();
maplist["hi"] = make_tuple( 100, pObj );
cout << maplist["hi"].first << endl; // Error !
cout << maplist["hi"].second << endl; // Error !

Error Msg : E0135 has no member

I want to program properties( .first, .second, third ... ). How can I operator overloading ? What can I do with it ? Is []operator in map ? Or Add properties in tuple ?

AKillUea
  • 145
  • 1
  • 1
  • 9
  • 1
    [`std::tuple`](https://en.cppreference.com/w/cpp/utility/tuple) is *not* like `std::pair`. – Some programmer dude Mar 15 '19 at 12:55
  • related/dupe: https://stackoverflow.com/questions/15835762/how-to-get-reference-to-an-element-of-a-stdtuple – NathanOliver Mar 15 '19 at 12:55
  • I know already not like std::pair. But I want to program like pair. I program to add properties as many as tuple elements.count. How do I do ? Is not possible ? – AKillUea Mar 15 '19 at 13:07
  • Did you read the linked reference? Did you check [its example](https://en.cppreference.com/w/cpp/utility/tuple#Example)? The example shows you three ways to get the "elements" from a tuple. Also, basic logic thinking should have you understand that you can't have members like `first` and `second` for a data-type without (theoretical) limits on the number of values it can store. – Some programmer dude Mar 15 '19 at 13:10
  • Your link example is very useful. But can't you do with tuple overloading ? – AKillUea Mar 15 '19 at 13:14
  • Of course you can, but then you first need to get the data from the tuple. Which is what seems to be your problem. – Some programmer dude Mar 15 '19 at 13:21
  • Possible duplicate of [How to get reference to an element of a std::tuple?](https://stackoverflow.com/questions/15835762/how-to-get-reference-to-an-element-of-a-stdtuple) – Artyer Mar 17 '19 at 15:03

0 Answers0