How to move or deep-copy when move/copy constructors are not avaibale?

-1

I wish to make a deep-copy or move the object in a std::vector but I am unable to do so. After looking the class implementation, their was no copy/move constructor. Using implicit move constructor is not helping as the object gets destroyed and I'm getting an exception.

Exception thrown at 0x00007FF96D780BE2 (snap7.dll) in SeimensPLC.exe: 0xC0000005: Access violation writing location 0x0000000000000000.

Unhandled exception at 0x00007FF96D780BE2 (snap7.dll) in SeimensPLC.exe: 0xC0000005: Access violation writing location 0x0000000000000000.

Implementation Class Definition (plc.hpp) :

class plc
{
private:
    std::vector<TS7Client>      client;   //doesn't works
    std::array<TS7Client,255>   clients;  //works
}

Code :

bool plc::connect_plc(const std::string& ip, std::uint8_t connectionType, std::uint16_t rack, std::uint16_t slot)
{
    try {
        TS7Client client;

        if (std::int32_t returnVal = client.SetConnectionType(connectionType)) //PG-PC : Programming Console type connection
        {
            LOG_ERROR << SrvErrorText(returnVal);
            return false;
        }
        if (std::int32_t returnVal = client.ConnectTo(ip.c_str(), rack, slot) not_eq EXIT_SUCCESS)
        {
            LOG_ERROR << SrvErrorText(returnVal);
            return false;
        }
        this->client.push_back(std::move(client));
        return true;
    }
    catch (const std::exception& ex)
    {
        LOG_FATAL << "Exception : " << ex.what();
    }
    return false;
}

bool plc::add_plc(const std::string& ip, const std::vector<config_table_struct>& config_list)
{

    if(!this->connect_plc(ip))
        return false;
    TS7CpuInfo cpu_info;
    this->client.at(0).GetCpInfo(&cp_info);
    this->client.at(0).GetCpuInfo(&cpu_info);
    spdlog::critical("CP Info : Max PDU Length : {}\nMax Connection : {}\nMax MPI bus : {}\nMax Bus Rate",
        cp_info.MaxPduLengt, cp_info.MaxConnections, cp_info.MaxMpiRate, cp_info.MaxBusRate);
    spdlog::critical("CPU Info : Module Type Name : {}\nSerial Number : {}\nAS Name : {}\nModule Name",
        cpu_info.ModuleName, cpu_info.SerialNumber, cpu_info.ASName, cpu_info.ModuleName);// <--- I get exception on this line
    return true;
}

Library Class Definition :

class TS7Client
{
private:
    S7Object Client;
public:
    TS7Client();
    ~TS7Client();
    int Connect();
    int ConnectTo(const char *RemAddress, int Rack, int Slot);
    int Disconnect();
};

Build Envireoment : x64 (_WIN64)

typedef unsigned __int64  uintptr_t;  //vadefs.h
typedef uintptr_t  S7Object;

Note - I don't want to use std::array because number of connection object (client) required is known only after reading database. The number won't ever reach 255.

c++
copy-constructor
move-semantics
deep-copy
move-constructor
asked on Stack Overflow May 27, 2019 by Dark Sorrow • edited May 27, 2019 by Dark Sorrow

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0