ok, here's the scenario (and maybe i will finally get this assignment finished) ...

i have a class IntArray. at the moment i have it all in a .C file. i have a little main section that has minimal testing in it (will do something more formal later). my prof. wants us to "split" it into an IntArray.C an IntArray.h and a Test.C.

i want to know what i need to #include and where so that when i run my Test.C it will be able to make objects from IntArray (.C or .h) and thoroughly test them. i don't know what the difference in an IntArray.C and an IntArray.h is, though ... so i don't know what is to be in those ...

advice?

THANKS
crq

// Class.h
class C {
  int i;
public:
  C();
public:
  int geti() const;
};
// Class.cpp
#include "Class.h"

C::C(): i(0) {}

int C::geti() const { return i; }
// main.cpp
#include <iostream>
#include "Class.h"

using namespace std;

int main()
{
  C c;

  cout<< c.geti() <<endl;
}

From the command line you would compile it something like this (your mileage may vary):

$ g++ class.cpp main.cpp
$ ./a.out

WOW!! thanks!!

i will try that.

cr1

// Class.h
class C {
  int i;
public:
  C();
public:
  int geti() const;
};
// Class.cpp
#include "Class.h"

C::C(): i(0) {}

int C::geti() const { return i; }
// main.cpp
#include <iostream>
#include "Class.h"

using namespace std;

int main()
{
  C c;

  cout<< c.geti() <<endl;
}

From the command line you would compile it something like this (your mileage may vary):

$ g++ class.cpp main.cpp
$ ./a.out
This article has been dead for over six months. Start a new discussion instead.