// main
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
#include "name.cpp"
#include "stats.cpp"
int main()
{
cout << "\tThis is the begining of the program\n" << endl;
Stats Player( 10, 20, "Person" );
Player.printName();
cout << "\t\tPRESS ENTER TO EXIT";
cin.get();
return 0;
}
// name.h
#ifndef NAME_H
#define NAME_H
class Name {
public:
Name( char * = "na" ); // constructor
void printName(); // prints name
private:
char *name; // name of Player
};
#endif // NAME_H
// name.cpp
#include <iostream>
using std::cout;
using std::endl;
#include "name.h"
Name::Name( char *n )
{ name = n; }
void Name::printName()
{ cout << name << endl; }
// stats.h
#ifndef STATS_H
#define STATS_H
class Stats : public Name {
public:
Stats( int = 1, int = 10, char * = "na" );
private:
int x;
int y;
};
#endif // STATS_H
// stats.cpp
#include <iostream>
using std::cout;
using std::endl;
#include "stats.h"
Stats::Stats( int a, int b, char * c )
: Name( c )
{
x = a;
y = b;
}
Im having problems. .
I'm having problems with header files and public base classes
Here's the code:
Any help/advice would be much appreciated. Its only been acting up for the last week or so and its aggrivating me. I am using Visual Studio 6
The errors i get are:
ompiling...
stats.cpp
d:\my projects\testin\stats.h(7) : error C2504: 'Name' : base class undefined
D:\My Projects\testin\stats.cpp(13) : error C2614: 'Stats' : illegal member initialization: 'Name' is not a base or member
Skipping... (no relevant changes detected)
name.cpp
Error executing cl.exe.
testin.exe - 2 error(s), 0 warning(s)
thanks for any help
NeFrUgLe
[edited by - NeFrUgLe on May 7, 2003 5:28:40 AM]
Just taken a quick look at the code and it looks like the includes are a little confused...
i.e.
In the main.cpp you need to #include "stats.h" instead of stats.cpp - note that you don''t need to include name.h as that''ll be included when you use stats.h
In the stats.h you''ll need to #include "name.h".
In each of cpp files just #include the name of the header file for that class and all should work.
i.e.
In the main.cpp you need to #include "stats.h" instead of stats.cpp - note that you don''t need to include name.h as that''ll be included when you use stats.h
In the stats.h you''ll need to #include "name.h".
In each of cpp files just #include the name of the header file for that class and all should work.
Ok. .
I included name.h into stats.h
and name.h into name.cpp
and stats.h into stats.cpp
and stats.h into the main.cpp
and i got this error at link:
compiling...
Skipping... (no relevant changes detected)
name.cpp
stats.cpp
Linking...
LINK : fatal error LNK1104: cannot open file ".\Debug\name.obj"
Error executing link.exe.
testin.exe - 1 error(s), 0 warning(s)
I included name.h into stats.h
and name.h into name.cpp
and stats.h into stats.cpp
and stats.h into the main.cpp
and i got this error at link:
compiling...
Skipping... (no relevant changes detected)
name.cpp
stats.cpp
Linking...
LINK : fatal error LNK1104: cannot open file ".\Debug\name.obj"
Error executing link.exe.
testin.exe - 1 error(s), 0 warning(s)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement