error: expected primary-expression before '*' token

i am getting an error that i cant figure out; nothing from google and textbook is useless for this. the error comes from this function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
std::string
ldu1::snapshot(uint16_t *decoded_lcw) const
{ 
   pickle p;
   if (lcf(uint16_t *decoded_lcw) == 0)
   {      
     p.add("duid", duid_str(uint16_t *decoded_lcw));
     p.add("nac", nac_str(uint16_t *decoded_lcw));
     p.add("mfid", mfid_str(uint16_t *decoded_lcw));
     p.add("tgid", tgid_str(uint16_t *decoded_lcw));
     p.add("source", source_str(uint16_t *decoded_lcw));
     return p.to_string();
   } 
   else if (lcf(uint16_t *decoded_lcw) == 0x03)
   {
     p.add("duid", duid_str(uint16_t *decoded_lcw));
     p.add("nac", nac_str(uint16_t *decoded_lcw));
     p.add("mfid", mfid_str(uint16_t *decoded_lcw));
     p.add("dest", destination_str(uint16_t *decoded_lcw));
     p.add("source", source_str(uint16_t *decoded_lcw));
     return p.to_string();
   }
}

declared like this in the .h :
1
2
3
4
5
   //make the snapshot() available to overload in this derived class
    using abstract_data_unit::snapshot;
   //return A string containing the fields to display.
   //The string is encoded as a pickled Python dictionary.
   virtual std::string snapshot(uint16_t *decoded_lcw) const;

and the errors:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
ldu1.cc: In member function 'virtual std::string ldu1::snapshot(uint16_t*) const':
ldu1.cc:163:21: error: expected primary-expression before '*' token
ldu1.cc:165:38: error: expected primary-expression before '*' token
ldu1.cc:166:36: error: expected primary-expression before '*' token
ldu1.cc:167:38: error: expected primary-expression before '*' token
ldu1.cc:168:38: error: expected primary-expression before '*' token
ldu1.cc:169:42: error: expected primary-expression before '*' token
ldu1.cc:172:26: error: expected primary-expression before '*' token
ldu1.cc:174:38: error: expected primary-expression before '*' token
ldu1.cc:175:36: error: expected primary-expression before '*' token
ldu1.cc:176:38: error: expected primary-expression before '*' token
ldu1.cc:177:45: error: expected primary-expression before '*' token
ldu1.cc:178:42: error: expected primary-expression before '*' token
ldu1.cc:181:1: warning: control reaches end of non-void function [-Wreturn-type]


totally stuck here. any help is much appreciated.
p.add("duid", duid_str(uint16_t *decoded_lcw));

Your syntax here (and all similar lines below it) makes no sense. You are declaring a function prototype in the middle of a function call.

If your intention was to CALL duid_str, the syntax for it is like this:

p.add( "duid", duid_str(decoded_lcw) );

Notice that you do not redeclare the parameter lists. You simply pass in the value you want to use as the parameter.
Thanks! yes i am trying to call these functions. but when i take out the pointer syntax i get:
1
2
3
4
ldu1.cc: In member function 'virtual std::string ldu1::snapshot(uint16_t*) const':
ldu1.cc:163:23: error: passing 'const ldu1' as 'this' argument of 'virtual uint16_t ldu1::lcf(uint16_t*)' discards qualifiers [-fpermissive]
ldu1.cc:172:28: error: passing 'const ldu1' as 'this' argument of 'virtual uint16_t ldu1::lcf(uint16_t*)' discards qualifiers [-fpermissive]
ldu1.cc:181:1: warning: control reaches end of non-void function [-Wreturn-type]

so either way i get an error??
Last edited on
error: passing 'const ldu1' as 'this' argument of 'virtual uint16_t ldu1::lcf(uint16_t*)' discards qualifiers


This error is because you have a const member function (snapshot) calling a non-const member function (lcf). This breaks const-correctness.

If lcf does not modify the object's state... then make it a const function.
Or if it does modify the state, you cannot call it from a const function... and you will have to change 'snapshot' to be non-const.

warning: control reaches end of non-void function


This is exactly what it says. You have a function that needs to return a value, but you do not end with a return statement.
i thought this part of it would return the appropriate pickle:
 
return p.to_string();

how exactly should i be doing this??
Thanks!!
You only return values inside of those if() blocks.

If neither of those if blocks execute (ie: if both conditions are false), the function ends without returning anything.
Last edited on
right right. is there a way to do an else return null ???
Well you have to return a string... because that's the function's return type. The closest thing to "null" for a string would be an empty string.

And yes... you can return that in an else statement. It's as easy as you think it is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
std::string yourfunction()
{
    if(...)
    { }
    else if (...)
    { }
    else  // else, return an empty string
        return "";
}

// Or... just do this....

std::string yourfunction()
{
    if(...)
    { }
    else if (...)
    { }

    return "";  // just return the empty string at the end of the function
}
ok ok i got it. thanks so much! love this site!!
Topic archived. No new replies allowed.