私はこのコンパイルエラーが何を意味するのかを理解しようとしています、そして私はこれをうまく説明したいと思います。
In file included from sys/charon.cpp:4:0:
これに続いて、上記の^ファイルに移動し、黄色で下線を引きます。
#include "../headers/charon.h"
また、ヘッダーファイルcharon.h内で定義されたクラスであるタイプ識別子 "charon_"にも黄色で下線が引かれ、おそらく別のエラーが発生します。
sys/../headers/charon.h:17:9: error: redefinition of ‘class charon::charon_’
sys/../headers/chio.h:86:9: error: previous definition of ‘class charon::charon_’
sys/charon.cpp:12:20: error: definition of implicitly-declared ‘charon::charon_::charon_()’
しかし、それらがすべて最初のエラーに関連していることを願っています。それは私がやろうとしていることに関連していると思います。
//File 1.h
/**********/
class I
{
private:
B* my_private_b;
public:
I(B& handle);
}
残念ながら、「ファイル1」が「I」の定義を開始する前に「B」を宣言する必要があります。それでも同時に、Bを定義する必要があります。したがって、両方を他の前に定義する方法がわかりません。より高度なソリューションが必要だと思いますが、わかりません。
//File 2.h
/***********/
class B
{
private:
I i;
O o;
public:
B();
}
ですから、その答えが見つかれば、次の部分を自分でチェックできるかもしれません。私が正しい方向に進んでいるかどうかを確認するのが良いと思われる場合は、問題のすべてのコードを以下に貼り付けます。
。#。#。#。#。#。#。#。#。#。#。#。#。#。#。#。#。#。#。#。#。#。#。#。#。# 。#。
十分な長さではありません、読みませんでしたか?コメントを除いて、4つのファイルすべてのコードのすべての行がここにあります。重要性が認識された順に。
//////////////////////////////////////
/////
/////////////
/////
/////
/////
//File: chio.h
#ifndef CHIO_H
#define CHIO_H
#include <deque>
#include <queue>
#include <iostream>
using namespace std;
namespace charon
{
class charon_
{
};
}
namespace chio
{
class chout_
{
private:
public:
chout_();
~chout_();
};
class chin_
{
private:
charon::charon_* engine;
public:
chin_(charon::charon_& handle);
chin_();
~chin_();
};
}
#endif /* CHIO_H */
//////////////////////////////////////
/////
/////////////
/////
/////
/////
//File: charon.h/*
//
* File: charon.h
* Author: josh
*
* Created on 11 April 2012, 22:26
*/
#ifndef CHARON_H
#define CHARON_H
//#include "boost/thread.hpp"
#include "chio.h"
using namespace std;
using namespace chio;
namespace charon
{
class charon_ {
private:
chout_ engine_output;
chin_ engine_input;
//boost::thread input_thread;
//boost::thread output_thread;
void start_threads();
void stop_threads();
public:
charon_();
charon_(charon_ &orig);
~charon_();
void run();
};
}
#endif /* CHARON_H */
これらはコンストラクター/cppファイルです。
charon.cpp
#include <iostream>
//#include <boost/thread.hpp>
//#include <boost/date_time.hpp>
#include "../headers/charon.h"
using namespace std;
using namespace charon;
using namespace chio;
namespace charon
{
charon_::charon_(){
engine_input = chio::chin_((charon_*)this);
}
};
//^^charon.cpp^^
---------
//chin.cpp
#include <iostream>
#include <borland/conio.h>
#include <ncurses.h>
#include <deque>
#include "../headers/charon.h"
using namespace std;
using namespace charon;
using namespace chio;
namespace chio
{
chin_::chin_(charon::charon_& handle) {
engine = handle;
}
chin_::~chin_() {
}
}
そしてフィナーレについては、私は個人的に読書が嫌いなので、誰かにこれをすべて尋ねるのを延期してきました。ですから、ここまで来たのなら、おそらくこれも欲しいでしょう。
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
gmake[1]: Entering directory `/home/josh/Projects/Maze/Charon'
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/charon
gmake[2]: Entering directory `/home/josh/Projects/Maze/Charon'
mkdir -p build/Debug/GNU-Linux-x86/sys
rm -f build/Debug/GNU-Linux-x86/sys/charon.o.d
g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/sys/charon.o.d -o build/Debug/GNU-Linux-x86/sys/charon.o sys/charon.cpp
In file included from sys/charon.cpp:4:0:
sys/../headers/charon.h:17:9: error: redefinition of ‘class charon::charon_’
sys/../headers/chio.h:86:9: error: previous definition of ‘class charon::charon_’
sys/charon.cpp:12:20: error: definition of implicitly-declared ‘charon::charon_::charon_()’
gmake[2]: *** [build/Debug/GNU-Linux-x86/sys/charon.o] Error 1
gmake[2]: Leaving directory `/home/josh/Projects/Maze/Charon'
gmake[1]: *** [.build-conf] Error 2
gmake[1]: Leaving directory `/home/josh/Projects/Maze/Charon'
gmake: *** [.build-impl] Error 2
私のより単純なバージョンへの答えがあれば、私は単にうれしいです。コンパイルエラーを修正するためのアイデアが不足し、考えられるすべてのことを検証する巨大なC++リファレンスをめくりました。すべての構文は正しいように見えますが、コンパイラを操作してこのようなことを行う方法をまだ具体的に学んでいないだけだと思います。
わからない、たぶん今はとりとめのないだけだろう。これは少なくとも過去3日間私を苛立たせてきました。