P
Peng Yu
Hi,
I'm trying to define inline_test::test() to be inline. But I always
got errors. I know that if I define inline_test::test() in
inline_test.h, there are no errors.
But I still would rather to put the member functions in *.cc files not
the *.h files. Do you know how to do that?
The following paragraphs are the compile error and the source codes.
Best wishes,
Peng
g++-3.3 -c -O -g -o inline_test.o inline_test.cc
g++-3.3 -c -O -g -o main.o main.cc
g++-3.3 -o main inline_test.o main.o
main.o(.text+0x1b): In function `main':
/usr/include/c++/3.3/ostream:193: undefined reference to
`inline_test::test()'
collect2: ld returned 1 exit status
make: *** [main] Error 1
//inline_test.h
#ifndef INLINE_TEST_H
#define INLINE_TEST_H
using namespace std;
class inline_test{
public:
inline_test();
~inline_test();
int test();
private:
int x;
};
#endif // INLINE_TEST_H
//inline_test.cc
#include "inline_test.h"
using namespace std;
inline_test::inline_test(){
x = 10;
}
inline_test::~inline_test(){
}
inline int inline_test::test(){
return x;
}
//main.cc
#include <iostream>
#include "inline_test.h"
using namespace std;
int main(int argc, char *argv[])
{
inline_test A;
cout << A.test() << endl;
}
I'm trying to define inline_test::test() to be inline. But I always
got errors. I know that if I define inline_test::test() in
inline_test.h, there are no errors.
But I still would rather to put the member functions in *.cc files not
the *.h files. Do you know how to do that?
The following paragraphs are the compile error and the source codes.
Best wishes,
Peng
g++-3.3 -c -O -g -o inline_test.o inline_test.cc
g++-3.3 -c -O -g -o main.o main.cc
g++-3.3 -o main inline_test.o main.o
main.o(.text+0x1b): In function `main':
/usr/include/c++/3.3/ostream:193: undefined reference to
`inline_test::test()'
collect2: ld returned 1 exit status
make: *** [main] Error 1
//inline_test.h
#ifndef INLINE_TEST_H
#define INLINE_TEST_H
using namespace std;
class inline_test{
public:
inline_test();
~inline_test();
int test();
private:
int x;
};
#endif // INLINE_TEST_H
//inline_test.cc
#include "inline_test.h"
using namespace std;
inline_test::inline_test(){
x = 10;
}
inline_test::~inline_test(){
}
inline int inline_test::test(){
return x;
}
//main.cc
#include <iostream>
#include "inline_test.h"
using namespace std;
int main(int argc, char *argv[])
{
inline_test A;
cout << A.test() << endl;
}