c ++的间接级别不同

时间:2017-04-28 21:34:30

标签: c++

尝试编译时收到此错误消息:

  • 错误C2556:' int *加密(const BinaryBuffer&,const EncryptionKey&)':重载函数的区别仅在于来自' BinaryBuffer Encrypt的返回类型(const BinaryBuffer& ;,const EncryptionKey&)'

  • 错误C2040:'加密':' int *(const BinaryBuffer&,const EncryptionKey&)'与BinaryBuffer(const BinaryBuffer&,const EncryptionKey&)'

  • 的间接等级不同
  • 错误C2556:' char * Decrypt(const BinaryBuffer&,const EncryptionKey&)':重载函数的区别仅在于来自' BinaryBuffer Decrypt的返回类型(const BinaryBuffer& ;,const EncryptionKey&)'

  • 错误C2040:'解密':' char *(const BinaryBuffer&,const EncryptionKey&)'与BinaryBuffer(const BinaryBuffer&,const EncryptionKey&)'

  • 的间接等级不同

cpp文件:

#include "Encryption.h"
#include <algorithm>
#include <iterator>

#pragma intrinsic(_rotl8, _rotr8)

constexpr auto xorKeyLocation = 0;
constexpr auto numberOfBitsToRotateLocation = 1;

int* Encrypt(const BinaryBuffer& plainText, const EncryptionKey& key)
{
    const auto xorKey = key[xorKeyLocation];
    const auto numberOfBitsToRotate() = key[numberOfBitsToRotateLocation];
    const BinaryBuffer result;

    do
    {
        std::transform(
            plainText.begin(),
            plainText.end(),
            std::back_inserter(result),
            [&](const auto byte)
        {
            const auto xored = byte ^ xorKey;
            const auto shifted = _rotl8(xored, numberOfBitsToRotate);

            return shifted;
        });
    } while (0);

    return result;
}

char* Decrypt(const BinaryBuffer& cipherText, const EncryptionKey& key)
{
    const auto xorKey = key[xorKeyLocation];
    const auto numberOfBitsToRotate() = key[(std::vector<int>)numberOfBitsToRotateLocation];
    const BinaryBuffer result;

    std::transform(
        cipherText.cbegin(),
        cipherText.cend(),
        std::back_inserter(result),
        [&](const auto byte)
    {
        const auto shifted = _rotr8(byte, numberOfBitsToRotate);
        const auto xored = shifted ^ xorKey;
        return xored;
    });

    return result;
}

h file:

#pragma once

#include "Common.h"

BinaryBuffer Encrypt(const BinaryBuffer& plainText, const EncryptionKey& key);
BinaryBuffer Decrypt(const BinaryBuffer& cipherText, const EncryptionKey& key);

我做错了什么?

感谢。

1 个答案:

答案 0 :(得分:2)

函数的返回类型与标题中的声明不匹配。