小编Yan*_*oor的帖子

list :: sort更改值c ++

我在c ++中编写了一个不起作用的简单算法.我发现当我从我自己制作的自定义类中排序指向对象的列表时,它们会发生变化.或者更确切地说,列表更改为该类中的奇怪随机对象.

// ConsoleApplication45.cpp : Defines the entry point for the console application.
//


#include "stdafx.h"
#include <iostream>  
#include <map>
#include <list>
#include <math.h> 
using namespace std;  

class LocationNode;
class NodeMap;


class LocationNode
{
private:
    char name;
    int xLocation;
    int yLocation;
    //map<LocationNode*,int> neighbors;
    LocationNode* neighbors[100];
    int neighborWeight[100];
    int neighborCount; 
    LocationNode *previous;
    int score;

    int CalcDistance(LocationNode &dest)
    {
        return (int)sqrt(pow(dest.xLocation-xLocation,2) + pow(dest.yLocation-yLocation,2));
    }

public:
    int finalScore;

    bool operator<(LocationNode const& rhs) const
    {
       // Use whatever makes sense for your application.
       return …
Run Code Online (Sandbox Code Playgroud)

c++ sorting visual-studio

0
推荐指数
1
解决办法
107
查看次数

标签 统计

c++ ×1

sorting ×1

visual-studio ×1