For my thesis project I am dependent on a bunch of CGAL code written by another student a year ago. Unfortunately, I can't get the code to compile due to errors. These errors were probably not experienced by the previous student, so they probably are more related to my setup than the code itself, but I have no idea what the direct cause is.
The errors are in the file CCBSegmentCalculator.h. The code is as follows:
#pragma once
#include "bezier_arrangement.h"
//Circulates around a PL_Arrrangement CCB, visiting the points between the segments that make up the CCB
// (so smaller-scale than the build-in iterator that only visits the PL_Arrangement vertices)
// --- Could be used in more places than it is now, e.g., in the SVGHandler
class CCBSegmentCirculator
{
public:
CCBSegmentCirculator(PL_Arrangement::Ccb_halfedge_const_circulator ccbCirculator);
const CCBSegmentCirculator& next();
PL_Point operator*();
PL_Point get(); // same as operator*
bool operator==(const CCBSegmentCirculator &other) const;
private:
const PL_Arrangement::Ccb_halfedge_const_circulator halfedgesBegin;
PL_Arrangement::Ccb_halfedge_const_circulator halfedge;
//Depending on this boolean ...
bool forward;
//... we are either using these forward iterators ...
// -> in which case the 'current' point is segment.source
Polyline::Segment_const_iterator segment;
Polyline::Segment_const_iterator segmentEnd;
//... or these reverse iterators
// -> in which case the 'current' point is segmentReverse.target
Polyline::Segment_const_reverse_iterator segmentReverse;
Polyline::Segment_const_reverse_iterator segmentReverseEnd;
void initHalfedge();
};
The file "bezier_arrangement.h" has the following code:
#pragma once
#include <CGAL/Cartesian.h>
#include <CGAL/CORE_algebraic_number_traits.h>
#include <CGAL/Arr_Bezier_curve_traits_2.h>
#include <CGAL/Arrangement_2.h>
#include <CGAL/Arrangement_with_history_2.h>
#include <CGAL/Arr_extended_dcel.h>
#include <CGAL/Iso_rectangle_2.h>
#include <CGAL/Arr_walk_along_line_point_location.h>
#include <CGAL/Arr_observer.h>
//#include <CGAL/basic.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arr_polyline_traits_2.h>
struct FaceData
{
FaceData ()
{
colored = false;
solved = false;
};
bool colored = false;
bool solved = false;
};
//// Bezier curve traits ////
typedef CGAL::CORE_algebraic_number_traits Nt_traits;
typedef Nt_traits::Rational NT;
typedef Nt_traits::Rational Rational;
typedef Nt_traits::Algebraic Algebraic;
//Simple_cartesian = for easier debugging, no ref counting, values directly in objects
typedef CGAL::Cartesian<Rational> Kernel;
typedef CGAL::Cartesian<Algebraic> Alg_kernel;
//typedef Kernel::Point_2 Rat_Point;
typedef CGAL::Arr_Bezier_curve_traits_2<Kernel, Alg_kernel, Nt_traits> Traits;
typedef Traits::Curve_2 Bezier;
typedef Traits::Point_2 Point;
typedef Kernel::Iso_rectangle_2 BoundingBox;
typedef CGAL::Arr_face_extended_dcel<Traits, FaceData> Dcel;
typedef CGAL::Arrangement_with_history_2<Traits, Dcel> Arrangement; //Not really used anymore, because of crashes/problems/bugs
//// Polyline traits ////
// Instantiate the traits class using a user-defined kernel
// and Segment_traits_2.
typedef CGAL::Exact_predicates_exact_constructions_kernel PL_Kernel;
typedef CGAL::Arr_segment_traits_2<PL_Kernel> Segment_traits;
typedef CGAL::Arr_polyline_traits_2<Segment_traits> PL_traits;
// Identical instantiation can be achieved using the default Kernel:
// typedef CGAL::Arr_polyline_traits_2<> Geom_traits_2;
typedef PL_traits::Point_2 PL_Point;
typedef PL_traits::Segment_2 Segment;
typedef PL_traits::Curve_2 Polyline;
typedef CGAL::Arr_extended_dcel<PL_traits, bool/*not used*/, double, FaceData> PL_Dcel;
typedef CGAL::Arrangement_with_history_2<PL_traits, PL_Dcel> PL_Arrangement; //This is now the only type of arrangement that we actually use
//Handles
typedef PL_Arrangement::Vertex_const_handle Vertex_handle;
typedef PL_Arrangement::Halfedge_const_handle Halfedge_handle;
typedef PL_Arrangement::Curve_const_handle Curve_handle;
//Point location
typedef CGAL::Arr_walk_along_line_point_location<PL_Arrangement> PointLocationAlg;
typedef CGAL::Arr_point_location_result<PL_Arrangement>::Type PointLocationResult;
//Less function to use for (vertex/halfedge/face) handle sets
template <class Handle> struct HandleLess
{
bool operator()(Handle a, Handle b)
{
return (a.ptr() - b.ptr() < 0);
}
};
typedef std::set<Vertex_handle, HandleLess<Vertex_handle>> VertexHandleSet;
//Arrangement observer that keeps the face colours correct
class FaceColorObserver : public CGAL::Arr_observer<PL_Arrangement>
{
private:
bool coloredBeforeMerge;
public:
FaceColorObserver(PL_Arrangement& arrangement) :
CGAL::Arr_observer<PL_Arrangement>(arrangement)
{}
virtual void after_split_face(Face_handle oldFace, Face_handle newFace, bool)
{
newFace->data().colored = oldFace->data().colored;
}
virtual void before_merge_face(Face_handle face1, Face_handle face2, Halfedge_handle)
{
//The assumption is that only same-color faces get merged
CGAL_precondition(face1->data().colored == face2->data().colored);
coloredBeforeMerge = face1->data().colored;// && face2->data().colored;
}
virtual void after_merge_face(Face_handle newFace)
{
newFace->data().colored = coloredBeforeMerge;
}
};
//Arrangement of line segments
typedef CGAL::Arrangement_2<Segment_traits> Seg_Arrangement;
The errors I am getting have to do with the fact that CGAL either thinks the defined Polyline type doesn't have a member Segment_const_iterator, or it fails to properly recognize the type at all. I'm not sure, due to it being translated into an internal CGAL type. The errors I get are:
Error C2039 'Segment_const_iterator': is not a member of 'CGAL::internal::Polycurve_2<SubcurveType_2,PointType_2>' CurvedNonograms c:\users\demeessias\documents\1. studie\0.masterthesis\curvednonograms-code\curvednonograms\curvednonograms\ccbsegmentcirculator.h 39
repeated for the lines containing the definitions of segment,segmentEnd,segmentReverse,and segmentReverseEnd.
According to the documentation, Curve_2 should have a definition for Segment_const_iterator.
Once again, the error is probably not in the code itself, but in my build/linking of CGAL somewhere. Reinstalling CGAL did not help, and I'm pretty sure I have it linked in the relevant places, but this part of building software isn't really my strong suit so I may not know all the relevant spots.
edit: the very first error given in the output is:
c:\users\demeessias\documents\1. studie\0.masterthesis\curvednonograms-code\curvednonograms\curvednonograms\svghandler.cpp(94): error C2039: 'begin_segments': is not a member of 'CGAL::_Curve_data_ex<CGAL::internal::X_monotone_polycurve_2<CGAL::Arr_segment_2<Kernel_>,CGAL::Point_2<Kernel_>>,CGAL::_Unique_list<Data_>>' 2> with 2> [ 2> Kernel_=PL_Kernel, 2> Data_=CGAL::internal::Polycurve_2<CGAL::Arr_segment_2<PL_Kernel>,CGAL::Point_2<CGAL::Epeck>> * 2> ]
This is in a different code file than the one shown above, as there are more errors in the code, but all of them seem to stem from similar problems. there are also some warnings of the form:
2>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(313): warning C4503: '__LINE__Var': decorated name length exceeded, name was truncated
Adding the CCBSegmentCalculator.h to a different project to compile only it gives the following errors:
Severity Code Description Project File Line Suppression State
Error (active) class "CGAL::internal::Polycurve_2<CGAL::Arr_segment_2<CGAL::Exact_predicates_exact_constructions_kernel>, CGAL::Point_2<CGAL::Epeck>>" has no member "Segment_const_iterator" CurvedNonogramsGenerator c:\Users\DeMeessias\Documents\1. Studie\0.MasterThesis\Code\CurvedNonogramsGenerator\CurvedNonogramsGenerator\CCBSegmentCirculator.h 28
Error (active) class "CGAL::internal::Polycurve_2<CGAL::Arr_segment_2<CGAL::Exact_predicates_exact_constructions_kernel>, CGAL::Point_2<CGAL::Epeck>>" has no member "Segment_const_iterator" CurvedNonogramsGenerator c:\Users\DeMeessias\Documents\1. Studie\0.MasterThesis\Code\CurvedNonogramsGenerator\CurvedNonogramsGenerator\CCBSegmentCirculator.h 29
Error (active) class "CGAL::internal::Polycurve_2<CGAL::Arr_segment_2<CGAL::Exact_predicates_exact_constructions_kernel>, CGAL::Point_2<CGAL::Epeck>>" has no member "Segment_const_reverse_iterator" CurvedNonogramsGenerator c:\Users\DeMeessias\Documents\1. Studie\0.MasterThesis\Code\CurvedNonogramsGenerator\CurvedNonogramsGenerator\CCBSegmentCirculator.h 32
Error (active) class "CGAL::internal::Polycurve_2<CGAL::Arr_segment_2<CGAL::Exact_predicates_exact_constructions_kernel>, CGAL::Point_2<CGAL::Epeck>>" has no member "Segment_const_reverse_iterator" CurvedNonogramsGenerator c:\Users\DeMeessias\Documents\1. Studie\0.MasterThesis\Code\CurvedNonogramsGenerator\CurvedNonogramsGenerator\CCBSegmentCirculator.h 33
Error C2039 'Segment_const_iterator': is not a member of 'CGAL::internal::Polycurve_2<SubcurveType_2,PointType_2>' CurvedNonogramsGenerator c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h 28
Error C3646 'segment': unknown override specifier CurvedNonogramsGenerator c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h 28
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int CurvedNonogramsGenerator c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h 28
Error C2039 'Segment_const_iterator': is not a member of 'CGAL::internal::Polycurve_2<SubcurveType_2,PointType_2>' CurvedNonogramsGenerator c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h 29
Error C3646 'segmentEnd': unknown override specifier CurvedNonogramsGenerator c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h 29
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int CurvedNonogramsGenerator c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h 29
Error C2039 'Segment_const_reverse_iterator': is not a member of 'CGAL::internal::Polycurve_2<SubcurveType_2,PointType_2>' CurvedNonogramsGenerator c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h 32
Error C3646 'segmentReverse': unknown override specifier CurvedNonogramsGenerator c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h 32
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int CurvedNonogramsGenerator c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h 32
Error C2039 'Segment_const_reverse_iterator': is not a member of 'CGAL::internal::Polycurve_2<SubcurveType_2,PointType_2>' CurvedNonogramsGenerator c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h 33
Error C3646 'segmentReverseEnd': unknown override specifier CurvedNonogramsGenerator c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h 33
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int CurvedNonogramsGenerator c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h 33
Replace Segment_const_iterator and Segment_const_reverse_iterator with Subcurve_const_iterator and Subcurve_const_reverse_iterator, respectively.
You probably need to replace begin_segments() and end_segments() with subcurves_begin() and subcurves_end(), respectively.
In version (I think) 4.2 we made significant changes to the code. One of the changes was extending the definition of the polylines supported by the arr_polyline_traits_2 traits class. Now, a polyline can be a chain of linear curves that are not necessarily segments. For example, it can have one or two rays as the first and last pieces, or even a line. (Officially, a piece of the polyline can be any curve that can be constructed from two points).
Related
I modified my project and after compiling there pop up some weird error.
#ifndef BART_RAY_TRACER_MESH_H
#define BART_RAY_TRACER_MESH_H
#include <vector>
#include "assert.h"
#include "vec3f.h"
class Triangle;
class Mesh {
public:
uint32_t nverts;
bool _is_static;
vec3f *verts;
vec3f *_verts_world;
Material material;
// 2 error occurs at the line below
Matrix4x4 _trans_local_to_world; // '_trans_local_to_world': unknown override specifier & missing type specifier - int assumed. Note: C++ does not support default-int
Matrix4x4 _trans_local_to_world_inv;
TransformHierarchy *_trans_hierarchy;
std::vector<Triangle* > triangles;
// ...
};
#endif
When I change the order of the declaration a little bit, the error always occurs the line after Material material, but with different message:
#ifndef BART_RAY_TRACER_MESH_H
#define BART_RAY_TRACER_MESH_H
#include <vector>
#include "assert.h"
#include "vec3f.h"
class Triangle;
class Mesh {
public:
uint32_t nverts;
bool _is_static;
vec3f *verts;
vec3f *_verts_world;
Material material;
// 2 error occurs at the line below
TransformHierarchy *_trans_hierarchy; // error C2143: syntax error: missing ';' before '*' & error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Matrix4x4 _trans_local_to_world;
Matrix4x4 _trans_local_to_world_inv;
std::vector<Triangle* > triangles;
// ...
};
#endif
I've searched for similar questions on SO but none seems useful.
I've checked my vec3f, Triangle class definition in case there are missing semicolons but I can't find any.
Can any one help?
This is just another Microsoft cock-up. Here it is in essence:
class C
{
x y ;
} ;
If you submit this to a sensible compiler like g++, it gives you a helpful error message:
3:2: error: 'x' does not name a type
MSVC, on the other hand, comes up with this gibberish:
(3): error C3646: 'y': unknown override specifier
(3): error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
With this key, you can decrypt Microsoft's error message into:
error: 'Matrix4x4' does not name a type
The error is most likely because that TransformHierarchy and Matrix4x4 are not defined.
If they are not defined in "assert.h" and "vec3f.h", this should be the case.
Forward declaration is enough only when you use the reference types and/or pointer types only. Therefore, to forward declare Triangle is OK. But forward declare Triangle does not mean your shape.h is processed. Neither does your material.h which is included in shape.h.
Therefore, all names in material.h is not visible from this code.
TransformHierarchy and Matrix4x4 are not recognized by the compiler.
Many of the compliers will complain with words similar to "missing type specifier - int assumed"
In my case, it was found that a header file had the following directives for a class [ie, myComboBoxData]
#ifndef __COMBOBOXDATA__
#define __COMBOBOXDATA__
// ...
class myComboBoxData
{
// ...
}
#endif
As another class below tried to use myComboBoxData class
class TypeDlg : public CDialog
{
myComboBoxData cbRow,cbCol;
// ...
}
the error message popped up as above:
"error C3646: 'cbRow': unknown override specifier".
Solution:
The problem was the directive name (__COMBOBOXDATA__) was already used by OTHER header.
Thus, make sure to use some other name like (__myCOMBOBOXDATA__).
I get errors compiling the code below when ugrading from VS 2008 to VS2015. The code is from the com4j project. Help wanted. Thanks!
syntax error: missing ';' before '<' missing type specifier
int assumed. Note: C++ does not support default-int
'array': ambiguous symbol
unexpected token(s) preceding ';'
Code:
// Class to marshal SAFEARRAY to Java multi dimensional array
//
// itemType : array item type
// XDUCER : converter for each array item
template < VARTYPE itemType, class XDUCER >
class ToJavaMultiDimlArrayMarshaller {
typedef array::Array<typename XDUCER::JavaType> JARRAY; // Errors here
typedef SAFEARRAY* NativeType;
typedef jarray JavaType;
What does VARTYPE stand for? Is it a macro? Replacing with class or typename may help
I have an issue compiling my code on windows.
On Unix-based systems all is working fine, but when I compile it on windows (currently with visual studio 2010 express), I'm getting the following errors:
Error 253 error C2146: syntax error : missing ';' before identifier 'N0' C:\ghost++\ghost\ohconnect.h 45
Error 254 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\ghost++\ghost\ohconnect.h 45
Error 255 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\ghost++\ghost\ohconnect.h 45
Error 256 error C2146: syntax error : missing ';' before identifier 'N' C:\ghost++\ghost\ohconnect.h 46
Error 257 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\ghost++\ghost\ohconnect.h 46
And so on.
I think it's all relating to my header file, the class itself is made to connect to websockets:
#ifndef OHConnect_H
#define OHConnect_H
//
// OHCONNECT
//
class CTCPClient;
class CBaseGame;
class CCommandPacket;
struct OHCHeader {
unsigned header_size;
bool fin;
bool mask;
enum opcode_type {
CONTINUTATION = 0x0,
TEXT_FRAME = 0x1,
BINARY_FRAME = 0x2,
CLOSE = 8,
PING = 9,
PONG = 0xa,
} opcode;
uint64_t N0;
uint64_t N;
uint8_t masking_key[4];
};
In my .cpp file I'm using namespace std; and included <string> only for windows.
But all this didnt work so far. I didnt wanted to put the whole files into the question since they are actually long.
Here is the full source:
Headerfile
Mainfile
What did I wrong here?
The compiler doesn't know the type uint64_t and uint8_t, add:
#include <cstdint>
Note also that the trailing comma in the enum (after the definition PONG = 0xa) was only standardized in C++11, following the change made in C99. Older compilers or those running in a mode following the older 1998/2003 standard may trip over that as well.
In my c++ program i'm trying to create a dll that houses the functionality of my a* algorithm.
I encounter a problem when trying to pass the map into it, I first tried to use a 2d array, but that limited my map sizes, so i'm now trying to use a vector in a vector and I keep hitting some odd snag.
In my dlls .h file:
namespace IInterface
{
class IInterface
{
public:
// Sets the map
static __declspec(dllexport) void setMap(int h, int w,vector<vector<byte>> &myarray);
private:
static vector<vector<byte>> mymap;
}
Finaly in the .cpp i have:
#include "IInterface.h"
#include <Windows.h>
#include <stdexcept>
#include <vector>
using namespace std;
namespace IInterface
{
void IInterface::setMap(int h, int w,vector<vector<byte>> &myarray)
{
mymap = myarray;
}
}
Im getting a few errors on compilation even tho the code looks fine to me.
error C2061: syntax error : identifier 'vector' c:\users\steven\documents\github\schooladvgdproject\game code\deathastardll\iinterface.h 7 1 DMAstarDLL
error C2143: syntax error : missing ';' before '<' c:\users\steven\documents\github\schooladvgdproject\game code\deathastardll\iinterface.h 21 1 DMAstarDLL
error C2238: unexpected token(s) preceding ';' c:\users\steven\documents\github\schooladvgdproject\game code\deathastardll\iinterface.h 21 1 DMAstarDLL
error C2511: 'void IInterface::IInterface::setMap(int,int,std::vector<_Ty> &)' : overloaded member function not found in 'IInterface::IInterface' c:\users\steven\documents\github\schooladvgdproject\game code\deathastardll\iinterface.cpp 13 1 DMAstarDLL
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\steven\documents\github\schooladvgdproject\game code\deathastardll\iinterface.h 21 1 DMAstarDLL
I looked at some samples, but there was really nothing that matched this scenario. I have a sneaking suspicion i'm forgetting something crucial, but I cant see it. Ideas on getting this to work?
your dlls.h does not include vector type - you should tell the compiler vector definition and include .
Tip: don't use using namespace std; in header file only in cpp. Instead of this use std::vector ...etc.
Secondly, be careful when your dll interface contains stl. This library differs as regards Release and Debug versions, so if you load Release dll in Debug program you could have problems.
This code is not compiling.
What modification can I do to achieve the desired result?
ClassOne.h
#ifndef _CLASS_ONE_
#define _CLASS_ONE_
#include <string>
#include "ClassTwo.h"
class ClassTwo;
class ClassOne
{
private:
string message;
friend ClassTwo;
ClassTwo m_ClassTwo;
public:
ClassOne();
void Display();
};
#endif
ClassTwo.h
#ifndef _CLASS_TWO_
#define _CLASS_TWO_
#include <string>
#include "ClassOne.h"
class ClassOne;
class ClassTwo
{
private:
string message;
friend ClassOne;
ClassOne m_ClassOne;
public:
ClassTwo();
void Display();
};
#endif
ClassOne.cpp
#include "ClassOne.h"
#include "ClassTwo.h"
#include <iostream>
ClassOne :: ClassOne()
{
std::cout<<"ClassOne()...called\n";
this->m_ClassTwo.message = "ClassOne - Message\n";
}
void ClassOne :: Display()
{
std::cout<<this->m_ClassTwo.message;
}
ClassTwo.cpp
#include "ClassTwo.h"
#include "ClassOne.h"
#include <iostream>
ClassTwo :: ClassTwo()
{
std::cout<<"ClassTwo()...called\n";
this->m_ClassOne.message = "ClassTwo - Message\n";
}
void ClassTwo :: Display()
{
std::cout<<this->m_ClassOne.message;
}
main.cpp
#include "ClassOne.h"
#include "ClassTwo.h"
int main()
{
ClassOne one;
one.Display();
ClassTwo two;
two.Display();
}
Error messages
1 error C2146: syntax error : missing ';' before identifier 'message'
2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
4 error C2079: 'ClassTwo::m_ClassOne' uses undefined class 'ClassOne'
5 error C2146: syntax error : missing ';' before identifier 'message'
6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
7 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
8 error C2039: 'message' : is not a member of 'ClassTwo'
9 error C2039: 'message' : is not a member of 'ClassTwo'
10 error C2146: syntax error : missing ';' before identifier 'message'
11 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
12 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
13 error C2079: 'ClassOne::m_ClassTwo' uses undefined class 'ClassTwo'
14 error C2146: syntax error : missing ';' before identifier 'message'
15 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
16 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
17 error C2039: 'message' : is not a member of 'ClassOne'
18 error C2039: 'message' : is not a member of 'ClassOne'
19 error C2146: syntax error : missing ';' before identifier 'message'
20 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
21 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
22 error C2079: 'ClassTwo::m_ClassOne' uses undefined class 'ClassOne'
23 error C2146: syntax error : missing ';' before identifier 'message'
24 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
25 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
You cannot, ever, compile that code. You have described a system where type A contains type B, and type B contains type A. Therefore, both type A and B recursively and infinitely contain themselves, which is impossible. You must fundamentally re-architect your code to eliminate this problem.
Also, your friend syntax is wrong.
As said, you need to forward declare at least one of ClassOne or ClassTwo.
You ClassOne.h could therefor look like:
#ifndef _CLASS_ONE_
#define _CLASS_ONE_
#include <string>
class ClassTwo;
class ClassOne
{
private:
string message;
ClassTwo* m_ClassTwo;
public:
ClassOne();
void Display();
};
#endif
As you can see, we declare ClassTwo, but do not include it. We basically only tell the compiler that yes, we do have a ClassTwo, but we don't really care what it contains right now.
Also look at your ClassTwo member, this is now a pointer. The reason is that a member would require the compiler to know the size of the object, which we currently have no clue what is. Therefor you need either a pointer or a ref.
Next, in your ClassOne.cpp, would will need to include ClassTwo.h, to get the functions and size of that class.
A few things though:
With a forward declaration you can not inherit from ClassTwo, use the methods of the forwarded class in the header file (How would the compiler know which methods exists?) Define functions or methods using the forwarded class, that is you have to pass by reference or pass a pointer.
1) Use forward declarations:
add
class ClassTwo;
to ClassOne.h
and
class ClassTwo;
to ClassTwo.h
2) You need to create your member variables (or at least one of them) dynamically, using operator new, or if you wish, with one of the smart-pointers, like boost::shared_ptr from boost library or std::shared_ptr from standard library if you use C++11.