|
|
这是main.cpp文件
-
- ...
- int main(void)
- {
- ...
- vector<Foo> vec_foo;
- cin >> x >> y >>z;
- Foo Obj1(x, y, z);
- vec_foo.push(Obj1);
- ...
- }
复制代码
这是Foo.h头文件
- ...
- class Foo
- {
- public:
- Foo(int , int );
- ...
- }
复制代码
这是Foo.cpp文件
- ...
- #include "foo.h"
- ...
- Foo::Foo(int Px, int Py)
- {
- x = Px;
- y = Py;
- ...
- }
复制代码
编译如下:
- [root@root TEST]# ls
- Foo.cpp Foo.h main.cpp test test6 test.cpp
- [root@root TEST]# g++ main.cpp -o main
- /tmp/ccFq6Xda.o(.text+0x125): In function `main':
- : undefined reference to `Foo::Foo(int, int)'
- /tmp/ccFq6Xda.o(.text+0x148): In function `main':
- : undefined reference to `Foo::~Foo()'
- /tmp/ccFq6Xda.o(.text+0x166): In function `main':
- : undefined reference to `Foo::~Foo()'
- /tmp/ccFq6Xda.o(.gnu.linkonce.t._ZN3FooC1ERKS_+0x8): In function `Foo::Foo(Foo const&)':
- : undefined reference to `vtable for Foo'
- /tmp/ccFq6Xda.o(.gnu.linkonce.t._ZNSt6vectorI3FooSaIS0_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS0_S2_EERKS0_+0xd2): In function `std::vector<Foo, std::allocator<Foo> >::_M_insert_aux(__gnu_cxx::__normal_iterator<Foo*, std::vector<Foo, std::allocator<Foo> > >, Foo const&)':
- : undefined reference to `Foo::~Foo()'
- /tmp/ccFq6Xda.o(.gnu.linkonce.t._ZNSt6vectorI3FooSaIS0_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS0_S2_EERKS0_+0xef): In function `std::vector<Foo, std::allocator<Foo> >::_M_insert_aux(__gnu_cxx::__normal_iterator<Foo*, std::vector<Foo, std::allocator<Foo> > >, Foo const&)':
- : undefined reference to `Foo::~Foo()'
- collect2: ld returned 1 exit status
- [root@root TEST]#
复制代码
谢谢先。不胜感激! |
|