Open KatharinaLin opened 8 years ago
@KatharinaLin multiple definition problem, please remember to add #program once
or
#ifndef HEADER_HPP_
#define HEADER_HPP_
// your class declaration
#endif
I just add #ifndef...into my digraph.cpp, others are with it before, but it did't work, the problem still exist.
@KatharinaLin no need to add it in cpp files. I found that you file "Ralation.hpp" dose not have a definition protection.
I'm so sorry.Firstly I add "#ifndef"into Relation.hpp,but I forget "RELATION_HPP", It reported some mistakes to me but without the same problem of redefinition.So I thought it repaired.However, Linux Teminal just don't show me.When fixed the problems, redefinition problem show again.I don't know why they didn't appear at the same time .I'm so sad.
I can not get your point? What's exactly happened with you? =_=
因为你在Relation.cpp和BooleanMatrix.cpp里都有那些函数的定义,编译器不知道要选哪个
BooleanMatrix.cpp里有那些函数不奇怪,但为什么Relation.cpp里也有那些函数的定义呢? 因为Relation.cpp里有#include "Relation.hpp", 于是Relation.cpp里出现了#include "BooleanMatrix.cpp" 于是Relation.cpp把那些函数的定义复制了进来,Relation.cpp里也就有了那些函数的定义
不妨试试
在没有十足把握的情况下, 建议不要include一个cpp,特别是在这个cpp里有函数定义的时候 给每个hpp加上防止多次include的#ifndef XXX #define XXX ... #endif 是个好习惯 (我觉得你其他文件都做得挺好的啊,这里应该是不小心打错了吧)
@ghostbody It didn't work actually.
@Mensu I am trying now.Thank you.
@Mensu Yes, it's actually the problem.Thank you, I will remember it next time.
I have tried my best to find the problem for two days ,but failed. This is the report: /tmp/cccZdMj9.o: In function
BooleanMatrix::BooleanMatrix(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:6: multiple definition of
BooleanMatrix::BooleanMatrix(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:6: first defined here /tmp/cccZdMj9.o: In functionBooleanMatrix::BooleanMatrix(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:6: multiple definition of
BooleanMatrix::BooleanMatrix(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:6: first defined here /tmp/cccZdMj9.o: In functionBooleanMatrix::BooleanMatrix(int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:9: multiple definition of
BooleanMatrix::BooleanMatrix(int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:9: first defined here /tmp/cccZdMj9.o: In functionBooleanMatrix::BooleanMatrix(int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:9: multiple definition of
BooleanMatrix::BooleanMatrix(int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:9: first defined here /tmp/cccZdMj9.o: In functionBooleanMatrix::replace(bool, int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:13: multiple definition of
BooleanMatrix::replace(bool, int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:13: first defined here /tmp/cccZdMj9.o: In functionBooleanMatrix::operator&(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:21: multiple definition of
BooleanMatrix::operator&(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:21: first defined here /tmp/cccZdMj9.o: In functionBooleanMatrix::operator|(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:28: multiple definition of
BooleanMatrix::operator|(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:28: first defined here /tmp/cccZdMj9.o: In functionBooleanMatrix::BooleanProduct(BooleanMatrix const&) const': /home/lin/DS/main.cpp/BooleanMatrix.cpp:35: multiple definition of
BooleanMatrix::BooleanProduct(BooleanMatrix const&) const' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:35: first defined here /tmp/ccnYc5A0.o: In functionBooleanMatrix::~BooleanMatrix()': /home/lin/DS/main.cpp/BooleanMatrix.cpp:6: multiple definition of
BooleanMatrix::BooleanMatrix(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:6: first defined here /tmp/ccnYc5A0.o: In functionBooleanMatrix::~BooleanMatrix()': /home/lin/DS/main.cpp/BooleanMatrix.cpp:6: multiple definition of
BooleanMatrix::BooleanMatrix(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:6: first defined here /tmp/ccnYc5A0.o: In functionBooleanMatrix::BooleanMatrix(int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:9: multiple definition of
BooleanMatrix::BooleanMatrix(int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:9: first defined here /tmp/ccnYc5A0.o: In functionBooleanMatrix::BooleanMatrix(int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:9: multiple definition of
BooleanMatrix::BooleanMatrix(int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:9: first defined here /tmp/ccnYc5A0.o: In functionBooleanMatrix::replace(bool, int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:13: multiple definition of
BooleanMatrix::replace(bool, int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:13: first defined here /tmp/ccnYc5A0.o: In functionBooleanMatrix::operator&(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:21: multiple definition of
BooleanMatrix::operator&(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:21: first defined here /tmp/ccnYc5A0.o: In functionBooleanMatrix::operator|(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:28: multiple definition of
BooleanMatrix::operator|(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:28: first defined here /tmp/ccnYc5A0.o: In functionBooleanMatrix::BooleanProduct(BooleanMatrix const&) const': /home/lin/DS/main.cpp/BooleanMatrix.cpp:35: multiple definition of
BooleanMatrix::BooleanProduct(BooleanMatrix const&) const' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:35: first defined here /tmp/cckiKUTS.o: In functionBooleanMatrix::~BooleanMatrix()': /home/lin/DS/main.cpp/BooleanMatrix.cpp:6: multiple definition of
BooleanMatrix::BooleanMatrix(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:6: first defined here /tmp/cckiKUTS.o: In functionBooleanMatrix::~BooleanMatrix()': /home/lin/DS/main.cpp/BooleanMatrix.cpp:6: multiple definition of
BooleanMatrix::BooleanMatrix(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:6: first defined here /tmp/cckiKUTS.o: In functionBooleanMatrix::BooleanMatrix(int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:9: multiple definition of
BooleanMatrix::BooleanMatrix(int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:9: first defined here /tmp/cckiKUTS.o: In functionBooleanMatrix::BooleanMatrix(int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:9: multiple definition of
BooleanMatrix::BooleanMatrix(int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:9: first defined here /tmp/cckiKUTS.o: In functionBooleanMatrix::replace(bool, int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:13: multiple definition of
BooleanMatrix::replace(bool, int, int)' main.cpp.zip/tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:13: first defined here /tmp/cckiKUTS.o: In function
BooleanMatrix::operator&(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:21: multiple definition of
BooleanMatrix::operator&(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:21: first defined here /tmp/cckiKUTS.o: In functionBooleanMatrix::operator|(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:28: multiple definition of
BooleanMatrix::operator|(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:28: first defined here /tmp/cckiKUTS.o: In functionBooleanMatrix::BooleanProduct(BooleanMatrix const&) const': /home/lin/DS/main.cpp/BooleanMatrix.cpp:35: multiple definition of
BooleanMatrix::BooleanProduct(BooleanMatrix const&) const' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:35: first defined here collect2: error: ld returned 1 exit status lin@lin-VirtualBox:~/DS/main.cpp$