SOLVED - Sorry, aber ja: C2027 - Use of undefined type
-
Problem wurde gelöst. Ich muss mich demütig bedanken.
Hab die namespaces
namespace FreeFD::Strucht; namespace FreeFD::Class;
zu
namespace FreeFD::UserDefined;
zusammengefasst.
Anschließend habe ich sämtliche Header-Dateien wie folgt aufgebaut:
#ifndef DEFINITION #edfine DEFINITION /*Content*/ #endif
Und alle 104 Fehler, woher auch immer sie kamen, waren weg
So, jetzt zum ursprünglichen Post
Es ist nicht so, dass ich das Problem nicht kannte und vorher schon versucht habe, zu beheben...Hallo.
Entschuldigung, es handelt sich um einen alt bekannten Fehler und prinzipiell verstehe ich diese Fehlermeldung auch (dachte ich bis eben), aber in meinem Fall macht sie (aus meiner Sicht) keinen Sinn.
Ich nutze verschiedene, etwas größere Structuren in meinem Programm.
Alle werden in einem separaten Header Definiert. Die Funktionen finden sich dann in einem separaten Header.Ein Beispiel:
//TNode_Definition.h #define TNODE_DEFINITIONS_H namespace FreeFD {namespace Struct { typedef struct TNode { struct TVector P; struct TFace** FP; int nFP; struct TCell** EP; double* Gamma; int nEP; int Index; int Index2; TNode(); bool External(); bool Internal(); void Reset(); void Copy(struct TNode* N); void Initialize(); }TNode; }}
...und...
//TNode_Function.h #define TNODE_FUNCTION_H namespace FreeFD { namespace Struct { TNode::TNode() { this->EP = nullptr; this->FP = nullptr; this->Gamma = nullptr; this->Reset(); } bool TNode::Internal() { if (this->nFP <= 0) { return true; } return false; } bool TNode::External() { if (this->nFP > 0) { return true; } return false; } void TNode::Initialize() { this->EP = nullptr; this->FP = nullptr; this->Gamma = nullptr; this->Reset(); } void TNode::Reset() { if (this->EP != nullptr) { free(this->EP); this->EP = nullptr; } if (this->FP != nullptr) { free(this->FP); this->FP = nullptr; } if (this->Gamma != nullptr) { free(this->Gamma); this->Gamma = nullptr; } this->P.Reset(); this->nEP = 0; this->nFP = 0; this->Index = 0; this->Index2 = 0; } void TNode::Copy(FreeFD::Struct::TNode* N) { /*...much code...*/ } } }
Analog gibt es das dann noch für TEdge, TFace, TCell, TVector uvm.
Beim Including gehe ich wie folgt vor:
/*...*/ #include TVector_Definition.h #include TNode_Definition.h /*TNode deklariert*/ #include TEdge_Definition.h #include TFace_Definition.h #include TCell_Definition.h #include CFamily_Definition.h /*...*/ #include TVector_Function.h #include TNode_Function.h /*TNode definiert*/ #include TEdge_Function.h #include TFace_Function.h #include TCell_Function.h #include CFamily_Function.h /*Fehler hier*/ /*...*/
Und jetzt bekomme ich im Header CFamily_Function.h auf einmal eine Fehlermeldung "Use of undefined type TNode".
//CFamily_Function.h /*...*/ if (npNodeVar > 0) { #pragma omp parallel for for (i = 0; i < this->npNodeVar; i++) { this->ppNodeVar[i]->Copy(Fam->ppNodeVar[i]); //C2027 } } if (npEdgeVar > 0) { #pragma omp parallel for for (i = 0; i < this->npEdgeVar; i++) { this->ppEdgeVar[i]->Copy(Fam->ppEdgeVar[i]); //C2027 } } if (npFaceVar > 0) { #pragma omp parallel for for (i = 0; i < this->npFaceVar; i++) { this->ppFaceVar[i]->Copy(Fam->ppFaceVar[i]); //C2027 } } if (npCellVar > 0) { #pragma omp parallel for for (i = 0; i < this->npCellVar; i++) { this->ppCellVar[i]->Copy(Fam->ppCellVar[i]); //C2027 } } } /*...*/
Ich verstehe das nicht wirklich, denn TNode ist vollkommen definiert.
Eine Funktion, welche lediglich deklariert, aber nie definiert wurde erscheint in Visual Studio grün unterringelt - solche Funktionien finde ich in meinem kompletten Projekt nicht.Tut mir leid für die lange Anfrage bzgl. dieses "Standardproblems", aber das versaut mir jetzt schon die letzten fünf Stunden.
Rein inhaltlich handelt es sich um Header-Files, die ich schon früher in einem anderen Programm benutzt habe.
Ich möchte noch darauf hinweisen, dass das Programm wunderbar läuft, wenn ich CFamily_Functions.h nicht mit einbeinde...
-
include guards und forward definitions.
-
Alle Definitionen, auch die von TNode wurden vorher durchgeführt. Erst weit später, nachdem sogar die Funktionen von TNode gelesen wurden, kommt es zum Fehler.
Include Guards nutze ich darüber hinaus...
Include Original:
#define CMESH_HEADER_H #pragma region PRÄ Processor #include "PRE_Definitions.h" #pragma endregion #pragma region Standards libraries #ifndef STDIO_H #define STDIO_H #include <stdio.h> #endif #ifndef STDLIB_H #define STDLIB_H #include <stdlib.h> #endif #ifndef MATH_H #define MATH_H #include <math.h> #endif #ifndef STRING_H #define STRING_H #include <string.h> #endif #ifndef VECTOR_H #define VECTOR_H #include <vector> #endif #ifndef OMP_H #define OMP_H #include <omp.h> #endif #pragma endregion #pragma region ENumerations #ifndef ENUMERATIONS_H #include "C:\\HomeC\\01_FreeFD\\Header\\ENumerations\\ENumerations.h" #endif #pragma endregion #pragma region Functions #ifndef STRING_FUNCTION_H #include "C:\\HomeC\\01_FreeFD\\Header\\Functions\\StrFunction.h" #endif #pragma endregion #pragma region Struct and Class definition #ifndef TVECTOR_DEFINITIONS_H #include "C:\\HomeC\\01_FreeFD\\Header\\MeshStructure\\TVector_Definitions.h" #endif #ifndef TNODE_DEFINITIONS_H #include "C:\\HomeC\\01_FreeFD\\Header\\MeshStructure\\TNode_Definitions.h" #endif #ifndef TEDGE_DEFINITIONS_H #include "C:\\HomeC\\01_FreeFD\\Header\\MeshStructure\\TEdge_Definitions.h" #endif #ifndef TFACE_DEFINITIONS_H #include "C:\\HomeC\\01_FreeFD\\Header\\MeshStructure\\TFace_Definitions.h" #endif #ifndef TCELL_DEFINITIONS_H #include "C:\\HomeC\\01_FreeFD\\Header\\MeshStructure\\TCell_Definitions.h" #endif #ifndef CFAMILY_DEFINITION_H #include "C:\\HomeC\\01_FreeFD\\Header\\CFamily\\CFamily_Definition.h" #endif #ifndef CMESH_DEFINITION_H #include "C:\\HomeC\\01_FreeFD\\Header\\CMesh\\CMesh_Definition.h" #endif #pragma endregion #pragma region Vector and Matrix Functions #ifndef VECTOR_AND_MATRIX_FUNCTIONS_H #include "C:\\HomeC\\01_FreeFD\\Header\\Functions\\VectorAndMatrix.h" #endif #ifndef GEOMETRIC_FUNCTIONS_H #include "C:\\HomeC\\01_FreeFD\\Header\\Functions\\Geometric.h" #endif #ifndef MEMORY_H #include "C:\\HomeC\\01_FreeFD\\Header\\Functions\\Memory\\Memory.h" #endif #pragma endregion #pragma region Struct and Class functions #ifndef TVECTOR_FUNCTION_H #include "C:\\HomeC\\01_FreeFD\\Header\\MeshStructure\\TVector_Functions.h" #endif #ifndef TNODE_FUNCTION_H #include "C:\\HomeC\\01_FreeFD\\Header\\MeshStructure\\TNode_Function.h" #endif #ifndef TEDGE_FUNCTION_H #include "C:\\HomeC\\01_FreeFD\\Header\\MeshStructure\\TEdge_Function.h" #endif #ifndef TFACE_FUNCTION_H #include "C:\\HomeC\\01_FreeFD\\Header\\MeshStructure\\TFace_Function.h" #endif #ifndef TCELL_FUNCTION_H #include "C:\\HomeC\\01_FreeFD\\Header\\MeshStructure\\TCell_Function.h" #endif #ifndef CFAMILY_FUNCTION_H /*ERROR OCCURES INCLUDING THIS FILE - ELSE, EVERYTHING IS FINE*/ #include "C:\\HomeC\\01_FreeFD\\Header\\CFamily\\CFamily_Function.h" #endif //#ifndef CMESH_FUNCTION_H // #include "C:\\HomeC\\01_FreeFD\\Header\\CMesh\\CMesh_Function.h" //#endif #pragma endregion
-
namespace Struct ? Ernsthaft?
Und sollte das nicht eigentlich FreeFD::Struct::TNode sein?
-
Ich bin im namespace FreeFD::Struct::
Die Fehlermeldung, da hast Du recht, heißt: Use of undefined type FreeFD:Struct:TNode
Die Namenskonvention mag geschmacksbedürftig sein, aber mir ist das so wichtig.
-
Wie sieht denn CFamily_Definition.h aus?
Deklarationen im C-Stil haben in reinem C++-Code nichts verloren. Abgesehen davon, dass sie unnötig Platz verschwenden, ist auch nicht in allen Fällen unmittelbar klar, was deklariert wird.
struct foo* bar;
Deklariert einen Zeigen bar. Es könnte Zusätzlich auch eine implizite Deklaration einer Struktur foo sein, sofern der Name nicht bereits vergeben wurde.
-
Noch was anderes: deine Include-Guards sind irgendwie "kreativ". Ich erinnere mich dunkel, dass wir hier mir dir schon einmal darüber diskutiert haben.
#ifndef MATH_H #define MATH_H #include <math.h> #endif
Sowas meine ich.
Normalerweise includet man einfach
<math.h>
und DORT findet sich dann der Guard. Dann kann man alle Header auch in beliebiger Reihenfolge includen. Jeder Header includet einfach die Header, von denen er abhängt.Auch scheint es mir eher so, als sollten deine *Function.h-Dateien eigentlich die cpp-Dateien zu den *Definition.h-Dateien sein.
Warum außerdem "typedef struct ..."? Du schreibst doch C++ und kein C. In TNode: warum
struct TFace** FP;
statt nurTFace** FP;
? Das TFace muss dann natürlich vorher bekannt sein. (entweder indem du TFace.h includest oder indem du oben einmal "struct TFace;" bekanntmachst.
-
wob schrieb:
Noch was anderes: deine Include-Guards sind irgendwie "kreativ". Ich erinnere mich dunkel, dass wir hier mir dir schon einmal darüber diskutiert haben.
#ifndef MATH_H #define MATH_H #include <math.h> #endif
Sowas meine ich.
Normalerweise includet man einfach
<math.h>
und DORT findet sich dann der Guard. Dann kann man alle Header auch in beliebiger Reihenfolge includen. Jeder Header includet einfach die Header, von denen er abhängt.Auch scheint es mir eher so, als sollten deine *Function.h-Dateien eigentlich die cpp-Dateien zu den *Definition.h-Dateien sein.
Warum außerdem "typedef struct ..."? Du schreibst doch C++ und kein C. In TNode: warum
struct TFace** FP;
statt nurTFace** FP;
? Das TFace muss dann natürlich vorher bekannt sein. (entweder indem du TFace.h includest oder indem du oben einmal "struct TFace;" bekanntmachst.Das kann gut sein und Dir ist sicher aufgefallen, dass ich das NUR bei "externen" Headerdateien mache weil ich einfach ... zu faul war sie mal auf zu machen um zu sehen, was da definiert wird.
Habe das nun nachgeholt
#pragma region Standards libraries #ifndef _INC_STDIO #include <stdio.h> #endif #ifndef STDLIB_H #define _INC_STDLIB #include <stdlib.h> #endif #ifndef _INC_MATH #include <math.h> #endif #ifndef _INC_STRING #include <string.h> #endif #ifndef __vector_h__ #include <vector> #endif #ifndef _OPENMP #include <omp.h> #endif #pragma endregion
Mein Problem habe ich irgendwie auch gelöst... aber - und das gefällt mir nicht - ich weiß nicht, wieso.
Ich habe die Includings so angeordnet:#include TVector_Definition.h /*include all other defintion files for structures*/ #include "TVector_Function.h /*include all other function files for structures*/ #include CFamily_Definition.h /*include all other defintion files for classes*/ #include "CFamily_Function.h /*include all other function files for classes*/
-
camper schrieb:
Wie sieht denn CFamily_Definition.h aus?
Deklarationen im C-Stil haben in reinem C++-Code nichts verloren. Abgesehen davon, dass sie unnötig Platz verschwenden, ist auch nicht in allen Fällen unmittelbar klar, was deklariert wird.
struct foo* bar;
Deklariert einen Zeigen bar. Es könnte Zusätzlich auch eine implizite Deklaration einer Struktur foo sein, sofern der Name nicht bereits vergeben wurde.
Hi,
anbei der Code. Ich denke, es liegt an den namespace. Denn erst als ich die includings umgeschachtelt hatte, hat es funktioniert (siehe vorheriger Post am Ende).
CFamily_Definition.h #define CFAMILY_DEFINITION_H namespace FreeFD { namespace Class { class CFamily { private: char* NameVar; class CMesh* ParentMesh; ENumerations::FamilySettings::FamilyTypeENUM TypeVar; struct TNode** ppNodeVar; int npNodeVar; struct TEdge** ppEdgeVar; int npEdgeVar; struct TFace** ppFaceVar; int npFaceVar; struct TCell** ppCellVar; int npCellVar; int IndexVar; int Index2Var; int NumberVar; public: CFamily(class CMesh* CM); char* Name(); char* Name(char* fName); class CMesh* M(); class CMesh* M(class CMesh* CM); ENumerations::FamilySettings::FamilyTypeENUM Type(); ENumerations::FamilySettings::FamilyTypeENUM Type(ENumerations::FamilySettings::FamilyTypeENUM fFam); void Initialize(); void Reset(); void Copy(class CFamily* Fam); void Delete(); struct TNode** ppNode(); struct TNode* pNode(int Index); struct TNode* CFamily::pNode(int Index, TNode* fN); int npNode(); struct TNode** ResetNodeStack(struct TNode** Stack, int Size); struct TEdge** ppEdge(); struct TEdge* pEdge(int Index); struct TEdge* CFamily::pEdge(int Index, TEdge* fE); int npEdge(); struct TEdge** ResetEdgeStack(struct TEdge** Stack, int Size); struct TFace** ppFace(); struct TFace* pFace(int Index); struct TFace* CFamily::pFace(int Index, TFace* fF); int npFace(); struct TFace** ResetFaceStack(struct TFace** Stack, int Size); struct TCell** ppCell(); struct TCell* pCell(int Index); struct TCell* CFamily::pCell(int Index, TCell* fC); int npCell(); struct TCell** ResetCellStack(struct TCell** Stack, int Size); int Index(); int Index(int fIndex); int Index2(); int Index2(int fIndex); int Number(); int Number(int fNumber); char* ToString(); }; }}
... und ...
//CFamily_Function.h #define CFAMILY_FUNCTION_H using namespace FreeFD::Struct; namespace FreeFD { namespace Class{ CFamily::CFamily(class CMesh* CM) { this->ParentMesh = CM; this->Initialize(); this->Reset(); } class CMesh* CFamily::M() { return ParentMesh; } class CMesh* CFamily::M(class CMesh* CM) { this->ParentMesh = CM; return this->ParentMesh; } void CFamily::Initialize() { this->NameVar = nullptr; this->ppNodeVar = nullptr; this->ppEdgeVar = nullptr; this->ppFaceVar = nullptr; this->ppCellVar = nullptr; } void CFamily::Reset() { if (this->NameVar != nullptr) { free(this->NameVar); } this->NameVar = nullptr; if (this->ppNodeVar != nullptr) { free(this->ppNodeVar); } this->ppNodeVar = nullptr; if (this->ppEdgeVar != nullptr) { free(this->ppEdgeVar); } this->ppEdgeVar = nullptr; if (this->ppFaceVar != nullptr) { free(this->ppFaceVar); } this->ppFaceVar = nullptr; if (this->ppCellVar != nullptr) { free(this->ppCellVar); } this->ppCellVar = nullptr; this->npNodeVar = 0; this->npEdgeVar = 0; this->npFaceVar = 0; this->npCellVar = 0; this->Type(FreeFD::ENumerations::FamilySettings::FamilyTypeENUM::FLUENT_SOLID); } void CFamily::Copy(class CFamily* Fam) { int i = 0; Fam->Reset(); Fam->NameVar = (char*)malloc((strlen(this->NameVar) + 1) * sizeof(char)); strcpy(Fam->NameVar, this->NameVar); Fam->npNodeVar = this->npNodeVar; Fam->npEdgeVar = this->npEdgeVar; Fam->npFaceVar = this->npFaceVar; Fam->npCellVar = this->npCellVar; Fam->Type(this->Type()); if (npNodeVar > 0) { Fam->ppNodeVar = (TNode**)malloc(this->npNodeVar * sizeof(TNode*)); for (i = 0; i < this->npNodeVar; i++) { Fam->ppNodeVar[i] = nullptr; } } else { Fam->ppNodeVar = nullptr; } if (npEdgeVar > 0) { Fam->ppEdgeVar = (TEdge**)malloc(this->npEdgeVar * sizeof(TEdge*)); for (i = 0; i < this->npEdgeVar; i++) { Fam->ppEdgeVar[i] = nullptr; } } else { Fam->ppEdgeVar = nullptr; } if (npFaceVar > 0) { Fam->ppFaceVar = (TFace**)malloc(this->npFaceVar * sizeof(TFace*)); for (i = 0; i < this->npFaceVar; i++) { Fam->ppFaceVar[i] = nullptr; } } else { Fam->ppFaceVar = nullptr; } if (npCellVar > 0) { Fam->ppCellVar = (TCell**)malloc(this->npCellVar * sizeof(TCell*)); for (i = 0; i < this->npCellVar; i++) { Fam->ppCellVar[i] = nullptr; } } else { Fam->ppCellVar = nullptr; } if (npNodeVar > 0) { #pragma omp parallel for for (i = 0; i < this->npNodeVar; i++) { this->ppNodeVar[i]->Copy(Fam->ppNodeVar[i]); } } if (npEdgeVar > 0) { #pragma omp parallel for for (i = 0; i < this->npEdgeVar; i++) { this->ppEdgeVar[i]->Copy(Fam->ppEdgeVar[i]); } } if (npFaceVar > 0) { #pragma omp parallel for for (i = 0; i < this->npFaceVar; i++) { this->ppFaceVar[i]->Copy(Fam->ppFaceVar[i]); } } if (npCellVar > 0) { #pragma omp parallel for for (i = 0; i < this->npCellVar; i++) { this->ppCellVar[i]->Copy(Fam->ppCellVar[i]); } } } void CFamily::Delete() { this->Reset(); } char* CFamily::Name() { return this->NameVar; } char* CFamily::Name(char* fName) { int i = 0; char* NewName = nullptr; std::vector<char*> NameStack; if (ParentMesh != nullptr) { for (i = 0; i < this->ParentMesh->npFamily(); i++) { if (this->ParentMesh->ppFamily(i) != this) { NameStack.push_back(this->ParentMesh->ppFamily(i)->Name()); } } NewName = FreeFD::Functions::String::GetNextName(fName, NameStack); } else { NewName = (char*)malloc((strlen(fName) + 1) * sizeof(char)); strcpy(NewName, fName); } if (this->NameVar != nullptr) { free(this->NameVar); } this->NameVar = nullptr; this->NameVar = NewName; return this->NameVar; } ENumerations::FamilySettings::FamilyTypeENUM CFamily::Type() { return this->TypeVar; } ENumerations::FamilySettings::FamilyTypeENUM CFamily::Type(ENumerations::FamilySettings::FamilyTypeENUM fType) { this->TypeVar = fType; return this->TypeVar; } char* CFamily::ToString() { return this->Name(); } struct TNode** CFamily::ppNode() { return this->ppNodeVar; } struct TNode* CFamily::pNode(int Index) { if (Index < this->npNodeVar) { return this->ppNodeVar[Index]; } return nullptr; } struct TNode* CFamily::pNode(int Index, TNode* fN) { if (Index < this->npNodeVar) { this->ppNodeVar[Index] = fN; } return this->ppNodeVar[Index]; } int CFamily::npNode() { return this->npNodeVar; } struct TNode** CFamily::ResetNodeStack(struct TNode** Stack, int Size) { int i = 0; if (this->ppNodeVar != nullptr) { free(this->ppNodeVar); } this->ppNodeVar = nullptr; if (Size < 1) { this->npNodeVar = 0; return nullptr; } if (Stack == nullptr) { this->ppNodeVar = (struct TNode**)malloc(Size * sizeof(struct TNode*)); #pragma omp parallel for if(Size > __N_MPI_ON) for (i = 0; i < Size; i++) { this->ppNodeVar[i] = nullptr; } } else { this->ppNodeVar = Stack; } this->npNodeVar = Size; return this->ppNodeVar; } struct TEdge** CFamily::ppEdge() { return this->ppEdgeVar; } struct TEdge* CFamily::pEdge(int Index) { if (Index < this->npEdgeVar) { return this->ppEdgeVar[Index]; } return nullptr; } struct TEdge* CFamily::pEdge(int Index, TEdge* fE) { if (Index < this->npEdgeVar) { this->ppEdgeVar[Index] = fE; } return this->ppEdgeVar[Index]; } int CFamily::npEdge() { return this->npEdgeVar; } struct TEdge** CFamily::ResetEdgeStack(struct TEdge** Stack, int Size) { int i = 0; if (this->ppEdgeVar != nullptr) { free(this->ppEdgeVar); } this->ppEdgeVar = nullptr; if (Size < 1) { this->npEdgeVar = 0; return nullptr; } if (Stack == nullptr) { this->ppEdgeVar = (struct TEdge**)malloc(Size * sizeof(struct TEdge*)); #pragma omp parallel for if(Size > __N_MPI_ON) for (i = 0; i < Size; i++) { this->ppEdgeVar[i] = nullptr; } } else { this->ppEdgeVar = Stack; } this->npEdgeVar = Size; return this->ppEdgeVar; } struct TFace** CFamily::ppFace() { return this->ppFaceVar; } struct TFace* CFamily::pFace(int Index) { if (Index < this->npFaceVar) { return this->ppFaceVar[Index]; } return nullptr; } struct TFace* CFamily::pFace(int Index, TFace* fF) { if (Index < this->npFaceVar) { this->ppFaceVar[Index] = fF; } return this->ppFaceVar[Index]; } int CFamily::npFace() { return this->npFaceVar; } struct TFace** CFamily::ResetFaceStack(struct TFace** Stack, int Size) { int i = 0; if (this->ppFaceVar != nullptr) { free(this->ppFaceVar); } this->ppFaceVar = nullptr; if (Size < 1) { this->npFaceVar = 0; return nullptr; } if (Stack == nullptr) { this->ppFaceVar = (struct TFace**)malloc(Size * sizeof(struct TFace*)); #pragma omp parallel for if(Size > __N_MPI_ON) for (i = 0; i < Size; i++) { this->ppFaceVar[i] = nullptr; } } else { this->ppFaceVar = Stack; } this->npFaceVar = Size; return this->ppFaceVar; } struct TCell** CFamily::ppCell() { return this->ppCellVar; } struct TCell* CFamily::pCell(int Index) { if (Index < this->npCellVar) { return this->ppCellVar[Index]; } return nullptr; } struct TCell* CFamily::pCell(int Index, TCell* fC) { if (Index < this->npCellVar) { this->ppCellVar[Index] = fC; } return this->ppCellVar[Index]; } int CFamily::npCell() { return this->npCellVar; } struct TCell** CFamily::ResetCellStack(struct TCell** Stack, int Size) { int i = 0; if (this->ppCellVar != nullptr) { free(this->ppCellVar); } this->ppCellVar = nullptr; if (Size < 1) { this->npCellVar = 0; return nullptr; } if (Stack == nullptr) { this->ppCellVar = (struct TCell**)malloc(Size * sizeof(struct TCell*)); #pragma omp parallel for if(Size > __N_MPI_ON) for (i = 0; i < Size; i++) { this->ppCellVar[i] = nullptr; } } else { this->ppCellVar = Stack; } this->npCellVar = Size; return this->ppCellVar; } int CFamily::Index() { return this->IndexVar; } int CFamily::Index(int fIndex) { this->IndexVar = fIndex; return this->IndexVar; } int CFamily::Index2() { return this->Index2Var; } int CFamily::Index2(int fIndex) { this->Index2Var = fIndex; return this->Index2Var; } int CFamily::Number() { return this->NumberVar; } int CFamily::Number(int fNumber) { this->NumberVar = fNumber; return this->NumberVar; } } }
-
CJens schrieb:
camper schrieb:
Wie sieht denn CFamily_Definition.h aus?
Deklarationen im C-Stil haben in reinem C++-Code nichts verloren. Abgesehen davon, dass sie unnötig Platz verschwenden, ist auch nicht in allen Fällen unmittelbar klar, was deklariert wird.
struct foo* bar;
Deklariert einen Zeigen bar. Es könnte Zusätzlich auch eine implizite Deklaration einer Struktur foo sein, sofern der Name nicht bereits vergeben wurde.
Hi,
anbei der Code. Ich denke, es liegt an den namespace. Denn erst als ich die includings umgeschachtelt hatte, hat es funktioniert (siehe vorheriger Post am Ende).
CFamily_Definition.h
#define CFAMILY_DEFINITION_H namespace FreeFD { namespace Class { class CFamily { ... struct TNode** ppNodeVar;
Ohne ein using namespace FreeFD::Struct irgendwo vorher (wie etwa in CFamily_Function.h), ist die Definition von ppNodeVar gleichzeitig eine Deklaration von TNode, die nichts mit FreeFD::Struct::TNode zu tun hat. Bedeutet nat. auch, dass in diesem Fall die Fehlermeldung tatsächtlich FreeFD::Class::CFamily::TNode bezeichnen dürfte. Details sind wichtig und Fehlermeldungen sollten immer 1:1 kopiert und nicht etwa nur umschrieben werden.
Wer natürlich namespace Struct und namespace Class verbricht und auch noch zusätzlich überall mit Klassenschlüsselwörtern um sich schmeisst, will Probleme bekommen... bist du bereit dazustruct Struct::TNode** ppNodeVar;
zu schreiben?
C-Stil benutzt man am besten nur wenn man ein Programm in C schreibt.
-
CJens schrieb:
wob schrieb:
Noch was anderes: deine Include-Guards sind irgendwie "kreativ".
Das kann gut sein und Dir ist sicher aufgefallen, dass ich das NUR bei "externen" Headerdateien mache weil ich einfach ... zu faul war sie mal auf zu machen um zu sehen, was da definiert wird.
#ifndef _INC_STDIO #include <stdio.h> #endif
Hä??!!!
Verstehe ich nicht, du hast doch immer noch irgendwie einen eigenen ifndef drum herum! Was spricht gegen das Weglassen des ifndef/endif an dieser Stelle?
#include <stdio.h>
Headerdatei aufmachen und Interna daraus nehmen?! Ernsthaft? Du WILLST unbedingt Probleme bekommen!
(ich hatte noch ein paar andere Dinge kritisiert und schließe mich außerdem der Kritik von Camper vollständig an)
-
Hast du den Eindruck, dass Standrdincludedateien von Vollidioten geschrieben werden?