Форум программистов, компьютерный форум, киберфорум
Boost C++
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.74/19: Рейтинг темы: голосов - 19, средняя оценка - 4.74
7 / 7 / 3
Регистрация: 23.12.2011
Сообщений: 372
Записей в блоге: 1
1

boost Variant

04.07.2012, 18:42. Показов 3511. Ответов 15
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Компилятор ругается что типа не может найти копи констрактор... но я его его вроде как внедрил... что я сделал не так ? Заранее огромное спасибо


log
1>------ Build started: Project: Exercise 3 Variant, Configuration: Debug Win32 ------
1> main.cpp
1>c:\program files\boost\boost_1_47\boost\variant\detail\initializer.hpp(95): error C2558: class 'Line' : no copy constructor available or copy constructor is declared 'explicit'
1> c:\program files\boost\boost_1_47\boost\variant\detail\initializer.hpp(90) : while compiling class template member function 'int boost::detail::variant::make_initializer_node::apply<BaseIndexPair,Iterator>::in itializer_node::initialize(void *,const Line &)'
1> with
1> [
1> BaseIndexPair=boost::mpl:air<boost::detail::variant::make_initializer_node::ap ply<boost::mpl:air<boost::detail::variant::initializer_root,boost::mpl::int_<0 >>,boost::mpl::l_iter<boost::mpl::list2<Point,Line>>>::initializer_node,boost::m pl::int_<1>>,
1> Iterator=boost::mpl::l_iter<boost::mpl::list1<Line>>
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\variant.hpp(1208) : see reference to class template instantiation 'boost::detail::variant::make_initializer_node::apply<BaseIndexPair,Iterator>::i nitializer_node' being compiled
1> with
1> [
1> BaseIndexPair=boost::mpl:air<boost::detail::variant::make_initializer_node::ap ply<boost::mpl:air<boost::detail::variant::initializer_root,boost::mpl::int_<0 >>,boost::mpl::l_iter<boost::mpl::list2<Point,Line>>>::initializer_node,boost::m pl::int_<1>>,
1> Iterator=boost::mpl::l_iter<boost::mpl::list1<Line>>
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\variant.hpp(1327) : see reference to class template instantiation 'boost::variant<T0_,T1>::initializer' being compiled
1> with
1> [
1> T0_=Point,
1> T1=Line
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\variant.hpp(1399) : see reference to function template instantiation 'void boost::variant<T0_,T1>::convert_construct<const T>(T &,int,boost::mpl::false_)' being compiled
1> with
1> [
1> T0_=Point,
1> T1=Line,
1> T=Point
1> ]
1> c:\all my\с++\ha level 8\solution\level 8\exercise 3 variant\main.cpp(28) : see reference to function template instantiation 'boost::variant<T0_,T1>::variant<Point>(const T &)' being compiled
1> with
1> [
1> T0_=Point,
1> T1=Line,
1> T=Point
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
//line.h
#ifndef LINE_H
#define LINE_H
#include "Shape.h"
#include "Point.h"
#include <string>
#include <iostream>
using namespace std;
class Line : public Shape
{
     private:
      Point start; 
      string discrib;
      Point end;
 
   public:
      //constructors and destructor
      Line();
      Line(string x, Point P_start, Point P_end);
      Line(Line& line); // line copy constructor
      ~Line();
        
      //getters and setters
      void SetStart ( Point SomePoint);
      void SetEnd ( Point SomePoint);
      Point GetStart() ;
      Point GetEnd() ;
 
      Line operator = ( Line& l);
     // friend ostream& operator << (ostream& os , const Line& l);
 
      //other useful methods
      void ToString(); 
};
 
#endif
 
//point.h
#ifndef POINT_H 
#define POINT_H
#include "Shape.h"
#include <iostream>
#include <string>
using namespace std;
class Point : public Shape
 
{
    private:
double Xcoord;
double Ycoord;
 
    public:
Point();
Point (double xNew, double yNew);
Point( Point& point); // copy constructor for Point
~Point();
      
void X( double Value);
void Y( double Value);
double X() ;
double Y() ;
 
Point operator = ( Point& p);
friend ostream& operator << (ostream& os ,  Point& p);
void ToString();
 
};
 
#endif 
 
// shape.h 
#ifndef Shape_h 
#define Shape_h
#include <iostream>
#include "stdlib.h"
#include "Shape.h"
using namespace std; 
class Shape
{
    protected: 
int m_id;  // Add a data member for an id number of type int.
    public: 
int id; 
int ID(); // return n_id data
Shape(); // initialises the id using a random number
Shape(const Shape &OtherShape); // copies the id member
Shape operator = (const Shape &OtherShape); // copies the id member
virtual void ToString() ; // returns the id as string e.g. “ID: 123”
};
#endif 
 
//line.cpp
#include <iostream>
//#include <math.h>
#include "line.h"
#include "Point.h"
#include "Shape.h"
#include <string>
using namespace std;
 
Line::Line(){}
 
Line::Line(string x, Point P_start, Point P_end)
    :discrib(x), start(P_start), end(P_end) {}
 
Line::Line( Line& line)
{
    start = line.start;
    end = line.end;
}
 
Line::~Line() {}
 
void Line::SetStart( Point SomePoint)
    {
   start = SomePoint;
    }
 
void Line::SetEnd ( Point SomePoint)
    {
  end = SomePoint;
    }
 
Point Line::GetStart() 
    {
   return start;
    }
 
Point Line::GetEnd() 
    {
   return end;
    }
 
Line Line::operator = ( Line& l)
     {
    if (this == &l)
    {
        return * this; 
    }
    /*member function from base class */
    m_id = l.m_id;
    /* data from derived class*/
    discrib = l.discrib;
    start = l.start;
    end = l.end;
    return *this ;
    } 
 
 
 
void Line::ToString()  // returns the line as string              
    {
    cout << "[[" << discrib << "," 
         << start << "," << end << "]]" << endl;
    }
 
 
//Point.cpp
#include <iostream>
#include "Point.h"
using namespace std;
 
Point::Point() {}
 
 Point::Point (double xNew, double yNew)
     : Xcoord(xNew), Ycoord(yNew) {}
 
Point::~Point() {} //Destructor
 
Point::Point( Point& point) // Point copy constructor
{
    Xcoord = point.Xcoord;
    Ycoord = point.Ycoord;
}
 
 
void Point::X( double Value) 
{//Assign X-coordinate the Value that is put into the main
    Xcoord = Value; 
}
 
void Point::Y( double Value) 
{//Assing Y-coordinate the Value that is put into the main
    Ycoord = Value;
}
 
double Point::X()  
{
return Xcoord;//Return X-coordinate
}
 
double Point::Y()  
{
return Ycoord;//Return Y-coordinate
}
 
 
void Point::ToString()
    {
cout << "( " << X() << "," 
     << Y() << " )";
    }
 
Point Point::operator = ( Point& p)
{
    if (this == &p)
    {
        return * this; 
    }   
 
m_id = p.m_id;// member function from base class    
Xcoord = p.Xcoord;// data from derived class
Ycoord = p.Ycoord;
return *this; 
} 
ostream& operator << (ostream& os ,  Point& p)
    {
        os << "[" << p.X() << "," << p.Y() << "]";
        return os ; 
    }
 
 
 
//Shape.cpp 
#include <iostream>
#include "Shape.h"
using namespace std; 
 
 
Shape::Shape() // initialises the id using a random number
    
    {
    m_id = rand();
    ///cout << "id of shape is: " << m_id << endl; 
    }
 
int Shape::ID() // retrieve the id of the shape
    {
    return m_id; 
    }
    
void Shape::ToString() // returns the id as string              
{
    // cout << "ID: "<< ID(); 
}
 
Shape::Shape(const Shape &OtherShape)
    {//copy constructor that copies the id member
        id = OtherShape.m_id;
    }
    
Shape Shape::operator = (const Shape& OtherShape)
    {//assignment operator that copies the id member
    
    if (this == &OtherShape)
        {
            return *this;
        }
    m_id = OtherShape.m_id;
    return *this; 
    }
 
 
 
//main.cpp
//Variant
 
#include "Point.h"//header file declaration of class Point
#include "Line.h"//header file declaration of class Line
//#include "Circle.h"//header file declaration of class Circle
#include "Shape.h"//header file declaration of class Shape
#include <boost/variant.hpp>//includes boost class for variant
#include <iostream>// C++ style I/O using operator overloading
#include <ostream>
using namespace std;// The C++ logical collection of functions
 
 
//defines a shape type that can be of the form Point, Line or Circle
typedef boost::variant<Point, Line/*, Circle*/> ShapeType;
 
//function that returns a variant with the specified shape
 
ShapeType shape_type(){
int type;//selector variable
cout<<"Please enter 1 for shape of Point type"<<endl;
cout<<"Please enter 2 for shape of Line type"<<endl;
//cout<<"Please enter 3 for shape of Circle type"<<endl;
cin>>type;
 
//assigns the user given type to the variant
if(type==1){//creates a point and returns it
return Point();
}
else if(type==2){//creates a line and returns it
return Line();
}
/*else if(type==3){//creates a circle and returns it
return Circle();
}*/
}
 
//Visitor class
class VisitorClass: public boost::static_visitor<void>{
private:
double m_dx;//x delta to move
double m_dy;//y delta to move
public:
//==================================================================================================
//modifiers
//==================================================================================================
//function that Visits a point and moves its X,Y values
VisitorClass(double xval,double yval):m_dx(xval),m_dy(yval){
}
 
void operator()(Point& p) const{
//modifies the values of the point according to the user given inputs
p.X(p.X()+m_dx);
p.Y(p.Y()+m_dy);
}
 
//function that Visits a Line and moves its X,Y values of the starting and ending points
void operator()(Line& l) const{
//modifies the values of the starting point according to the user given inputs
//l.p1().X(l.p1().X()+m_dx);
//l.p1().Y(l.p1().Y()+m_dy);
l.GetStart().X(l.GetStart().X()+m_dx);
l.GetStart().Y(l.GetStart().Y()+m_dx);
 
 
 
//modifies the values of the ending point according to the user given inputs (scaled by 2)
//l.p2().X(l.p2().X()+m_dx*2);
//l.p2().Y(l.p2().Y()+m_dy*2);
l.GetEnd().X(l.GetEnd().X()+m_dx*2);
l.GetEnd().Y(l.GetEnd().Y()+m_dy*2);
}
 
//function that Visits a Circle and moves its X,Y values of its center
/*void operator()(Circle& c) const{
//modifies the values of the center point with the user given values
c.centerPoint().X((c.centerPoint().X()+m_dx));
c.centerPoint().Y((c.centerPoint().Y()+m_dy));
c.radius(m_dx+m_dy);
}*/
};
 
int main(){
 
//========================================================================================================================
// usage of variant data container
//========================================================================================================================
 
//Assigns a shape type via shape_type function
ShapeType figure=shape_type();
 
//prints the type of the figure given by the user
const std::type_info &ti=figure.type();//captures the type
cout<<"The created figure type is an object of the "<<ti.name()<<endl;//calls its names and prints it
cout<<figure;//the user assignation is sent to the cout using the overloaded << operator in each shape class
 
Line l("MyLine",Point(3,4),Point(6,8));//creates a Line
try{
boost::get<Line>(figure)=l;//assigns Line l to the figure variant
}
catch(boost::bad_get e){
std::cout << "***********************bad get error**************************" <<std::endl;
}
 
boost::apply_visitor(VisitorClass(9,12),figure);//shifts the figure according to a user given values
cout<<figure;//the user assignation is sent to the cout.
return 0;
}
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
04.07.2012, 18:42
Ответы с готовыми решениями:

Boost::variant достать значение
class parser { public: struct DATA { uint8_t vtype; struct st0 { float val0,...

Boost начало работы: Undefined reference to `boost::system::generic_category() '
Добрый день Собственно говоря возникла необходимость использовать boost в работе. Поставил так: ...

Boost Log - undefined reference to `boost::system::system_category()'
Пытаюсь скомпилировать код из примеров Boost Log:#include &lt;boost/log/trivial.hpp&gt; int main(int,...

Использование boost и boost.build с несколькими компиляторами
Здравствуйте! Собрал библиотеку boost и boost.build для двух компиляторов: MinGW 4.5.2 и Visual...

15
AnArtem
04.07.2012, 18:45 2
Кори конструкторы обычно получают const переменную, может проблема в этом?
7 / 7 / 3
Регистрация: 23.12.2011
Сообщений: 372
Записей в блоге: 1
04.07.2012, 19:11  [ТС] 3
Цитата Сообщение от AnArtem Посмотреть сообщение
Кори конструкторы обычно получают const переменную, может проблема в этом?
[quote name='Skydiver' date='04 July 2012 - 08:01 AM' timestamp='1341414107' post='1657320']
I think copy constructors are supposed to take a const reference, not just a reference.
[/quote]


Лог
1>------ Build started: Project: Exercise 3 Variant, Configuration: Debug Win32 ------
1> main.cpp
1>c:\program files\boost\boost_1_47\boost\variant\detail\variant_io.hpp(64): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const T0' (or there is no acceptable conversion)
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(679): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(726): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(764): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(811): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(937): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(944): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(951): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(958): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(968): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>,T>(std::basic_ostream<_Elem,_Traits> &&,_Ty)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> T=T0,
1> _Ty=T0
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(1085): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\boost\boost_1_47\boost\blank.hpp(93): or 'std::basic_ostream<_Elem,_Traits> &boost::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const boost::blank &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\all my\с++\ha level 8\solution\level 8\exercise 3 variant\point.h(26): or 'std::ostream &operator <<(std::ostream &,Point &)' [found using argument-dependent lookup]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(186): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits> &(__cdecl *)(std::basic_ostream<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(192): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(199): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(206): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(226): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(short)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(260): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(280): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(int)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(305): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned int)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(325): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(345): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned long)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(366): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(386): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(407): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(427): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(447): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(467): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(487): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> while trying to match the argument list '(std::basic_ostream<_Elem,_Traits>, const T0)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\variant.hpp(858) : see reference to function template instantiation 'void boost::detail::variant:rinter<OStream>::operator ()<const T>(const T &) const' being compiled
1> with
1> [
1> OStream=std::basic_ostream<char,std::char_traits<char>>,
1> T=T0
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\detail\visitation_impl.hpp(145) : see reference to function template instantiation 'void boost::detail::variant::invoke_visitor<Visitor>::internal_visit<const T>(T &,int)' being compiled
1> with
1> [
1> Visitor=boost::detail::variant:rinter<std::basic_ostream<char,std::char_traits <char>>>,
1> T=T0
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\detail\visitation_impl.hpp(173) : see reference to function template instantiation 'void boost::detail::variant::visitation_impl_invoke_impl<Visitor,VoidPtrCV,T>(int,Vis itor &,VoidPtrCV,T *,boost::mpl::false_)' being compiled
1> with
1> [
1> Visitor=boost::detail::variant::invoke_visitor<boost::detail::variant:rinter<s td::basic_ostream<char,std::char_traits<char>>>>,
1> VoidPtrCV=const void *,
1> T=T0
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\detail\visitation_impl.hpp(256) : see reference to function template instantiation 'void boost::detail::variant::visitation_impl_invoke<Visitor,VoidPtrCV,T0,NoBackupFlag >(int,Visitor &,VoidPtrCV,T *,NoBackupFlag,int)' being compiled
1> with
1> [
1> Visitor=boost::detail::variant::invoke_visitor<boost::detail::variant:rinter<s td::basic_ostream<char,std::char_traits<char>>>>,
1> VoidPtrCV=const void *,
1> NoBackupFlag=boost::variant<Point,Line>::has_fallback_type_,
1> T=T0
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\variant.hpp(1802) : see reference to function template instantiation 'void boost::detail::variant::visitation_impl<first_which,first_step,Visitor,VoidPtrCV ,boost::variant<T0_,T1>::has_fallback_type_>(const int,const int,Visitor &,VoidPtrCV,boost::mpl::false_,NoBackupFlag,Which *,step0 *)' being compiled
1> with
1> [
1> Visitor=boost::detail::variant::invoke_visitor<boost::detail::variant:rinter<s td::basic_ostream<char,std::char_traits<char>>>>,
1> VoidPtrCV=const void *,
1> T0_=Point,
1> T1=Line,
1> NoBackupFlag=boost::variant<Point,Line>::has_fallback_type_,
1> Which=first_which,
1> step0=first_step
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\variant.hpp(1824) : see reference to function template instantiation 'void boost::variant<T0_,T1>::internal_apply_visitor_impl<Visitor,const void*>(int,int,Visitor &,VoidPtrCV)' being compiled
1> with
1> [
1> T0_=Point,
1> T1=Line,
1> Visitor=boost::detail::variant::invoke_visitor<boost::detail::variant:rinter<s td::basic_ostream<char,std::char_traits<char>>>>,
1> VoidPtrCV=const void *
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\variant.hpp(1846) : see reference to function template instantiation 'void boost::variant<T0_,T1>::internal_apply_visitor<boost::detail::variant::invoke_vi sitor<Visitor>>(boost::detail::variant::invoke_visitor<Visitor> &) const' being compiled
1> with
1> [
1> T0_=Point,
1> T1=Line,
1> Visitor=boost::detail::variant:rinter<std::basic_ostream<char,std::char_traits <char>>>
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\detail\variant_io.hpp(88) : see reference to function template instantiation 'void boost::variant<T0_,T1>::apply_visitor<boost::detail::variant:rinter<OStream>>( Visitor &) const' being compiled
1> with
1> [
1> T0_=Point,
1> T1=Line,
1> OStream=std::basic_ostream<char,std::char_traits<char>>,
1> Visitor=boost::detail::variant:rinter<std::basic_ostream<char,std::char_traits <char>>>
1> ]
1> c:\all my\с++\ha level 8\solution\level 8\exercise 3 variant\main.cpp(95) : see reference to function template instantiation 'std::basic_ostream<_Elem,_Traits> &boost::operator <<<char,std::char_traits<char>,Point,Line,boost::detail::variant::void_,boost::d etail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void _,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::var iant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::d etail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void _,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::var iant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::d etail::variant::void_>(std::basic_ostream<_Elem,_Traits> &,const boost::variant<T0_,T1> &)' being compiled
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> T0_=Point,
1> T1=Line
1> ]
1>c:\program files\boost\boost_1_47\boost\variant\detail\variant_io.hpp(64): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const T1' (or there is no acceptable conversion)
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(679): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(726): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(764): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(811): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(937): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(944): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(951): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(958): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(968): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>,T>(std::basic_ostream<_Elem,_Traits> &&,_Ty)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> T=T1,
1> _Ty=T1
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(1085): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\boost\boost_1_47\boost\blank.hpp(93): or 'std::basic_ostream<_Elem,_Traits> &boost::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const boost::blank &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\all my\с++\ha level 8\solution\level 8\exercise 3 variant\point.h(26): or 'std::ostream &operator <<(std::ostream &,Point &)' [found using argument-dependent lookup]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(186): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits> &(__cdecl *)(std::basic_ostream<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(192): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(199): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(206): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(226): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(short)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(260): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(280): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(int)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(305): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned int)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(325): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(345): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned long)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(366): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(386): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(407): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(427): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(447): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(467): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(487): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> while trying to match the argument list '(std::basic_ostream<_Elem,_Traits>, const T1)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\variant.hpp(858) : see reference to function template instantiation 'void boost::detail::variant:rinter<OStream>::operator ()<const T>(const T &) const' being compiled
1> with
1> [
1> OStream=std::basic_ostream<char,std::char_traits<char>>,
1> T=T1
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\detail\visitation_impl.hpp(145) : see reference to function template instantiation 'void boost::detail::variant::invoke_visitor<Visitor>::internal_visit<const T>(T &,int)' being compiled
1> with
1> [
1> Visitor=boost::detail::variant:rinter<std::basic_ostream<char,std::char_traits <char>>>,
1> T=T1
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\detail\visitation_impl.hpp(173) : see reference to function template instantiation 'void boost::detail::variant::visitation_impl_invoke_impl<Visitor,VoidPtrCV,T>(int,Vis itor &,VoidPtrCV,T *,boost::mpl::false_)' being compiled
1> with
1> [
1> Visitor=boost::detail::variant::invoke_visitor<boost::detail::variant:rinter<s td::basic_ostream<char,std::char_traits<char>>>>,
1> VoidPtrCV=const void *,
1> T=T1
1> ]
1> c:\program files\boost\boost_1_47\boost\variant\detail\visitation_impl.hpp(256) : see reference to function template instantiation 'void boost::detail::variant::visitation_impl_invoke<Visitor,VoidPtrCV,T1,NoBackupFlag >(int,Visitor &,VoidPtrCV,T *,NoBackupFlag,int)' being compiled
1> with
1> [
1> Visitor=boost::detail::variant::invoke_visitor<boost::detail::variant:rinter<s td::basic_ostream<char,std::char_traits<char>>>>,
1> VoidPtrCV=const void *,
1> NoBackupFlag=boost::variant<Point,Line>::has_fallback_type_,
1> T=T1
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Все равно не работает
я изменил

Point(const Point& point); // copy constructor for Point
Point operator = (const Point& p); // for Point class
Line operator = (const Line& l) ; //
Line(const Line& line) ; // line copy constructor

Кстати сто пудова не в этом проблема
Это из 11 стандарта последний дрифт что я нашел
12.8:
A non-template constructor for class X is a copy constructor if its first parameter is of type X&, const X&,
volatile X& or const volatile X&
0
В астрале
Эксперт С++
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
04.07.2012, 19:18 4
Leeto, Ну и? Пишет что нет оператора вывода в поток.
Дело в том, что оператор вывода в поток тоже ДОЛЖЕН принимать const ссылку.

Добавлено через 1 минуту
1> c:\program files\boost\boost_1_47\boost\variant\variant.hpp(858) : see reference to function template instantiation 'void boost::detail::variant:rinter<OStream>::operator ()<const T>(const T &) const' being compiled
Вроде ж прозрачно указывается что параметр const T&, а вы пытаетесь вызвать функцию operator <<, который принимает просто ссылку.
1
7 / 7 / 3
Регистрация: 23.12.2011
Сообщений: 372
Записей в блоге: 1
04.07.2012, 19:52  [ТС] 5
Цитата Сообщение от ForEveR Посмотреть сообщение
Leeto, Ну и? Пишет что нет оператора вывода в поток.
Дело в том, что оператор вывода в поток тоже ДОЛЖЕН принимать const ссылку.

Добавлено через 1 минуту


Вроде ж прозрачно указывается что параметр const T&, а вы пытаетесь вызвать функцию operator <<, который принимает просто ссылку.
ну соответственно у хпп тоже поправит теперь он мне подсвечивает см красным
C++
1
2
3
4
5
ostream& operator << (const ostream& os ,const  Point& p)
    {
        os [COLOR="Red"]<<[/COLOR] "[" << p.X() << "," << p.Y() << "]";
        return  [COLOR="red"]os [/COLOR]; 
    }
и пишет типа


log
1>------ Build started: Project: Exercise 3 Variant, Configuration: Debug Win32 ------
1> Point.cpp
1>c:\all my\с++\ha level 8\solution\level 8\exercise 3 variant\point.cpp(65): error C2678: binary '<<' : no operator found which takes a left-hand operand of type 'const std::ostream' (or there is no acceptable conversion)
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(679): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(726): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(764): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(811): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(851): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const _Elem *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(937): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(944): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(951): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(958): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(968): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>,const char*>(std::basic_ostream<_Elem,_Traits> &&,_Ty)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ty=const char *
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(1085): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\all my\с++\ha level 8\solution\level 8\exercise 3 variant\point.h(26): or 'std::ostream &operator <<(const std::ostream &,const Point &)'
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(186): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits> &(__cdecl *)(std::basic_ostream<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(192): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(199): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(206): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(226): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(short)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(260): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(280): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(int)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(305): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned int)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(325): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(345): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned long)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(366): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(386): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(407): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(427): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(447): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(467): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(487): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> while trying to match the argument list '(const std::ostream, const char [2])'
1>c:\all my\с++\ha level 8\solution\level 8\exercise 3 variant\point.cpp(66): error C2440: 'return' : cannot convert from 'const std::ostream' to 'std::ostream &'
1> Conversion loses qualifiers
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
0
В астрале
Эксперт С++
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
04.07.2012, 19:56 6
Leeto, Да потому что функции геттеры ДОЛЖНЫ быть константными и ostream должен передаваться по ссылке, а не const ссылке.
1
7 / 7 / 3
Регистрация: 23.12.2011
Сообщений: 372
Записей в блоге: 1
04.07.2012, 19:56  [ТС] 7
у меня только в point.cpp и соответсвенно в этом классе есть перегрузка << оператора
0
В астрале
Эксперт С++
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
04.07.2012, 19:57 8
Leeto, Ну почитайте книжку-то. Или стандарт. А то лезете в буст, не зная правильной семантике оператора вывода в поток. Зачем?
1
7 / 7 / 3
Регистрация: 23.12.2011
Сообщений: 372
Записей в блоге: 1
04.07.2012, 19:58  [ТС] 9
Цитата Сообщение от ForEveR Посмотреть сообщение
Leeto, Да потому что функции геттеры ДОЛЖНЫ быть константными и ostream должен передаваться по ссылке, а не const ссылке.
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ostream& operator << ( ostream& os , const Point& p)
    {
        os << "[" << p.X() << "," << p.Y() << "]";
        return os ; 
    }
 
 
 
double Point::X()  const
{
return Xcoord;//Return X-coordinate
}
 
double Point::Y()  const
{
return Ycoord;//Return Y-coordinate
}
Типа так ?
0
В астрале
Эксперт С++
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
04.07.2012, 20:01 10
Leeto, Нет.

C++
1
2
3
4
5
ostream& operator << ( ostream& os , const Point& p)
    {
        os << "[" << p.X() << "," << p.Y() << "]";
        return os ; 
    }
Константные функции описаны верно, не забудьте поменять их объявление в .hpp файле.

Возьмите за правило - все функции аксессоры (геттеры) должны быть const функциями. Все операторы сравнения, если они определены в классе, должны быть константными. Все функции в которых не меняется состояние объекта (данные) должны быть константными. Все функции, которые не меняют передаваемого параметра (явно или вызывая другие функции) должны принимать данный параметр по const ссылке.
2
7 / 7 / 3
Регистрация: 23.12.2011
Сообщений: 372
Записей в блоге: 1
04.07.2012, 20:12  [ТС] 11
Компелиться теперь только что херню какую выдает... Помогите разобраться что опять не так...
вот последняя версия кода... ну ничего собственно не изменилось только конст раставил криво наверное но как мог
там типа два принскрина
один это если лайн выбирать
второй если пойнт с поинтом вообще беда какая то не эксепшен выскакивает (((
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
//line.h
#ifndef LINE_H
#define LINE_H
#include "Shape.h"
#include "Point.h"
#include <string>
#include <iostream>
using namespace std;
class Line : public Shape
{
     private:
      Point start; 
      Point end;
 
   public:
      //constructors and destructor
      Line();
      Line(Point P_start, Point P_end);
      Line(const Line& line) ; // line copy constructor
      ~Line();
        
      //getters and setters
      void SetStart ( Point SomePoint);
      void SetEnd ( Point SomePoint);
      Point GetStart() const ;
      Point GetEnd() const;
 
      Line operator = (const Line& l) ; // 
     friend ostream& operator << (ostream& os , const Line& l);
 
      //other useful methods
      void ToString(); 
};
 
#endif
 
//point.h
#ifndef POINT_H 
#define POINT_H
#include "Shape.h"
#include <iostream>
#include <string>
using namespace std;
class Point : public Shape
 
{
    private:
double Xcoord;
double Ycoord;
 
    public:
Point();
Point (double xNew, double yNew);
Point(const Point& point); // copy constructor for Point
~Point();
      
void X( double Value);
void Y( double Value);
double X() const ;
double Y() const ;
Point operator = (const Point& p); // for Point class
friend ostream& operator << ( ostream& os ,const  Point& p);
void ToString();
 
};
 
#endif 
 
// shape.h 
#ifndef Shape_h 
#define Shape_h
#include <iostream>
#include "stdlib.h"
#include "Shape.h"
using namespace std; 
class Shape
{
    protected: 
int m_id;  // Add a data member for an id number of type int.
    public: 
int id; 
int ID(); // return n_id data
Shape(); // initialises the id using a random number
Shape(const Shape &OtherShape); // copies the id member
Shape operator = (const Shape &OtherShape); // copies the id member
virtual void ToString() ; // returns the id as string e.g. “ID: 123”
};
#endif 
 
//line.cpp
#include <iostream>
//#include <math.h>
#include "line.h"
#include "Point.h"
#include "Shape.h"
#include <string>
using namespace std;
 
Line::Line(){}
 
Line::Line(Point P_start, Point P_end)
    : start(P_start), end(P_end) {}
 
Line::Line(const Line& line) 
{
    start = line.start;
    end = line.end;
}
 
Line Line::operator = (const Line& l) 
     {
    if (this == &l)
    {
        return * this; 
    }
    /*member function from base class */
    m_id = l.m_id;
    /* data from derived class*/
    start = l.start;
    end = l.end;
    return *this ;
    } 
 
Line::~Line() {}
 
void Line::SetStart( Point SomePoint)
    {
   start = SomePoint;
    }
 
void Line::SetEnd ( Point SomePoint)
    {
  end = SomePoint;
    }
 
Point Line::GetStart() const
    {
   return start;
    }
 
Point Line::GetEnd() const
    {
   return end;
    }
 
ostream& operator << ( ostream& os , const  Line& l)
    {
        os << "[" << l.GetStart() << "," << l.GetEnd() << "]";
        return os ; 
    }
 
 
 
void Line::ToString()  // returns the line as string              
    {
    cout << "[[" 
         << start << "," << end << "]]" << endl;
    }
 
 
//Point.cpp
#include <iostream>
#include "Point.h"
using namespace std;
 
Point::Point() {}
 
 Point::Point (double xNew, double yNew)
     : Xcoord(xNew), Ycoord(yNew) {}
 
Point::~Point() {} //Destructor
 
Point::Point(const Point& point) // Point copy constructor
{
    Xcoord = point.Xcoord;
    Ycoord = point.Ycoord;
}
 
 
void Point::X( double Value) 
{//Assign X-coordinate the Value that is put into the main
    Xcoord = Value; 
}
 
void Point::Y( double Value) 
{//Assing Y-coordinate the Value that is put into the main
    Ycoord = Value;
}
 
double Point::X()  const
{
return Xcoord;//Return X-coordinate
}
 
double Point::Y()  const
{
return Ycoord;//Return Y-coordinate
}
 
 
void Point::ToString()
    {
cout << "( " << X() << "," 
     << Y() << " )";
    }
 
Point Point::operator = (const Point& p)
{
    if (this == &p)
    {
        return * this; 
    }   
 
m_id = p.m_id;// member function from base class    
Xcoord = p.Xcoord;// data from derived class
Ycoord = p.Ycoord;
return *this; 
} 
 
 
 
 
ostream& operator << ( ostream& os , const  Point& p)
    {
        os << "[" << p.X() << "," << p.Y() << "]";
        return os ; 
    }
 
 
 
//Shape.cpp 
#include <iostream>
#include "Shape.h"
using namespace std; 
 
 
Shape::Shape() // initialises the id using a random number
    
    {
    m_id = rand();
    ///cout << "id of shape is: " << m_id << endl; 
    }
 
int Shape::ID() // retrieve the id of the shape
    {
    return m_id; 
    }
    
void Shape::ToString() // returns the id as string              
{
    // cout << "ID: "<< ID(); 
}
 
Shape::Shape(const Shape &OtherShape)
    {//copy constructor that copies the id member
        id = OtherShape.m_id;
    }
    
Shape Shape::operator = (const Shape& OtherShape)
    {//assignment operator that copies the id member
    
    if (this == &OtherShape)
        {
            return *this;
        }
    m_id = OtherShape.m_id;
    return *this; 
    }
 
 
 
//main.cpp
//Variant
 
#include "Point.h"//header file declaration of class Point
#include "Line.h"//header file declaration of class Line
//#include "Circle.h"//header file declaration of class Circle
#include "Shape.h"//header file declaration of class Shape
#include <boost/variant.hpp>//includes boost class for variant
#include <iostream>// C++ style I/O using operator overloading
#include <ostream>
using namespace std;// The C++ logical collection of functions
 
 
//defines a shape type that can be of the form Point, Line or Circle
typedef boost::variant<Point, Line/*, Circle*/> ShapeType;
 
//function that returns a variant with the specified shape
 
ShapeType shape_type(){
int type;//selector variable
cout<<"Please enter 1 for shape of Point type"<<endl;
cout<<"Please enter 2 for shape of Line type"<<endl;
//cout<<"Please enter 3 for shape of Circle type"<<endl;
cin>>type;
 
//assigns the user given type to the variant
if(type==1){//creates a point and returns it
return Point();
}
else if(type==2){//creates a line and returns it
return Line();
}
/*else if(type==3){//creates a circle and returns it
return Circle();
}*/
}
 
//Visitor class
class VisitorClass: public boost::static_visitor<void>{
private:
double m_dx;//x delta to move
double m_dy;//y delta to move
public:
//==================================================================================================
//modifiers
//==================================================================================================
//function that Visits a point and moves its X,Y values
VisitorClass(double xval,double yval):m_dx(xval),m_dy(yval){
}
 
void operator()(Point& p) const{
//modifies the values of the point according to the user given inputs
p.X(p.X()+m_dx);
p.Y(p.Y()+m_dy);
}
 
//function that Visits a Line and moves its X,Y values of the starting and ending points
void operator()(Line& l) const{
//modifies the values of the starting point according to the user given inputs
//l.p1().X(l.p1().X()+m_dx);
//l.p1().Y(l.p1().Y()+m_dy);
l.GetStart().X(l.GetStart().X()+m_dx);
l.GetStart().Y(l.GetStart().Y()+m_dx);
 
 
 
//modifies the values of the ending point according to the user given inputs (scaled by 2)
//l.p2().X(l.p2().X()+m_dx*2);
//l.p2().Y(l.p2().Y()+m_dy*2);
l.GetEnd().X(l.GetEnd().X()+m_dx*2);
l.GetEnd().Y(l.GetEnd().Y()+m_dy*2);
}
 
//function that Visits a Circle and moves its X,Y values of its center
/*void operator()(Circle& c) const{
//modifies the values of the center point with the user given values
c.centerPoint().X((c.centerPoint().X()+m_dx));
c.centerPoint().Y((c.centerPoint().Y()+m_dy));
c.radius(m_dx+m_dy);
}*/
};
 
int main(){
 
//========================================================================================================================
// usage of variant data container
//========================================================================================================================
 
//Assigns a shape type via shape_type function
ShapeType figure=shape_type();
 
//prints the type of the figure given by the user
const std::type_info &ti=figure.type();//captures the type
cout<<"The created figure type is an object of the "<<ti.name()<<endl;//calls its names and prints it
cout<<figure;//the user assignation is sent to the cout using the overloaded << operator in each shape class
 
Line l(Point(3,4),Point(6,8));//creates a Line
try{
boost::get<Line>(figure)=l;//assigns Line l to the figure variant
}
catch(boost::bad_get e){
std::cout << "***********************bad get error**************************" <<std::endl;
}
 
boost::apply_visitor(VisitorClass(9,12),figure);//shifts the figure according to a user given values
cout<<figure;//the user assignation is sent to the cout.
return 0;
}
Миниатюры
boost Variant   boost Variant  
0
В астрале
Эксперт С++
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
04.07.2012, 20:22 12
Зачем методам модифицирующим так же прифигачили const?
Оператор присваивания ДОЛЖЕН возвращать ссылку на объект.
Ну и на тему Line - он выдает не фигню, а то что и должен, ибо значения не инициализированы, т.к. в конструкторе вы их ничем не инициализируете и в Point аналогично.
1
7 / 7 / 3
Регистрация: 23.12.2011
Сообщений: 372
Записей в блоге: 1
04.07.2012, 20:31  [ТС] 13
Цитата Сообщение от ForEveR Посмотреть сообщение
Зачем методам модифицирующим так же прифигачили const?
а какие именно типа
() оператор
копи констрактор
= оператор
???

со всего это надо убрать ?

Добавлено через 4 минуты
Цитата Сообщение от Leeto Посмотреть сообщение
а какие именно типа
() оператор
копи констрактор
= оператор
???

со всего это надо убрать ?
чо то фейлдит он меня я убираю конст
0
В астрале
Эксперт С++
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
04.07.2012, 20:53 14
Leeto, Не со всего... Ну смотрите сообщения компилятора и ориентируйтесь в них.

Добавлено через 18 минут
Вот ваш код переписанный с const как нужно.

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#include <string>
#include <iostream>
using namespace std;
 
// shape.h 
class Shape
{
    protected: 
int m_id;  // Add a data member for an id number of type int.
    public: 
int id; 
int ID() const; // return n_id data
Shape(); // initialises the id using a random number
Shape(const Shape &OtherShape); // copies the id member
Shape& operator = (const Shape &OtherShape); // copies the id member
virtual void ToString() const ; // returns the id as string e.g. “ID: 123”
};
 
//point.h
class Point : public Shape
 
{
    private:
double Xcoord;
double Ycoord;
 
    public:
Point();
Point (double xNew, double yNew);
Point( const Point& point); // copy constructor for Point
~Point();
      
void X( double Value);
void Y( double Value);
double X() const;
double Y() const;
 
Point& operator = ( const Point& p);
friend ostream& operator << (ostream& os ,  const Point& p);
void ToString() const;
 
};
 
// line.h
class Line : public Shape
{
     private:
      Point start; 
      string discrib;
      Point end;
 
   public:
      //constructors and destructor
      Line();
      Line(const string& x, const Point& P_start, const Point& P_end);
      Line(const Line& line); // line copy constructor
      ~Line();
        
      //getters and setters
      void SetStart ( const Point& SomePoint);
      void SetEnd ( const Point& SomePoint);
      Point GetStart() const ;
      Point GetEnd() const ;
 
      Line& operator = ( const Line& l);
      friend ostream& operator << (ostream& os , const Line& l);
 
      //other useful methods
      void ToString() const; 
};
 
//line.cpp
Line::Line():start(Point(0, 0)), end(Point(0, 0)){}
 
Line::Line(const string& x, const Point& P_start, const Point& P_end)
    :discrib(x), start(P_start), end(P_end) {}
 
Line::Line( const Line& line)
{
    start = line.start;
    end = line.end;
}
 
Line::~Line() {}
 
void Line::SetStart( const Point& SomePoint)
    {
   start = SomePoint;
    }
 
void Line::SetEnd ( const Point& SomePoint)
    {
  end = SomePoint;
    }
 
Point Line::GetStart() const
    {
   return start;
    }
 
Point Line::GetEnd() const
    {
   return end;
    }
 
Line& Line::operator = ( const Line& l)
     {
    if (this == &l)
    {
        return * this; 
    }
    /*member function from base class */
    m_id = l.m_id;
    /* data from derived class*/
    discrib = l.discrib;
    start = l.start;
    end = l.end;
    return *this ;
    } 
 
 
 
void Line::ToString() const  // returns the line as string              
    {
    cout << "[[" << discrib << "," 
         << start << "," << end << "]]" << endl;
    }
 
 
ostream& operator << ( ostream& os , const  Line& l)
    {
        os << "[" << l.GetStart() << "," << l.GetEnd() << "]";
        return os ; 
    }
 
//Point.cpp
 
Point::Point() : Xcoord(0), Ycoord(0) {}
 
 Point::Point (double xNew, double yNew)
     : Xcoord(xNew), Ycoord(yNew) {}
 
Point::~Point() {} //Destructor
 
Point::Point( const Point& point) // Point copy constructor
{
    Xcoord = point.Xcoord;
    Ycoord = point.Ycoord;
}
 
 
void Point::X( double Value) 
{//Assign X-coordinate the Value that is put into the main
    Xcoord = Value; 
}
 
void Point::Y( double Value) 
{//Assing Y-coordinate the Value that is put into the main
    Ycoord = Value;
}
 
double Point::X()  const
{
return Xcoord;//Return X-coordinate
}
 
double Point::Y()  const
{
return Ycoord;//Return Y-coordinate
}
 
 
void Point::ToString() const
    {
cout << "( " << X() << "," 
     << Y() << " )";
    }
 
Point& Point::operator = ( const Point& p)
{
    if (this == &p)
    {
        return * this; 
    }   
 
m_id = p.m_id;// member function from base class    
Xcoord = p.Xcoord;// data from derived class
Ycoord = p.Ycoord;
return *this; 
}
 
ostream& operator << (ostream& os ,  const Point& p)
    {
        os << "[" << p.X() << "," << p.Y() << "]";
        return os ; 
    }
 
 
Shape::Shape() // initialises the id using a random number
    
    {
    m_id = rand();
    ///cout << "id of shape is: " << m_id << endl; 
    }
 
int Shape::ID() const // retrieve the id of the shape
    {
    return m_id; 
    }
    
void Shape::ToString() const // returns the id as string              
{
    // cout << "ID: "<< ID(); 
}
 
Shape::Shape(const Shape &OtherShape)
    {//copy constructor that copies the id member
        id = OtherShape.m_id;
    }
    
Shape& Shape::operator = (const Shape& OtherShape)
    {//assignment operator that copies the id member
    
    if (this == &OtherShape)
        {
            return *this;
        }
    m_id = OtherShape.m_id;
    return *this; 
    }
 
 
 
//main.cpp
//Variant
 
#include <boost/variant.hpp>//includes boost class for variant
#include <iostream>// C++ style I/O using operator overloading
 
 
//defines a shape type that can be of the form Point, Line or Circle
typedef boost::variant<Point, Line/*, Circle*/> ShapeType;
 
//function that returns a variant with the specified shape
 
ShapeType shape_type(){
int type;//selector variable
cout<<"Please enter 1 for shape of Point type"<<endl;
cout<<"Please enter 2 for shape of Line type"<<endl;
//cout<<"Please enter 3 for shape of Circle type"<<endl;
cin>>type;
 
//assigns the user given type to the variant
if(type==1){//creates a point and returns it
return Point();
}
else if(type==2){//creates a line and returns it
return Line();
}
/*else if(type==3){//creates a circle and returns it
return Circle();
}*/
}
 
//Visitor class
class VisitorClass: public boost::static_visitor<void>{
private:
double m_dx;//x delta to move
double m_dy;//y delta to move
public:
//==================================================================================================
//modifiers
//==================================================================================================
//function that Visits a point and moves its X,Y values
VisitorClass(double xval,double yval):m_dx(xval),m_dy(yval){
}
 
void operator()(Point& p) const{
//modifies the values of the point according to the user given inputs
p.X(p.X()+m_dx);
p.Y(p.Y()+m_dy);
}
 
//function that Visits a Line and moves its X,Y values of the starting and ending points
void operator()(Line& l) const{
//modifies the values of the starting point according to the user given inputs
//l.p1().X(l.p1().X()+m_dx);
//l.p1().Y(l.p1().Y()+m_dy);
l.GetStart().X(l.GetStart().X()+m_dx);
l.GetStart().Y(l.GetStart().Y()+m_dx);
 
 
 
//modifies the values of the ending point according to the user given inputs (scaled by 2)
//l.p2().X(l.p2().X()+m_dx*2);
//l.p2().Y(l.p2().Y()+m_dy*2);
l.GetEnd().X(l.GetEnd().X()+m_dx*2);
l.GetEnd().Y(l.GetEnd().Y()+m_dy*2);
}
 
//function that Visits a Circle and moves its X,Y values of its center
/*void operator()(Circle& c) const{
//modifies the values of the center point with the user given values
c.centerPoint().X((c.centerPoint().X()+m_dx));
c.centerPoint().Y((c.centerPoint().Y()+m_dy));
c.radius(m_dx+m_dy);
}*/
};
 
int main(){
 
//========================================================================================================================
// usage of variant data container
//========================================================================================================================
 
//Assigns a shape type via shape_type function
ShapeType figure=shape_type();
 
//prints the type of the figure given by the user
const std::type_info &ti=figure.type();//captures the type
cout<<"The created figure type is an object of the "<<ti.name()<<endl;//calls its names and prints it
cout<<figure;//the user assignation is sent to the cout using the overloaded << operator in each shape class
 
Line l("MyLine",Point(3,4),Point(6,8));//creates a Line
try{
boost::get<Line>(figure)=l;//assigns Line l to the figure variant
}
catch(boost::bad_get e){
std::cout << "***********************bad get error**************************" <<std::endl;
}
 
boost::apply_visitor(VisitorClass(9,12),figure);//shifts the figure according to a user given values
cout<<figure;//the user assignation is sent to the cout.
return 0;
}
1
7 / 7 / 3
Регистрация: 23.12.2011
Сообщений: 372
Записей в блоге: 1
11.07.2012, 14:32  [ТС] 15
Цитата Сообщение от ForEveR Посмотреть сообщение
Leeto, Не со всего... Ну смотрите сообщения компилятора и ориентируйтесь в них.

Добавлено через 18 минут
Вот ваш код переписанный с const как нужно.

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#include <string>
#include <iostream>
using namespace std;
 
// shape.h 
class Shape
{
    protected: 
int m_id;  // Add a data member for an id number of type int.
    public: 
int id; 
int ID() const; // return n_id data
Shape(); // initialises the id using a random number
Shape(const Shape &OtherShape); // copies the id member
Shape& operator = (const Shape &OtherShape); // copies the id member
virtual void ToString() const ; // returns the id as string e.g. “ID: 123”
};
 
//point.h
class Point : public Shape
 
{
    private:
double Xcoord;
double Ycoord;
 
    public:
Point();
Point (double xNew, double yNew);
Point( const Point& point); // copy constructor for Point
~Point();
      
void X( double Value);
void Y( double Value);
double X() const;
double Y() const;
 
Point& operator = ( const Point& p);
friend ostream& operator << (ostream& os ,  const Point& p);
void ToString() const;
 
};
 
// line.h
class Line : public Shape
{
     private:
      Point start; 
      string discrib;
      Point end;
 
   public:
      //constructors and destructor
      Line();
      Line(const string& x, const Point& P_start, const Point& P_end);
      Line(const Line& line); // line copy constructor
      ~Line();
        
      //getters and setters
      void SetStart ( const Point& SomePoint);
      void SetEnd ( const Point& SomePoint);
      Point GetStart() const ;
      Point GetEnd() const ;
 
      Line& operator = ( const Line& l);
      friend ostream& operator << (ostream& os , const Line& l);
 
      //other useful methods
      void ToString() const; 
};
 
//line.cpp
Line::Line():start(Point(0, 0)), end(Point(0, 0)){}
 
Line::Line(const string& x, const Point& P_start, const Point& P_end)
    :discrib(x), start(P_start), end(P_end) {}
 
Line::Line( const Line& line)
{
    start = line.start;
    end = line.end;
}
 
Line::~Line() {}
 
void Line::SetStart( const Point& SomePoint)
    {
   start = SomePoint;
    }
 
void Line::SetEnd ( const Point& SomePoint)
    {
  end = SomePoint;
    }
 
Point Line::GetStart() const
    {
   return start;
    }
 
Point Line::GetEnd() const
    {
   return end;
    }
 
Line& Line::operator = ( const Line& l)
     {
    if (this == &l)
    {
        return * this; 
    }
    /*member function from base class */
    m_id = l.m_id;
    /* data from derived class*/
    discrib = l.discrib;
    start = l.start;
    end = l.end;
    return *this ;
    } 
 
 
 
void Line::ToString() const  // returns the line as string              
    {
    cout << "[[" << discrib << "," 
         << start << "," << end << "]]" << endl;
    }
 
 
ostream& operator << ( ostream& os , const  Line& l)
    {
        os << "[" << l.GetStart() << "," << l.GetEnd() << "]";
        return os ; 
    }
 
//Point.cpp
 
Point::Point() : Xcoord(0), Ycoord(0) {}
 
 Point::Point (double xNew, double yNew)
     : Xcoord(xNew), Ycoord(yNew) {}
 
Point::~Point() {} //Destructor
 
Point::Point( const Point& point) // Point copy constructor
{
    Xcoord = point.Xcoord;
    Ycoord = point.Ycoord;
}
 
 
void Point::X( double Value) 
{//Assign X-coordinate the Value that is put into the main
    Xcoord = Value; 
}
 
void Point::Y( double Value) 
{//Assing Y-coordinate the Value that is put into the main
    Ycoord = Value;
}
 
double Point::X()  const
{
return Xcoord;//Return X-coordinate
}
 
double Point::Y()  const
{
return Ycoord;//Return Y-coordinate
}
 
 
void Point::ToString() const
    {
cout << "( " << X() << "," 
     << Y() << " )";
    }
 
Point& Point::operator = ( const Point& p)
{
    if (this == &p)
    {
        return * this; 
    }   
 
m_id = p.m_id;// member function from base class    
Xcoord = p.Xcoord;// data from derived class
Ycoord = p.Ycoord;
return *this; 
}
 
ostream& operator << (ostream& os ,  const Point& p)
    {
        os << "[" << p.X() << "," << p.Y() << "]";
        return os ; 
    }
 
 
Shape::Shape() // initialises the id using a random number
    
    {
    m_id = rand();
    ///cout << "id of shape is: " << m_id << endl; 
    }
 
int Shape::ID() const // retrieve the id of the shape
    {
    return m_id; 
    }
    
void Shape::ToString() const // returns the id as string              
{
    // cout << "ID: "<< ID(); 
}
 
Shape::Shape(const Shape &OtherShape)
    {//copy constructor that copies the id member
        id = OtherShape.m_id;
    }
    
Shape& Shape::operator = (const Shape& OtherShape)
    {//assignment operator that copies the id member
    
    if (this == &OtherShape)
        {
            return *this;
        }
    m_id = OtherShape.m_id;
    return *this; 
    }
 
 
 
//main.cpp
//Variant
 
#include <boost/variant.hpp>//includes boost class for variant
#include <iostream>// C++ style I/O using operator overloading
 
 
//defines a shape type that can be of the form Point, Line or Circle
typedef boost::variant<Point, Line/*, Circle*/> ShapeType;
 
//function that returns a variant with the specified shape
 
ShapeType shape_type(){
int type;//selector variable
cout<<"Please enter 1 for shape of Point type"<<endl;
cout<<"Please enter 2 for shape of Line type"<<endl;
//cout<<"Please enter 3 for shape of Circle type"<<endl;
cin>>type;
 
//assigns the user given type to the variant
if(type==1){//creates a point and returns it
return Point();
}
else if(type==2){//creates a line and returns it
return Line();
}
/*else if(type==3){//creates a circle and returns it
return Circle();
}*/
}
 
//Visitor class
class VisitorClass: public boost::static_visitor<void>{
private:
double m_dx;//x delta to move
double m_dy;//y delta to move
public:
//==================================================================================================
//modifiers
//==================================================================================================
//function that Visits a point and moves its X,Y values
VisitorClass(double xval,double yval):m_dx(xval),m_dy(yval){
}
 
void operator()(Point& p) const{
//modifies the values of the point according to the user given inputs
p.X(p.X()+m_dx);
p.Y(p.Y()+m_dy);
}
 
//function that Visits a Line and moves its X,Y values of the starting and ending points
void operator()(Line& l) const{
//modifies the values of the starting point according to the user given inputs
//l.p1().X(l.p1().X()+m_dx);
//l.p1().Y(l.p1().Y()+m_dy);
l.GetStart().X(l.GetStart().X()+m_dx);
l.GetStart().Y(l.GetStart().Y()+m_dx);
 
 
 
//modifies the values of the ending point according to the user given inputs (scaled by 2)
//l.p2().X(l.p2().X()+m_dx*2);
//l.p2().Y(l.p2().Y()+m_dy*2);
l.GetEnd().X(l.GetEnd().X()+m_dx*2);
l.GetEnd().Y(l.GetEnd().Y()+m_dy*2);
}
 
//function that Visits a Circle and moves its X,Y values of its center
/*void operator()(Circle& c) const{
//modifies the values of the center point with the user given values
c.centerPoint().X((c.centerPoint().X()+m_dx));
c.centerPoint().Y((c.centerPoint().Y()+m_dy));
c.radius(m_dx+m_dy);
}*/
};
 
int main(){
 
//========================================================================================================================
// usage of variant data container
//========================================================================================================================
 
//Assigns a shape type via shape_type function
ShapeType figure=shape_type();
 
//prints the type of the figure given by the user
const std::type_info &ti=figure.type();//captures the type
cout<<"The created figure type is an object of the "<<ti.name()<<endl;//calls its names and prints it
cout<<figure;//the user assignation is sent to the cout using the overloaded << operator in each shape class
 
Line l("MyLine",Point(3,4),Point(6,8));//creates a Line
try{
boost::get<Line>(figure)=l;//assigns Line l to the figure variant
}
catch(boost::bad_get e){
std::cout << "***********************bad get error**************************" <<std::endl;
}
 
boost::apply_visitor(VisitorClass(9,12),figure);//shifts the figure according to a user given values
cout<<figure;//the user assignation is sent to the cout.
return 0;
}
Спасибо огромное !
0
7 / 7 / 3
Регистрация: 23.12.2011
Сообщений: 372
Записей в блоге: 1
22.07.2012, 17:37  [ТС] 16
Цитата Сообщение от Leeto Посмотреть сообщение
Спасибо огромное !
Что то Поинт класс работает, а Лайн значение дефолтного конструктора выдает... сейчас стоит [(1,2) (3,1)], но визитор не как точки не изменяет. А мне надо что чтобы сетилось то что я назвал MyLine [(3,4) (6,8)]


C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
// line.h
#ifndef LINE_H
#define LINE_H
#include "Shape.h"
#include "Point.h"
#include <ostream>
 
class Line : public Shape
{
     private:
      Point start; 
     // string discrib;
      Point end;
 
   public:
      //constructors and destructor
      Line();
      Line(  Point& P_start,  Point& P_end);
      Line(const Line& line); // line copy constructor
      ~Line();
        
      //getters and setters
      void SetStart (  Point& SomePoint);
      void SetEnd (  Point& SomePoint);
      Point GetStart() const ;
      Point GetEnd() const ;
 
      Line& operator = ( const Line& l);
      friend ostream& operator << (ostream& os , const Line& l);
 
      //other useful methods
      void ToString() const; 
};
 
#endif 
 
//point.h
#ifndef POINT_H
#define POINT_H
 
#include "Shape.h"
#include <ostream>
class Point : public Shape
 
{
    private:
double Xcoord;
double Ycoord;
 
    public:
Point();
Point (double xNew, double yNew);
Point( const Point& point); // copy constructor for Point
~Point();
      
void X( double Value);
void Y( double Value);
double X() const;
double Y() const;
 
Point& operator = ( const Point& p);
friend ostream& operator << (ostream& os ,  const Point& p);
void ToString() const;
 
};
 
#endif 
 
#ifndef Shape_h
#define Shape_h
#include <string>
#include <iostream>
using namespace std;
 
// shape.h 
class Shape
{
    protected: 
int m_id;  // Add a data member for an id number of type int.
    public: 
int id; 
int ID() const; // return n_id data
Shape(); // initialises the id using a random number
Shape(const Shape &OtherShape); // copies the id member
Shape& operator = (const Shape &OtherShape); // copies the id member
virtual void ToString() const ; // returns the id as string e.g. “ID: 123”
};
 
 
#endif 
 
//line.cpp
#include <iostream>
#include "line.h"
 
using namespace std;
Line::Line():start(Point(1, 2)), end(Point(3, 1)){}
 
Line::Line( Point& P_start,  Point& P_end)
    : start(P_start), end(P_end) {}
 
Line::Line( const Line& line)
{
    start = line.start;
    end = line.end;
}
 
Line::~Line() {}
 
void Line::SetStart(  Point& SomePoint)
    {
   start = SomePoint;
    }
 
void Line::SetEnd (  Point& SomePoint)
    {
  end = SomePoint;
    }
 
Point Line::GetStart() const
    {
   return start;
    }
 
Point Line::GetEnd() const
    {
   return end;
    }
 
Line& Line::operator = ( const Line& l)
     {
    if (this == &l)
    {
        return * this; 
    }
    /*member function from base class */
    m_id = l.m_id;
    /* data from derived class*/
   
    start = l.start;
    end = l.end;
    return *this ;
    } 
 
 
 
void Line::ToString() const  // returns the line as string              
    {
    cout << "[["  
         << start << "," << end << "]]" << endl;
    }
 
 
ostream& operator << ( ostream& os , const  Line& l)
    {
        os << "[" << l.GetStart() << "," << l.GetEnd() << "]";
        return os ; 
    }
 
//Point.cpp
 #include <iostream>
#include "Point.h"
 
using namespace std;
 
Point::Point() : Xcoord(0), Ycoord(0) {}
 
 Point::Point (double xNew, double yNew)
     : Xcoord(xNew), Ycoord(yNew) {}
 
Point::~Point() {} //Destructor
 
Point::Point( const Point& point) // Point copy constructor
{
    Xcoord = point.Xcoord;
    Ycoord = point.Ycoord;
}
 
 
void Point::X( double Value) 
{//Assign X-coordinate the Value that is put into the main
    Xcoord = Value; 
}
 
void Point::Y( double Value) 
{//Assing Y-coordinate the Value that is put into the main
    Ycoord = Value;
}
 
double Point::X()  const
{
return Xcoord;//Return X-coordinate
}
 
double Point::Y()  const
{
return Ycoord;//Return Y-coordinate
}
 
 
void Point::ToString() const
    {
cout << "( " << X() << "," 
     << Y() << " )";
    }
 
Point& Point::operator = ( const Point& p)
{
    if (this == &p)
    {
        return * this; 
    }   
 
m_id = p.m_id;// member function from base class    
Xcoord = p.Xcoord;// data from derived class
Ycoord = p.Ycoord;
return *this; 
}
 
ostream& operator << (ostream& os ,  const Point& p)
    {
        os << "[" << p.X() << "," << p.Y() << "]";
        return os ; 
    }
 
 
 
 
//Shape.cpp 
#include <iostream>
#include "Shape.h"
 
//using namespace std; 
 
 
 
Shape::Shape() // initialises the id using a random number
    
    {
    m_id = rand();
    ///cout << "id of shape is: " << m_id << endl; 
    }
 
int Shape::ID() const // retrieve the id of the shape
    {
    return m_id; 
    }
    
void Shape::ToString()  const// returns the id as string              
{
    // cout << "ID: "<< ID(); 
}
 
Shape::Shape(const Shape &OtherShape)
    {//copy constructor that copies the id member
        id = OtherShape.m_id;
    }
    
Shape& Shape::operator = (const Shape& OtherShape)
    {//assignment operator that copies the id member
    
    if (this == &OtherShape)
        {
            return *this;
        }
    m_id = OtherShape.m_id;
    return *this; 
    }
 
 
 
//main.cpp
 
#include "Point.h"                  //header file declaration of class Point
#include "Line.h"                   //header file declaration of class Line
//#include "Circle.h"               //header file declaration of class Circle
#include "Shape.h"                  //header file declaration of class Shape
#include <boost/variant.hpp>        //includes boost class for variant
#include <iostream>                 // C++ style I/O using operator overloading
#include <ostream>
using namespace std;                // The C++ logical collection of functions
 
 
//defines a shape type that can be of the form Point, Line or Circle
typedef boost::variant<Point, Line/*, Circle*/> ShapeType;
 
//function that returns a variant with the specified shape
 
ShapeType shape_type()
{
int type;//selector variable
cout<<"Please enter 1 for shape of Point type"<<endl;
cout<<"Please enter 2 for shape of Line type"<<endl;
//cout<<"Please enter 3 for shape of Circle type"<<endl;
cin>>type;
 
//assigns the user given type to the variant
    if(type==1)
        {                       //creates a point and returns it
        return Point();
        }
    else if(type==2)
        {               //creates a line and returns it
        return Line();
        }
/*else if(type==3){//creates a circle and returns it
return Circle();
}*/
}
 
//Visitor class
class VisitorClass: public boost::static_visitor<void>
{
private:
double m_dx;//x delta to move
double m_dy;//y delta to move
public:
//==================================================================================================
//modifiers
//==================================================================================================
//function that Visits a point and moves its X,Y values
    VisitorClass(double xval,double yval):m_dx(xval),m_dy(yval) {}
 
 
void operator()(Point& p) const 
{
//modifies the values of the point according to the user given inputs
p.X(p.X()+m_dx);
p.Y(p.Y()+m_dy);
}
 
//function that Visits a Line and moves its X,Y values of the starting and ending points
void operator()(Line& l) const 
{
//modifies the values of the starting point according to the user given inputs
//l.p1().X(l.p1().X()+m_dx);
//l.p1().Y(l.p1().Y()+m_dy);
//l.GetStart().X(l.GetStart().X()+m_dx);
//l.GetStart().Y(l.GetStart().Y()+m_dx);
l.GetStart().X(l.GetStart().X()+m_dx);
l.GetStart().Y(l.GetStart().Y()+m_dx);
 
 
 
//modifies the values of the ending point according to the user given inputs (scaled by 2)
//l.p2().X(l.p2().X()+m_dx*2);
//l.p2().Y(l.p2().Y()+m_dy*2);
l.GetEnd().X(l.GetEnd().X()+m_dx*2);
l.GetEnd().Y(l.GetEnd().Y()+m_dy*2);
}
 
//function that Visits a Circle and moves its X,Y values of its center
/*void operator()(Circle& c) const{
//modifies the values of the center point with the user given values
c.centerPoint().X((c.centerPoint().X()+m_dx));
c.centerPoint().Y((c.centerPoint().Y()+m_dy));
c.radius(m_dx+m_dy);
}*/
};
 
int main(){
 
//========================================================================================================================
// usage of variant data container
//========================================================================================================================
 Point p(11,1);
 Point p1(2,2);
 Point p2(3,3);
Line l(Point(3,4),Point(6,8));
//Assigns a shape type via shape_type function
ShapeType figure=shape_type();
 cout << "\n\n\t myLine" << l << "\n\n\t";
 
  try
{
 
 
switch (figure.which())
{
case 0: cout << "\n\n\tPoint"; break;
case 1: cout << "\n\n\tLine"; break;
default : cout << "invalide input" ; 
}
 
 
//the user assignation is sent to the cout using the overloaded << operator in each shape class
 
//creates a Line
 
    
boost::get<Point>(figure)=p;//assigns Line l to the figure variant
boost::get<Line>(figure)=l;//assigns Line l to the figure variant
}
catch(boost::bad_get e)
{
std::cout << "\n\n\t***********************bad get error**************************" <<std::endl;
}
 
 cout<<"\n\n\t BEFORE VISITOR "<< figure << "\n\n\t ";
boost::apply_visitor(VisitorClass(9,12),figure);//shifts the figure according to a user given values
cout<<"\n\n\t AFTER VISITOR "<<figure;//the user assignation is sent to the cout.
cout << "\n\n\t";
system ("pause");
return 0;
}
Миниатюры
boost Variant  
0
22.07.2012, 17:37
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
22.07.2012, 17:37
Помогаю со студенческими работами здесь

Метапрограммирование в boost::proto (boost::spirit)
В библиотеке boost:: proto есть такой код calculator&lt;proto::terminal&lt;placeholder&lt;0&gt; &gt;::type&gt;...

Qt и boost boost::system::generic_category()
Добрый день Не подскажите как настроить Qt на работу с boost? У меня в принципе все работает:...

boost::geometry::model::box и boost::geometry::area
Здравствуйте! Пытаюсь измерить площадь box'a :D, но не знаю как правильно это сделать. Вот этот код...

Get для std::variant
Задача: сделать простой метод get() без параметров, который буде возвращать установленное в...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
16
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru