Jump to content
  • Advertisement
Sign in to follow this  
Denisius

lvalue error

This topic is 3620 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. When I try to compile a certain file, I get the following error:
Quote:
lvalue required as left operand of assignment
In the following piece of code:
			GET_PULLED_BY(GET_PULLING(ch), 0) = NULL;
		if (GET_PULLED_BY(GET_PULLING(ch), 1) == ch)
			GET_PULLED_BY(GET_PULLING(ch), 1) = NULL;

Share this post


Link to post
Share on other sites
Advertisement
Is GET_PULLED_BY looks like a function to me.

With:
GET_PULLED_BY(GET_PULLING(ch), 0) = NULL;

You try to asign NULL to that function. But you can't asign anything to functions.

Share this post


Link to post
Share on other sites
Quote:
Original post by JvdWulp
You try to asign NULL to that function. But you can't asign anything to functions.

He's not assigning anything to the function. He's assigning to the return value of the function. As DevFred said, if the return value is a reference (and a non-constant such), you can assign to it.

But that assumes C++, which was not stated in the original post. In fact, not much was stated at all, really.

Share this post


Link to post
Share on other sites
The entire function:

void extract_char(Creature ch) {
void display_statistics_to_char(Creature ch);

Creature k, temp;
Descr t_desc;
Object obj;
int i, freed = 0;

perform_dismount(ch);

if (GET_FED_ON_BY(ch)) {
GET_FEEDING_FROM(GET_FED_ON_BY(ch)) = NULL;
GET_FED_ON_BY(ch) = NULL;
}
if (GET_FEEDING_FROM(ch)) {
GET_FED_ON_BY(GET_FEEDING_FROM(ch)) = NULL;
GET_FEEDING_FROM(ch) = NULL;
}

if (GET_LEADING(ch)) {
GET_LED_BY(GET_LEADING(ch)) = NULL;
GET_LEADING(ch) = NULL;
}
if (GET_LED_BY(ch)) {
GET_LEADING(GET_LED_BY(ch)) = NULL;
GET_LED_BY(ch) = NULL;
}

if (GET_PULLING(ch)) {
if (GET_PULLED_BY(GET_PULLING(ch), 0) == ch)
GET_PULLED_BY(GET_PULLING(ch), 0) = NULL;
if (GET_PULLED_BY(GET_PULLING(ch), 1) == ch)
GET_PULLED_BY(GET_PULLING(ch), 1) = NULL;
GET_PULLING(ch) = NULL;
}

if (!IS_NPC(ch) && !ch->desc) {
for (t_desc = descriptor_list; t_desc; t_desc = t_desc->next)
if (t_desc->original == ch)
do_return(t_desc->character, NULL, 0, 0);
}
if (ch->in_room == NOWHERE) {
log("SYSERR: NOWHERE extracting char %s. (%s, extract_char)", GET_NAME(ch), __FILE__);
exit(1);
}
if (ch->followers || ch->master)
die_follower(ch);

/* Forget snooping, if applicable */
if (ch->desc) {
if (ch->desc->snooping) {
ch->desc->snooping->snoop_by = NULL;
ch->desc->snooping = NULL;
}
if (ch->desc->snoop_by) {
SEND_TO_Q("Your victim is no longer among us.\r\n", ch->desc->snoop_by);
ch->desc->snoop_by->snooping = NULL;
ch->desc->snoop_by = NULL;
}
}
/* transfer objects to room, if any */
while (ch->carrying) {
obj = ch->carrying;
obj_from_char(obj);
obj_to_room(obj, ch->in_room);
}

/* transfer equipment to room, if any */
for (i = 0; i < NUM_WEARS; i++)
if (GET_EQ(ch, i))
obj_to_room(unequip_char(ch, i), ch->in_room);

if (FIGHTING(ch))
stop_fighting(ch);

for (k = combat_list; k; k = temp) {
temp = k->next_fighting;
if (FIGHTING(k) == ch)
stop_fighting(k);
}

char_from_room(ch);

/* pull the char from the list */
REMOVE_FROM_LIST(ch, character_list, next);

if (ch->desc && ch->desc->original)
do_return(ch, NULL, 0, 0);

if (!IS_NPC(ch))
Crash_delete_crashfile(ch);
else {
if (GET_MOB_RNUM(ch) > -1) /* if mobile */
mob_index[GET_MOB_RNUM(ch)].number--;
free_char(ch);
freed = 1;
}

if (!freed && ch->desc != NULL) {
STATE(ch->desc) = CON_MENU;
display_statistics_to_char(ch);
SEND_TO_Q(MENU, ch->desc);
}
else { /* if a player gets purged from within the game */
if (!freed)
free_char(ch);
}
}


The code is C.

Share this post


Link to post
Share on other sites
No offense: I guess you really copied and pasted the code from somewhere without understanding it at all, because you would have recognized that we were not asking for that fuction, but rather for the definition of
GET_FEEDING_FROM(...)
and company.

Share this post


Link to post
Share on other sites
Sorry, I've missed that.

Here's the definition:

#define GET_PULLED_BY(obj, i) (i == 0 ? (obj)->pulled_by1 : (obj)->pulled_by2)



#define GET_PULLING(ch) ((ch)->char_specials.pulling)

Share this post


Link to post
Share on other sites
Should be possible if "...->pulled_by[12]" and "....pulling" are non-const references, or if you overloaded the assignment operators for their types. Plus "...->pulled_by[12]" must be of the same type.

Example:

#include <iostream>

struct Foo {
int &a;
int &b;
Foo (int& a, int& b) : a(a), b(b) {}
};

int main () {
int a, b;
Foo foo (a,b);
((1<2) ? foo.a : foo.b) = 0;
((1>2) ? foo.a : foo.b) = 1;
::std::cout << "a=" << foo.a << '\n';
::std::cout << "b=" << foo.b << '\n';
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!