🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #1706

Rare C++ fout (std::map)

#1706
From: Aquila
Date: Wed, 15 Dec 2004 09:06
96 lines
3469 bytes
Voor een AI programma krijg ik heel rare fouten met onderstaande code. (Ik
weet dat het nogal lang is maar ik heb al heel hard gewerkt om het probleem
te verkleinen).

possiblestate.h:

#ifndef POSSIBLESTATE_H
#define POSSIBLESTATE_H

class PossibleState{
 public:
  PossibleState(bool);
  PossibleState();
  ~PossibleState();
  bool operator < (const PossibleState &) const; 
 private:
  bool turning;
};
#endif


possiblestate.cpp:

#include "possiblestate.h"
PossibleState::PossibleState(bool turninger):
 turning(turninger)
{}
PossibleState::PossibleState():
 turning()
{}
PossibleState::~PossibleState(){}
bool PossibleState::operator<(const PossibleState & state) const{
 return turning != state.turning;
}


onlinelrta.h:

#ifndef ONLINELRTA_H
#define ONLINELRTA_H
#include <string>
#include <map>
class OnlineLRTA{
 public:
  OnlineLRTA(std::string );
  void lrtaAgent();
};
#endif


onlinelrta.cpp:
#include "onlinelrta.h"
#include "possiblestate.h"
#include <iostream>

void OnlineLRTA::lrtaAgent() {
 PossibleState s(false);
 static std::map<const PossibleState,int>  H;
 if (H.find(s) == H.end()) H[s] = 5;
 
 H[PossibleState(true)] = 8;
 if (H.find(PossibleState(true)) != H.end()) std::cout << "ok\n";
 
 
 std::map<const PossibleState,int>  K;
 PossibleState s2(false);
 if (K.find(s2) == K.end()) K[s2] = 5;
 
 K[PossibleState(true)] = 8;
 if (K.find(PossibleState(true)) != K.end()) std::cout << "ok\n";
 
}


OnlineLRTA::OnlineLRTA(std::string str)
{
 std::map<const PossibleState,int>  H;
 H[PossibleState(true)] = 8;
 if (H.find(PossibleState(true)) != H.end()) std::cout << "ok\n";
}

int main(int argc, char** argv){
 OnlineLRTA lrta("test");
 lrta.lrtaAgent();
}

Gewoon uitvoeren geeft raar maar waar als resultaat 1 ok ipv 3, dat is dus
het probleem. Als ik nu in de method lrtaAgent de if (H.find(s) == H.end())
H[s] = 5; en idem voor K uitquote dan krijg ik opeens 3 keer ok: waarom?
Kan iemand hier enige duidelijkheid scheppen want ik begrijp echt niet
waarom dit is en het ligt bv. niet aan de compiler, ik heb het getest met
gcc �n icc.

Bedankt!
-- 
"May the source be with you"
Technical Details
Message-ID: <ZJKdne45LpA4YyLcRVnyvA@scarlet.biz>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.scarlet.biz!news.scarlet.biz.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: fcea4,f50cab2f57916087,start
X-Google-Thread: 107324,f50cab2f57916087,start
X-Google-Attributes: gidfcea4,gid107324,public
X-Google-Language: ENGLISH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.scarlet.biz!news.scarlet.biz.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 15 Dec 2004 03:06:45 -0600
From: Aquila <braempje@netscape.net>
Subject: Rare C++ fout (std::map)
Newsgroups: be.comp.programming,nl.comp.programmeren
Followup-To: be.comp.programming
Date: Wed, 15 Dec 2004 10:06:44 +0100
User-Agent: KNode/0.8.1
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8Bit
Message-ID: <ZJKdne45LpA4YyLcRVnyvA@scarlet.biz>
Lines: 96
NNTP-Posting-Host: 81.11.150.5
X-Trace: sv3-U8UAUVQlFNLXK07fiiDU9ajmp3n8j5Jn7xxaUpd1GsfOhEuzrY6eEbLhhlM1ESeb304Pcu1drDOuk+a!8RA6+yHE52JxLQ9qRqJl/oFGV1AR4GCVcApiLcPYLHepSAnIDcxKohwpFXpkspOeJXXGD6jv
X-Complaints-To: abuse@scarlet.be
X-DMCA-Complaints-To: abuse@scarlet.biz
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.20