-2

I'm working on an assignment that uses OMNeT++, Veins/Sumo. Although my question is not completely related to it, it might add some context. I'm familiar with programming, but having a little bit of trouble wrapping my head around the whole

The idea is that there is a network of cars, and all these cars are talking to eachother using messages. A message inlcudes the vehicle name, but also information about the current position/mobility of the car. This is where TraCIMobilitycomes in.

Ideally I would like to have all this information stored in the original class in the message, but I am running into some issues.

pointer/memory address idea when working with classes.

class InterVehicleMessage : public ::veins::DemoSafetyMessage
{
  protected:
    ::omnetpp::opp_string vehicleName;
    veins::TraCIMobility vehicle_mobility; <--- important
 
  private:
    void copy(const InterVehicleMessage& other);
 
  protected:
    bool operator==(const InterVehicleMessage&);
 
  public:
    //stuff
    virtual veins::TraCIMobility& getMobility();  <--- important
    virtual const veins::TraCIMobility& getMobility() const {return const_cast<InterVehicleMessage*>(this)->getMobility();}  <--- important
    virtual void setMobility(const veins::TraCIMobility& vehicle_mobility);  <--- important
};

This all looks fine and dandy, I assume it functions as intended aswell.

But then when I try to make define the setMobility class I run into some problems.

void InterVehicleMessage::SetMobility(const veins::TraCIMobility& vehicle_mobility)
{
  this->vehicle_mobility = vehicle_mobility;
}

This results in the error: InterVehicleMessage_m.cc:240:28: error: object of type 'veins::TraCIMobility' cannot be assigned because its copy assignment operator is implicitly deleted

I'm not familiar with C++ enough to really know what this means. Is there anyone who could hint me into the right direction? pastebin to TraCIMobility.h: https://pastebin.com/pGZEepxX

YourivdHeuvel
  • 97
  • 2
  • 8
  • 1
    You probably need to provide an appropriate move assignment operator for `veins::TraCIMobility`. – πάντα ῥεῖ Jul 10 '22 at 11:40
  • 6
    A member (or a member of a member etc) of `veins::TraCIMobility` is an object that can't be copied. So by implication `veins::TraCIMobility` can't be copied and therefore the compiler deletes its copy assignment operator . Investigate which member(s) of `veins::TraCIMobility` can't be copied and why. – Richard Critten Jul 10 '22 at 11:44
  • 2
    @RichardCritten Good advice, but that looks to be a big ask. OP, _why_ are you trying to copy that object? After a cursory glance, it looks like maybe you're not supposed to try. – Paul Sanders Jul 10 '22 at 11:51
  • 2
    Weird. The shown code fragments are woefully incomplete, but sufficiently express the high complexity and advanced nature of the underlying code base. There's operator overloading, virtual inheritance, etc... These are all moderate to advance C++ topics, so how does someone who's "not familiar with C++" end up to deal with this code? Can you provide some background as to the nature of your programming task? – Sam Varshavchik Jul 10 '22 at 11:52
  • @PaulSanders Using the information from the cars I need to calculate whether there is a gonna be a collision at some point. And the `TraCIMobility.h` has a perfect function called "PositionAt" which makes me able to calculate where the car will be and if the paths intersect. I could take all this data invidually, which would work. But ideally having just one class to reference would be easier. – YourivdHeuvel Jul 10 '22 at 11:53
  • 2
    @PaulSanders without a [mcve] all I can do is point OP where to start looking, if OP want to post one we can all look with them. – Richard Critten Jul 10 '22 at 11:55
  • @SamVarshavchik I am using one of the veins demo messages. I didn't really have to touch that fancy stuff, just add variables that are necessary for communication. – YourivdHeuvel Jul 10 '22 at 11:58
  • 2
    This doesn't explain the background for your need for this C++ library. The code snippet had a pointer to the web site it came from. It's a highly advanced, sophisticated C++ library, and obviously requires expert-level C++ knowledge to work with. I can't say that I'd expect something like that as a typical environment for someone who's "not familiar with C++" to be working with. The reason for this compilation error is not necesarily this class, but some other related class. Advanced C++ knowledge and understanding is needed to find the problematic class and figure out what to do next. – Sam Varshavchik Jul 10 '22 at 12:06
  • *Is there anyone who could hint me into the right direction?* -- C++ is one of the most complex languages out there. There is no *hint* -- the solution requires advanced knowledge of the language. There is no way a responsible team of programmers would hoist a library this sophisticated onto someone who doesn't have C++ experience -- that's plain nuts. If it's your sole project, then these libraries are meant for experienced C++ programmers, and not to be used as "learning material". – PaulMcKenzie Jul 10 '22 at 12:12
  • @PaulMcKenzie -- it's possible that this happens, unintentionally. See https://it.slashdot.org/story/22/06/25/1745219/are-google-programmers-the-new-next-next-finish-programmers -- after reading that, evaluate how likely that is the situation. – Sam Varshavchik Jul 10 '22 at 12:16
  • The goal of the assignment is to focus on algorithms to guide the cars. Is there a simpler tool out there to work with? Probably. But I don't get to decide that unfortunately. I've decided to dumb down the class, it's an ugly solutions but works as intended. That way I can focus on my algorithms:) – YourivdHeuvel Jul 10 '22 at 12:19

1 Answers1

1

I've decided to save the information necesarry from TraCIMobility in individual variables.

So:

double speed;
veins::Coord position;
veins::Heading direction;
veins::Coord nextPositions[7];

Instead of:

veins::TraCIMobility vehicle_mobility;

As @PaulSanders stated in the comment, this class is not supposed to be copied. Thanks everyone for their time and effort. Have a nice day.

YourivdHeuvel
  • 97
  • 2
  • 8