首页 > 解决方案 > 重复类型中的方法声明不一致

问题描述

我在 c++-cli 中创建一个类,并为我的一个函数添加了一个额外的参数。额外参数的名称是 int row,当我添加时,我得到了这个错误:

LNK2022 元数据操作失败 (80131187):重复类型中的方法声明不一致(类型:查询;方法:Read_DB)

当我删除我添加的额外参数时,错误就消失了。如果我删除参数 column_index,它也会消失。但是,如果我删除其中一个 String^ 参数,它仍然存在。我不确定错误是什么,这是我的 .h 和 .cpp 代码文件中的函数定义:

标题:

#ifndef DATA_BASE
#define DATA_BASE

using namespace System;
using namespace System::Data::SqlClient;

ref class ConnectDB{
protected:
    SqlConnection^ cnn;
    bool state;

public:
    String^ db;

    bool ConnectDataBase();
    bool DisconnectDataBase(void);
};

ref class Query : public ConnectDB {
private:
    ~Query(void);
public:
    bool Create_Table(String^ name, String^ columns);

    String^ Read_DB(String^ column, String^ table, int column_index, int row);
    bool Write_DB(String^ path, String^ msg);
};

#endif 

cpp文件:


String^ Query::Read_DB(String^ column, String^ table, int column_index, int row) {
    String^ output;
    String^ sql = "SELECT " + column + " FROM " + table;

    try {
        SqlCommand^ command;
        SqlDataReader^ dataReader;


        command = gcnew SqlCommand(sql, cnn);
        dataReader = command->ExecuteReader();

        std::cout << "Reading data from Database...\n";

        int counter;
        while (dataReader->Read()) {
            counter++;

            if(counter == row)
                output = (String^)dataReader->GetValue(column_index);
        }

        //command->Dispose();
        dataReader->Close();
    }
    catch (Exception^ e) {
        Console::WriteLine(e);

        std::cout << "Failed to query database\n";
        return "0";
    }

    return output;
}

标签: c++-cli

解决方案


为了解决这个问题,我刚刚删除了调试文件夹并重新启动了我的应用程序。它与更改对象的名称有关。


推荐阅读