Click here to Skip to main content
15,908,445 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: where can I find a tutorial about raw socket programming? Pin
George222-Apr-03 16:28
George222-Apr-03 16:28 
GeneralRe: where can I find a tutorial about raw socket programming? Pin
Phil Hamer22-Apr-03 17:14
Phil Hamer22-Apr-03 17:14 
GeneralC++ related Pin
John-theKing22-Apr-03 3:11
John-theKing22-Apr-03 3:11 
GeneralRe: C++ related Pin
Paul D'hertoghe22-Apr-03 3:39
professionalPaul D'hertoghe22-Apr-03 3:39 
GeneralRe: C++ related Pin
Jim Crafton22-Apr-03 4:41
Jim Crafton22-Apr-03 4:41 
GeneralOnWndMsg(),OnCommand(),OnCmdMsg() Pin
Member 25731522-Apr-03 2:31
Member 25731522-Apr-03 2:31 
GeneralRe: OnWndMsg(),OnCommand(),OnCmdMsg() Pin
David Crow22-Apr-03 5:26
David Crow22-Apr-03 5:26 
GeneralUnresolved Externals: Class Template Pin
yprog22-Apr-03 2:11
yprog22-Apr-03 2:11 
Can anybody see why this doesn't link? (VSC++v.6)Any help would be truly appreciated...

HEADER FILE:
-----------

// set.h
#ifndef _INTLIST_H
#define _INTLIST_H

#include <iostream>
#include <vector>
#include <cassert> // for assert fn.

using namespace std;

template <class eltype="">
class Set
{
public:
// constructor
Set(); // construct a list of length 0

// accessors
int length () const;
// return length of list
Eltype retrieve (int i) const;
// retrieve ith list element
// (first element is in position 1)
bool contains (Eltype elt) const;
// return true if list contains elt; else false.
void make_empty();
// modifiers
void add (Eltype elt);
// add elt to end of list
void sort ();
// sort list in increasing order
void display ();
// display list on ostream os

Set<eltype> operator+(Set<eltype> set2);


void position(Eltype element, vector<int>& p);

void remove(Eltype element);
int len; vector<eltype> Elts;
private:
// length of the list
// elements of the list
bool sorted; // true if list is sorted; false otherwise
}; // end Int_list class declaration

template <class eltype="">
Set<eltype>::Set()
: len(0), sorted(true) // initializer list
{ }


template <class eltype="">
void Set<eltype>::add (Eltype elt)
{
if (len >= Elts.size())
Elts.resize(Elts.size() + 8);
Elts[len] = elt;
len++;
sorted = sorted &&
(len==1 || elt >= Elts[len-2]);
sort();
}
template <class eltype="">
void Set<eltype>::make_empty()
{
set();
Elts.resize(0);
}
template <class eltype="">
int Set<eltype>::length() const
{ return len; }

template <class eltype="">
void Set<eltype>::display()
{
ostream os=cout;
if (length()==0) return;
os << Elts[0];
for (int i=1; i<length(); i++)
="" os="" <<="" '="" elts[i];
}

template="" <class="" eltype="">
Eltype Set<eltype>::retrieve (int i) const
{
assert (0 <= i && i < len);
return Elts[i];
}

template <class eltype="">
bool Set<eltype>::contains (Eltype elt) const
{
for (int i=0; i< length(); i++)
if (Elts[i]==elt)
return true;
return false;
}

template <class eltype="">
void Set<eltype>::sort()
{
if (sorted) return;
int ins_elt; // element to insert
int ssv_sz; // sorted subvector size
int i;
for (ssv_sz = 1; ssv_sz < length(); ssv_sz++)
{
ins_elt = Elts[ssv_sz];
for (i = ssv_sz-1; i>=0; i--)
{
if (ins_elt >= Elts[i])
break;
Elts[i+1] = Elts[i];
}
Elts[i+1] = ins_elt;
}
sorted = true;
}

template <class eltype="">
void Set<eltype>::position(Eltype element, vector<int>& p)
{
int j=0;
for(int i=0;i<len;i++)
{
="" if(element="=Elts[i]){
" p[j]="i;
" j++;}
="" }
}
template="" <class="" eltype="">
void Set<eltype>::remove(Eltype element)
{
for(int i=0;i<len;i++)
{
="" if(element="=Elts[i]){
" for(int="" j="i;j<(len-1);j++)
" elts[j]="Elts[j+1];
" elts[j+1]="0;
" len="len-1;
" i="i-1;}
" }
}

template="" <class="" eltype="">
Set<eltype> operator+(Set<eltype> set2)
{
Set<eltype> result;
int total_length=len+set2.length();
result.Elts.resize(total_length);
for(int i=0;i<len;i++)
{
="" result.elts[i]="Elts[i];
" }
="" for(int="" j="len;j<set2.length();j++)
" return="" result;
}
#endif


test="" file:
---------

="" tstlist0.cpp
#include="" <iostream="">
#include <vector>
#include "ordintlist.h"
using namespace std;
template <class eltype="">
ostream& operator<<(ostream& outs, Set<eltype>& set2);
int main()
{
vector<int> p(6);
Set<int> L;
Set<int> M;
Set<int> N;
cout << "L= ";
L.display(); cout << endl;
cout << L.length() << endl;
L.add(30);
L.add(25);
L.add(30);
L.add(99);
M.add(67);
M.add(58);
M.add(30);
M.add(99);
cout << "L= ";
L.display();
cout << endl;
M.display();
cout << L + M;
cout << endl;
cout << N;
/*cout << L.length() << endl;
L.remove(30);
L.position(25, p);
cout << p[0];*/

cout << endl;
return 0;
}
// overloaded operators
template <class eltype="">
ostream& operator<<(ostream& outs, Set<eltype>& set2)
{
cout << "{";
for(int i=0;i<set2.len;i++)
{
="" cout="" <<set2.elts[i];
="" if(i!="set2.len-1)
" <<",="" ";
="" }
="" <<="" "}";
="" return="" cout;
}

errors:
------

compiling...
tstlist0.cpp
linking...
tstlist0.obj="" :="" error="" lnk2001:="" unresolved="" external="" symbol="" "public:="" class="" set<int=""> __thiscall Set<int>::operator+(class Set<int>)" (??H?$Set@H@@QAE?AV0@V0@@Z)
Debug/finally3.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

finally3.exe - 2 error(s), 0 warning(s)
GeneralRe: Unresolved Externals: Class Template Pin
Hans Ruck22-Apr-03 3:35
Hans Ruck22-Apr-03 3:35 
GeneralProgrammatically click a CListCtrl row Pin
Snakebyte22-Apr-03 1:57
Snakebyte22-Apr-03 1:57 
GeneralRe: Programmatically click a CListCtrl row Pin
Rage22-Apr-03 5:14
professionalRage22-Apr-03 5:14 
GeneralRe: Programmatically click a CListCtrl row Pin
Anunay Kumar22-Apr-03 5:44
Anunay Kumar22-Apr-03 5:44 
GeneralPragmatically click a CListCtrl row Pin
Snakebyte22-Apr-03 1:55
Snakebyte22-Apr-03 1:55 
GeneralAudio file information Pin
viliam22-Apr-03 1:34
viliam22-Apr-03 1:34 
GeneralRe: Audio file information Pin
RaajaOfSelf22-Apr-03 2:08
RaajaOfSelf22-Apr-03 2:08 
GeneralHELP in ACCESS DATABASE Pin
RaajaOfSelf22-Apr-03 1:25
RaajaOfSelf22-Apr-03 1:25 
QuestionSAPI 5.0, how do I select other languages? Pin
Joan M22-Apr-03 0:31
professionalJoan M22-Apr-03 0:31 
GeneralHelp VC6 linker! Pin
Zoltan22-Apr-03 0:04
Zoltan22-Apr-03 0:04 
GeneralRe: Help VC6 linker! Pin
Neville Franks22-Apr-03 0:59
Neville Franks22-Apr-03 0:59 
Generalabout SetThreadDesktop Pin
lin_li_00021-Apr-03 22:40
lin_li_00021-Apr-03 22:40 
QuestionHow to give a run time struct definition Pin
gumber21-Apr-03 22:38
gumber21-Apr-03 22:38 
AnswerRe: How to give a run time struct definition Pin
Phil Hamer22-Apr-03 12:57
Phil Hamer22-Apr-03 12:57 
GeneralRe: how to input a xml file in vc++ project ? Pin
Joaquín M López Muñoz21-Apr-03 22:29
Joaquín M López Muñoz21-Apr-03 22:29 
Generaltvn_selchanging message Pin
JensB21-Apr-03 21:31
JensB21-Apr-03 21:31 
GeneralRe: tvn_selchanging message Pin
Phil Hamer22-Apr-03 13:00
Phil Hamer22-Apr-03 13:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.