Reputation: 1360
To save some space in my code, I made this typedef:
typedef clients.members.at(selectedTab) currentMember;
however, g++ gives me this error:
error: expected initializer before '.' token
I figure that I'm misusing typedef, since clients.members.at(selectedTab)
is a function call and not a type. Is there a way to do what I'm trying to do here?
Upvotes: 1
Views: 438
Reputation: 146930
In C++0x, you can do
decltype(clients.members.at(selectedTab)) currentMember(clients.members.at(selectedTab));
However, what you're doing is fundamentally not possible. You're trying to get a value and make it a type. That's just not doable. Consider the following code:
typedef clients.members.at(selectedTab) currentMember;
currentMember a;
What on earth is a, and what does it do? You're going to have to explain more what you want.
Upvotes: 1
Reputation: 98984
If this is used function-local and neither clients.members
nor selectedTab
change between its uses, just use references. E.g.:
Member& currentMember = clients.members.at(selectedTab);
currentMember.foo();
currentMember.bar();
Upvotes: 5
Reputation: 237060
You seem to be trying to create a macro.
#define currentMember clients.members.at(selectedTab)
Though depending on how it's used, a simple function could be much better.
Upvotes: 3