Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Nefrugle

Im having problems. .

This topic is 5524 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having problems with header files and public base classes Here's the code:
    
// 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;
}
    
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]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
you need to #include "name.h"
in stats.h ........

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
Android_s - Thanks for the advice. Works fine now.

and dark_logik thank you also for the help with where my #includes needed to go.

Thank you all for all your Guys help!



NeFrUgLe

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!