Problem with inheritance

From: ---- (no_at_mail.com)
Date: 05/31/04


Date: Sun, 30 May 2004 20:07:05 -0500

Here are my files (problem follows the code):
--------------------------------------------------------------------------
// Group.h

#ifndef GROUP_H
#define GROUP_H

class Group {

public:
 // default constructor
 Group(string groupName = "BLANK");

 void setName(string name);
 string getName();

protected:
 string name;

};

#endif
---------------------------------------------------------------------------
//Group.cpp

#include <string>
using std::string;

#include "Group.h"

// default constructor
Group::Group(string groupName)
 :name(groupName)
{

}

void Group::setName(string name)
{
 this->name = name;
}

string Group::getName()
{
 return this->name;
}
--------------------------------------------------------------
//Area.h

#ifndef AREA_H
#define AREA_H

#include "Group.h"

class Area : public Group {

public:
 Area(string areaName = "BLANK", int population = 0);

 void setPopulation(int population);
 int getPopulation();

protected:
 int population;

};

#endif
----------------------------------------------------------------------------

----
//Area.cpp
#include "Area.h"
Area::Area(string areaName, int population)
 : Group(areaName), population(population)
{
}
void Area::setPopulation(int population)
{
 this->population = population;
}
int Area::getPopulation()
{
 return this->population;
}
----------------------------------------------------------------------------
-----
OK, I'm working on a larger project, but I was having problems with
inheritance. This is a stripped down example that I still can;t get to work.
I'm compiling it with Visual C++ 6.0. When I try to compile the above files,
I get the following:
\group.h(10) : error C2629: unexpected 'class Group ('
\group.h(10) : error C2238: unexpected token(s) preceding ';'
\group.h(12) : error C2061: syntax error : identifier 'string'
\group.h(13) : error C2146: syntax error : missing ';' before identifier
'getName'
\group.h(13) : error C2501: 'string' : missing storage-class or type
specifiers
\group.h(16) : error C2146: syntax error : missing ';' before identifier
'name'
\group.h(16) : error C2501: 'string' : missing storage-class or type
specifiers
\group.h(16) : error C2501: 'name' : missing storage-class or type
specifiers
\area.h(11) : error C2629: unexpected 'class Area ('
\area.h(11) : error C2238: unexpected token(s) preceding ';'
\area.cpp(5) : error C2065: 'string' : undeclared identifier
\area.cpp(5) : error C2146: syntax error : missing ')' before identifier
'areaName'
\area.cpp(5) : error C2350: 'Area::Area::Area' is not a static member
\area.cpp(5) : error C2059: syntax error : ')'
\area.cpp(6) : error C2065: 'population' : undeclared identifier
\area.cpp(6) : error C2448: '<Unknown>' : function-style initializer appears
to be a function definition
I don't understand what the problem is! I'm fairly new to C++, but I tried
to follow an example in a book (with my own source files, though) and it
won't work. I might try typing the files in from the book, but
syntactically, I think everything is the same. Any help would be
appreciated!


Relevant Pages

  • Re: [MSH] how to list constuctor overloads
    ... Void .ctor ... > I did know that I needed an attachement object first (fits nice in the ... > new-object: Constructor not found. ... > Encoding contentEncoding, String mediaType), static System.Net.Mail.Att ...
    (microsoft.public.windows.server.scripting)
  • Re: LoadControl() and Constructor Parameters
    ... void Init. ... Page_Init phase as because if you do this on say, Page_Load, the control ... non-default constructor to work. ... also make the _Subcategory a public field and rename it to Subcategory, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: default parameters
    ... every permutation of default params in a C++ constructor, ... can someone explain the reasoning behind why it does not? ... overloading, and which is indeed what people do today, but yes, you?re ... If you do overloads, let?s say you have void f, and ...
    (microsoft.public.dotnet.languages.csharp)
  • Run-time Execution - Assert Failure
    ... to something i am missing in the copy constructor implementation. ... unary prefix increment operator and overloaded increment postfix ... FootballGame(char* szName, char* szCity, char* szQB, char* szMascot); ... void FootballGame::addSafety ...
    (comp.lang.cpp)
  • Re: 3 dimensional C++ dynamic array
    ... showstopper problem up front to help unthinkers avoid thinking, ... Better provide a default constructor that sets all three dimensions. ... The detection code will not ever be executed. ... erronously let you get away with 'void'. ...
    (comp.lang.cpp)