x不是名称空间的成员

问题描述 投票:1回答:1

我正在用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;

我认为这可能与包含项或名称空间有关。对我在做什么错误/潜在的解决方案有什么想法?

namespaces include c++-cli
1个回答
0
投票

我最后要做的是在UTF :: Callback之前删除projekt1 :::,并在我创建函数的回调中插入内联前端。解决了问题

© www.soinside.com 2019 - 2024. All rights reserved.