void deallocate中的xmemory0异常

时间:2016-03-20 14:43:40

标签: c++ access-violation

我的代码构建并运行正常,直到程序的实际结束时xmemory0的第909行出现问题。

void deallocate(pointer _Ptr, size_type _Count)
        {   // deallocate object at _Ptr, ignore size
        _Mybase::deallocate(_Ptr, _Count);
        }

我的代码是一个非常基本的Twitter客户端的开始,这个问题才真正发生在我开始构建我的类时。我99%肯定它与我的矢量有关,但我还没有用它做任何事情,所以我不确定。当我在线搜索此错误时,我无法找到任何类似的问题。当我使用twitcurl库时,要求任何人构建所有内容以编译我的代码是非常困难和不公平的,但这里只是让你可以看到我拥有的内容 这是我所有课程的头文件

#pragma once
#ifndef CLASSES_H
#define CLASSES_H
#include<string>
#include<vector>
#include"rapidjson/document.h"
#include"rapidjson/reader.h"
#include"rapidjson/writer.h"
#include"rapidjson/stringbuffer.h"
#include "rapidjson/rapidjson.h"
#include"rapidjson/prettywriter.h"
using namespace rapidjson;


class tweet {
public:
    tweet();
    ~tweet();
    std::string userName;
    std::string userid;
    std::string tweetData;

};
class timeline {
public:
    std::vector<tweet> tweets;
    timeline();
    ~timeline();
    void set_userTimeline(std::string);
};
class user:public timeline {

    public:
        user();
        std::string name;
        std::string screenName;
        std::string user_ID;
        timeline userTimeline;
        void loadUserData(std::string);
        std::string get_name();
        std::string get_screenName();
        std::string get_user_ID();
        void set_name(std::string);
        void set_screenName(std::string);
        void set_user_ID(std::string);
        ~user();
};

#endif /*CLASSES_H*/

我的实施档案

#include "classes.h"

tweet::tweet()
{

}
tweet::~tweet()
{

}

timeline::timeline()
{

}
timeline::~timeline()
{

}
void timeline::set_userTimeline(std::string)
{

}
user::user()
{

}
std::string user::get_name()
{
    return name;
}
std::string user::get_screenName()
{
    return screenName;
}
std::string user::get_user_ID()
{
    return user_ID;
}
void user::set_name(std::string n)
{
    name = n;
}
void user::set_screenName(std::string sn)
{
    screenName = sn;
}
void user::set_user_ID(std::string id)
{
    user_ID = id;
}

void user::loadUserData(std::string input)
{
    bool userLoaded = false;
    std::string json;
    json = input;
    Document d;
    d.Parse(json.c_str());
    assert(d.IsObject());
    assert(d.HasMember("id_str"));
    assert(d.HasMember("name"));
    assert(d.HasMember("screen_name"));
    assert(d["name"].IsString());
    assert(d["screen_name"].IsString());
    assert(d["id_str"].IsString());
    set_user_ID(d["id_str"].GetString());
    set_name(d["name"].GetString());
    set_screenName(d["screen_name"].GetString());


}
user::~user()
{

}

和我的主要

#include<string>
#include<iostream>
#include "twitcurl.h"
#include "curl/curl.h"
#include"classes.h"

FILE _iob[] = { *stdin, *stdout, *stderr };

extern "C" FILE * __cdecl __iob_func(void)
{
    return _iob;
}



int main(int argc, char *argv[])
{


    ///first screen login or exit

    std::string choice;
    std::cout << "Press" << std::endl << "1 to login" << std::endl << "2 to exit" << std::endl;
    std::cin >> choice;
    int intChoice = std::stoi(choice, nullptr);
    if (intChoice == 0)
    {
        return 0;

    }
    else if (intChoice == 1)


    {
        /*choice = "";
        intChoice = 0;*/
        std::string userName = "Jordash90";
        std::string passWord = "*******";
        /*std::cout << "Please enter your twitter username->" << std::endl;
        std::cin >> userName;
        std::cout << "Please enter your twitter password->" << std::endl;
        std::cin >> passWord;*/

        twitCurl twitterObj;
        std::string tmpStr, tmpStr2;
        std::string replyMsg;
        char tmpBuf[1024];

        /* Set twitter username and password */
        twitterObj.setTwitterUsername(userName);
        twitterObj.setTwitterPassword(passWord);

        //SETMYKEYS AND SECRET OAUTHSTUFF
        twitterObj.getOAuth().setConsumerKey(std::string("bHnCXjV*************47Jk"));
        twitterObj.getOAuth().setConsumerSecret(std::string("fmjE*********VrzK7JoZWg28NECB0Eu5xsAQxXbOYdjjA"));

        //
        std::string oAuthUrl;
        twitterObj.oAuthRequestToken(oAuthUrl);
        twitterObj.oAuthHandlePIN(oAuthUrl);

        twitterObj.oAuthAccessToken();

        std::string myAccessTokenKey;
        std::string myAccessTokenSecret;
        twitterObj.getOAuth().getOAuthTokenKey(myAccessTokenKey);
        twitterObj.getOAuth().getOAuthTokenSecret(myAccessTokenSecret);
        //save these for later
        std::ofstream tokenKeySave;
        std::ofstream tokenSecretSave;
        tokenKeySave.open("twitterClient_token_key.txt");
        tokenSecretSave.open("twitterClient_token_secret.txt");

        tokenKeySave.clear();
        tokenSecretSave.clear();

        tokenKeySave << myAccessTokenKey.c_str();
        tokenSecretSave << myAccessTokenSecret.c_str();

        tokenKeySave.close();
        tokenSecretSave.close();

        /////actually trying to do something with this 

        user currentUser;
        /* Account credentials verification */
        if (twitterObj.accountVerifyCredGet())
        {
            twitterObj.getLastWebResponse(replyMsg);

            currentUser.loadUserData(replyMsg);


            std::cout << "User name: " << currentUser.get_name() << std::endl;
            std::cout << "User ID: " << currentUser.get_user_ID() << std::endl;
            std::cout << "User screen name: " << currentUser.get_screenName() << std::endl;
            std::cout << "login successful! :) " << std::endl;
        }
        else
        {
            twitterObj.getLastCurlError(replyMsg);
            printf("\ntwitterClient:: twitCurl::accountVerifyCredGet error:\n%s\n", replyMsg.c_str());
        }
    }

    system("PAUSE");


    return 0;

};

1 个答案:

答案 0 :(得分:0)

问题是由于我没有将推文类声明为时间轴类。