Toon posts:

[C++] hash_map-error

Pagina: 1
Acties:

Verwijderd

Topicstarter
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class CSocket;

#include <hash_map>
using namespace std;

struct eq
{
  bool operator () ( SOCKET s1, SOCKET s2 ) const
  {
    return (s1 == s2);
  }
};

hash_map<SOCKET, CSocket, hash<SOCKET>, eq> m_colSockets;


Dat heb ik, maar die geeft deze fout:
code:
1
2
3
4
5
6
c:\program files\common files\vc98\include\stl_pair.h(42) : error C2079: 'second' uses undefined class 'CSocket'
        c:\program files\common files\vc98\include\stl_function.h(335) : see reference to class template instantiation 'std::pair<unsigned int const ,class CSocket>' being compiled
        c:\program files\common files\vc98\include\stl_hashtable.h(231) : see reference to class template instantiation 'std::_Select1st<struct std::pair<unsigned int const ,class CSocket> >' being compiled
        c:\program files\common files\vc98\include\stl_hash_map.h(69) : see reference to class template instantiation 'std::hashtable<struct std::pair<unsigned int const ,class CSocket>,unsigned int,struct std::hash<unsigned int>,struct std::_Select1st<struct std::pair<unsigned int const ,class CSocket> >,struct eq,class std::__default_alloc_template<1,0> >' being compiled
        c:\c++ programs\maindll\csocket.h(27) : see reference to class template instantiation 'std::hash_map<unsigned int,class CSocket,struct std::hash<unsigned int>,struct eq,class std::__default_alloc_template<1,0> >' being compiled
CSocket.cpp


Wat ik daaruit begrijp is dat ie class CSocket niet kent... Maar toch zet ik die helemaal vanboven (dus als ik het goed heb is dat zeggen van die class bestaat, maar ik zal deze later definiëren).

Enig idee + misschien wat uitleg hoe op te lossen & waarom hij deze fout geeft?

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

Je declareert CSocket alleen, om 'm te kunnen gebruiken moet je 'm definieren. Sla je jargonwoordenboek maar vast open :)

Professionele website nodig?


Verwijderd

Topicstarter
aaaaaaaaaaah ja :)
tuurlijk!!!!

mercie :) (typedef right? :) )

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

Typedef lijkt me niet handig, ik zou gewoon de class definitie van CSocket includen :)

Professionele website nodig?


  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

Ter verduidelijking:
• Declareren = roepen dat het ding bestaat
• Definieren = roepen dat het ding bestaat en bepaalde methods/properties heeft
• Implementeren = zorgen dat method x code bevat.

Professionele website nodig?


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 12:02

.oisyn

Moderator Devschuur®

Demotivational Speaker

curry684 schreef op 09 May 2003 @ 13:45:
Ter verduidelijking:
• Declareren = roepen dat het ding bestaat
• Definieren = roepen dat het ding bestaat en bepaalde methods/properties heeft
• Implementeren = zorgen dat method x code bevat.
aanvulling in code:

C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// declaratie:
class MyClass;


// definitie:
class MyClass
{
public:
    void method ();
};


// implementatie
void MyClass::method ()
{
    std::cout << "hoi" << std::endl;
};


Bij puur gebruik van pointers en references is minstens de declaratie nodig. Als je de members wilt accessen, een nieuwe instantie wil maken (op de stack of heap) of wilt definieren als een member ergens van, dan is minstens de definitie nodig.

De implementatie hoeft vrijwel nooit bekend te zijn in de huidige compile-unit (natuurlijk wel meelinken met je project), tenzij het gaat om niet-geexporteerde templates

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

De implementatie hoeft vrijwel nooit bekend te zijn in de huidige compile-unit (natuurlijk wel meelinken met je project), tenzij het gaat om niet-geexporteerde templates
Inlines.

Professionele website nodig?


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 12:02

.oisyn

Moderator Devschuur®

Demotivational Speaker

Ow ja natuurlijk, even vergeten :)

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.

Pagina: 1