zoukankan      html  css  js  c++  java
  • 程序莫名其妙地老死

    调了一天最后在网上有人给了答案

    ////////////////////////////////////////////////////main.cpp
            #include <iostream>
            #include<vector>
            #include "CPath.h"
            using namespace std;
            int main()
            {
            for(int i = 0;i<10;++i){
            cout<<i;
            CPath path1;

        CPath path2;
        cross(path1,path2);
        path1.updatePathInfo();//这就是那个空函数,删掉就好了
        path2.updatePathInfo();

        }
        }
        //////////////////////////////////////////////////////////////CPath.h
        #ifndef CPATH_H_
        #define CPATH_H_
        #include<iostream>
        #include<vector>
        #include<fstream>
        #include<map>
        #include<cmath>
        #include<cstdlib>
        class CPath
        {
        public:
        CPath();
        friend void cross(CPath & path1,CPath & path2);
        void updatePathInfo();
        std::vector< int > getPathByCode();
        void createRadomCode();
        std::vector< int > code;
        double pathLineLength;
        };
        #endif //CPATH_H_
        //////////////////////////////////////////////////////////////////////CPath.cpp
        #include"CPath.h"
        CPath::CPath(){
        createRadomCode();
        }
        void cross(CPath & path1,CPath & path2){
        int max,min;
        max = rand()%8;
        min = rand()%8;
        if(min > max){max ^= min;min ^= max;max ^= min;}
        if(0.9*100>rand()%100){
        for(int i = min;i<=max;++i){
        path1.code[i]^=path2.code[i];
        path2.code[i]^=path1.code[i];
        path1.code[i]^=path2.code[i];
        }
        }
        }
        void CPath::updatePathInfo(){
        getPathByCode();
        }
        std::vector< int > CPath::getPathByCode(){
        }
        void CPath::createRadomCode(){
        for(int i = 0 ; i<8 ; ++i){
        code.push_back(rand()%(i+1));
        }
        }


    原因是getPathByCode有返回类型但是没有返回值。

  • 相关阅读:
    gTest&gMock learning
    机器学习 delay learning
    c++ learning
    2017 湘潭邀请赛&JSCPC G&J
    mapreduce&GFS&bigtable learning
    golang learning
    高斩仙的北京历险记
    python learning
    Codeforces Round #448 (Div. 2) B
    python之callable
  • 原文地址:https://www.cnblogs.com/maplewizard/p/2942039.html
Copyright © 2011-2022 走看看