namespaces - x 不是命名空间的成员

标签 namespaces include c++-cli

我正在用 Windows 窗体做我的第一个 c++/CLI 项目。主要思想是制作一个图形界面,使用我从服务器获得的数据。我使用 curl 与服务器交谈,它给了我一个 json 字符串。然后我使用rapidJson。我是 C++ 新手,所以请耐心等待 noobie 错误。我的名为 Myform.h 的文件包括 skapakonto.h。我得到以下信息:

错误 C2039“UTF”:不是“Project1”第 149 行的成员

我收到错误的代码在名为 skapaKonto.h 的文件中

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^  e) {
    int httpCode(0);
    std::string readBuffer;
    //string* retval;
    if (curl) {
        String^ anamn = this->textBox1->Text;
        const char* url = "serverip/TP/Admin/funktioner/skapa.php";
        string param = "nyckel=iRxOUsizwhoXddb4&funktion=skapaAKonto&anamn=" + msclr::interop::marshal_as<std::string>(anamn) + "&tjanst=47&rollid=6";
        //string param = "nyckel=iRxOUsizwhoXddb4&funktion=skapaAKonto&anamn=BJORN&tjanst=47&rollid=6";
        const char *data = param.c_str();
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Project1::UTF::callback); //line 149, where error originates
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);

        ret = curl_easy_perform(curl);
        if (ret != CURLE_OK)
            Console::Write("fel på begäran");

        cout << readBuffer;
        curl_easy_cleanup(curl);

        const char* json = readBuffer.c_str();

        Document d;
        d.Parse(json);

        StringBuffer buffer;
        Writer<StringBuffer, Document::EncodingType, UTF8<> > writer(buffer);
        d.Accept(writer);
        const char* output = buffer.GetString();
        std::cout << output;

        MessageBoxA(NULL, output, "serversvar:", MB_OK | MB_ICONQUESTION);
    }
}
};

我有 2 个命名空间 Project1,每个文件中有 1 个。 MyForm.h 中包含命名空间 UTF。如果我将命名空间 UTF 的内容放在 skapakonto.h 中,我会收到与多次定义某些内容相关的错误(即使我将其命名为其他名称)。这是 skapaKonto.h 的顶部,我有包含:
#pragma once
#include <ctime>
#include <list>
#include <string>
#include <cmath>
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include <iostream>
#include <msclr\marshal_cppstd.h>
#include "rapidjson/encodings.h"
#define CURL_STATICLIB
#include <curl/curl.h>
#include <algorithm>
#include <codecvt>

namespace Project1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace rapidjson;
using namespace std;

我认为这可能是与包含或命名空间有关的错误。关于我做错了什么/潜在解决方案的任何想法?

最佳答案

最后我必须做的是在 UTF::Callback 之前删除 projekt1::,并将内联放在我创建函数的回调前面。这解决了问题

关于namespaces - x 不是命名空间的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59358416/

相关文章:

c++ - 头文件和命名空间有什么区别?

c - 在 C 中的同一行包含和编码

大型项目 (redux) 的 C++ header 策略

opencv - 将系统::绘图::位图^转换为::MAT

JSF 为组件声明定义自定义命名空间

c# - 在另一个文件中使用一个文件的方法

string - 从 std::string 转换为 String^

c# - 建议放置 make_public pragmas 的位置

TypeScript:命名空间与类

c# - 通过用户控件确定 JavaScript 文件是否已包含