a problem about compiling a class

Hi, I am new to C++. I write a simple program involving class. A compiling error occurs while compiling. Someone could help solve? Thanks,

I define the main function, declare a class and implement its member function in three separate files: main.cc, class1.h and class1.cc. When I compile main.cc using "g++ -o main main.cc", I get the error below,
+++++++++++++++++++++++++++++++++++++++++++++++++++++
-bash-2.05b$ g++ -Wall -g -o main main.cc
/tmp/cc7qAmEo.o(.text+0xd2): In function `main':
/home/users/ycai/examples/cplusplusExp/main.cc:10: undefined reference to `class1::printValue()'
collect2: ld returned 1 exit status
+++++++++++++++++++++++++++++++++++++++++++++++++++++

Below are my files
+++++++ main.cc +++++++++
#include <iostream>
#include "class1.h"

using namespace std;

int main() {
cout << "OK" << endl;

class1 c1;
c1.setValue(10);
return 0;
}
+++++++++++++++++++++++++++

+++++++ class1.h ++++++++
class class1 {
int *a;
public:
class1();
~class1();
void setValue(int v);
};


class1::class1() {
a = new int;
*a = 0;
}

class1::~class1() {
delete a;
}
+++++++++++++++++++++++++++

++++++++ class1.cc +++++++
#include "class1.h"
#include <iostrem>
uing namespace std;

void class1::setValue(int v) {
*a = v;
cout << *a << endl;
return;
}

+++++++++++++++++++++++++++++
You aren't linking to class1.cc, use this command to compile/link both source files:
g++ -Wall -g -o main main.cc class1.cc
Thanks a lot, it works.

======================================================
You aren't linking to class1.cc, use this command to compile/link both source files:

g++ -Wall -g -o main main.cc class1.cc
======================================================
Topic archived. No new replies allowed.