Linker error and no classes appear



Hi,

I have a question about visual C++ version 6. I am new to C++

I am trying to make work a program called Alphabet.cpp
from the book "Introduction to Computer Science" by
Lambert, Nance and Naps.

Chapter 7 refers to the files from the disk which
came with the book. Also at bottom of this posting.

To run the program Alphabet in VC++ I do the following...

1. File -> New -> Projects -> Win32 Console Application

2. Project Name: Alphabet
Location: d:\Brad
Platform: Win32

3. An Empty Project

Into the directory d:\Brad\Alphabet I copy the files which come with the
book:
Boolean.h
Strlib.h
Alphabet.cpp
Strlib.cpp

These files appear at the bottom of this email.

I then select Project -> Add to Project -> Files
and add the above four files to the project.

When I select Build -> Alphabet.exe

The programs compile with no errors, but they fail to link...

Linking...
LIBC.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Release/Alphabet.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Under the "ClassView", no classes appear. I think classes should appear
there - am I right?

I suspect I am making a basic error, but none of the VC++ books I have
explore such a simple setup. Any help much appreciated.

// Program file: alphabet.cpp

#include <iostream.h>
#include "boolean.h"
#include "strlib.h"

int main()
{ string word1, word2, temp;
cout << "Enter the first word: ";
cin >> word1;
cout << "Enter the second word: ";
cin >> word2;
if (word1 > word2)
{ temp = word1;
word1 = word2;
word2 = temp;
}
cout << word1 << " " << word2 << endl;
return 0;
}


// Library header file: boolean.h

#ifndef BOOL_H

#undef TRUE
#undef FALSE

const int TRUE = 1;
const int FALSE = 0;

typedef int boolean;

#define BOOL_H
#endif


// Class implementation file: strlib.cpp

// Implementation section

#include <string.h>
#include <assert.h>

#include "strlib.h"

string::string()
{
data[0] = '\0';
}

string::string(const char str[MAX_STRING_SIZE])
{
strcpy(data, str);
}

string::string(const string &str)
{
strcpy(data, str.data);
}

int string::length()
{
return strlen(data);
}

char string::nth_char(int n)
{
assert((n >= 1) && (n < MAX_STRING_SIZE));
return data[n - 1];
}

void string::append_char(char ch)
{
int length = strlen(data);

assert(strlen(data) < MAX_STRING_SIZE - 1);
data[length] = ch;
data[length + 1] = '\0';
}

boolean string::operator == (const string &str)
{
return strcmp(data, str.data) == 0;
}

boolean string::operator < (const string &str)
{
return strcmp(data, str.data) < 0;
}

boolean string::operator > (const string &str)
{
return strcmp(data, str.data) > 0;
}

boolean string::operator <= (const string &str)
{
return (strcmp(data, str.data) < 0) ||
(strcmp(data, str.data) == 0);
}

boolean string::operator >= (const string &str)
{
return (strcmp(data, str.data) > 0) ||
(strcmp(data, str.data) == 0);
}


boolean string::operator != (const string &str)
{
return strcmp(data, str.data) != 0;
}

string& string::operator = (const char str[MAX_STRING_SIZE])
{
strcpy(data, str);
return *this;
}

string& string::operator = (const string &str)
{
strcpy(data, str.data);
return *this;
}

istream& operator >> (istream &is, string &str)
{
is >> str.data;
return is;
}

ostream& operator << (ostream &os, const string &str)
{
os << str.data;
return os;
}



// Class definition file: strlib.h

#ifndef STRING_H

#include <iostream.h>

#include "boolean.h"

// Definition section

const MAX_STRING_SIZE = 21;

class string
{

public:

// Class constructor

string();
string(const char str[MAX_STRING_SIZE]);
string(const string &str);

// Function members

int length();
char nth_char(int n);
void append_char(char ch);
boolean operator == (const string &str);
boolean operator < (const string &str);
boolean operator > (const string &str);
boolean operator <= (const string &str);
boolean operator >= (const string &str);
boolean operator != (const string &str);
string& operator = (const char str[MAX_STRING_SIZE]);
string& operator = (const string &str);
friend istream& operator >> (istream &is, string &str);
friend ostream& operator << (ostream &os, const string &str);

protected:

// Data members

char data[MAX_STRING_SIZE];

};

#define STRING_H
#endif




.



Relevant Pages

  • Re: parser needed
    ... static int tokenlen(const char *str, ... str - string containing expression ... ignores white space between tokens ...
    (comp.programming)
  • implicit declaration of function error
    ... void func(string str) { ... void func2{ ... implicit declaration of function `int func' ... cannot pass objects of type `string' through `...' ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Why date do not construct from date?
    ... Why int form int, str from str, Decumal from Decumal can construct ... instead it creates an int from a string. ... constructor for the date object. ...
    (comp.lang.python)
  • Re: How to Return an array of strings in C (char**)
    ... int start=0; ... // to know the number of elements in the array ... The reason is that you fail to increment str. ... The you could have printed "here" before entering the main loop to see if you actually got there, then str + start to see where you go to in the string on each pass. ...
    (comp.lang.c)
  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)