STL

who body can find what is wrong in this code :
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
template<class f, class h, class g>
struct myfun : public unary_function<typename g::argument_type, typename f::result_type> {
	myfun(f &o1, h &o2, g &o3) : op1( o1 ), op2( o2 ), op3( o3 )
	{ }

	result_type operator ()(const typename argument_type &x) const
	{
		return op1(op2( x ), op3( x ));
	}
	
private:
	f op1;
	h op2;
	g op3;
};

template<class T>
struct my : unary_function<typename T::argument_type, bool> {
	my(const T &o) : op( op )
	{ }

	bool operator ()(const typename T::argument_type &arg) const 
	{
		return ( !op( arg ) );
	}

private:
	T op;
};

void main()
{
	myfun<logical_and<int>, binder1st<less<int> >, binder2nd<less<int> > > m(logical_and<int>(), bind1st(less<int>(), 3), bind2nd(less<int>(), 8));

	my<myfun<logical_and<int>, binder1st<less<int> >, binder2nd<less<int> > > > x( m );

	for (int i = 0; i < 10; i++)
		cout << x( i ) << " "; // its wrong but why ?!!! Very interesting for me because all of value is 1 !!! 
// you can test m( i ) instead of x( i ) and see ....

	cin.get();
}

i just do some practicing for myself and declare this class but its wrong and very interesting because it to come be correct!!!
Last edited on
It does not compile:
_ main must return int.
_ invalid initialization of non-const reference from a temporary

Also, you've got a typo. Line 19: my(const T &o) : op( op )
Last edited on
hey nan they are true
1) main can be void and dont return type !
2) T op is static not a pointer or reference so "You can copy const T &o in op because it be copy"!when your idea is true that "T op" be "T &op" or "T *op" not "T op"

they are not my problem!!! please compile it
Last edited on
1) main can be void and dont return type !


This is incorrect. The C++ standard is very clear on this. If your compiler accepts main returning void, your compiler is wrong. Your compiler is not a C++ compiler. It compiles something that is similar to C++, but it is not C++.
my compile is "Microsoft Visual Studio Professional 2008 Sp 1" and its strongest IDE & compiler in the world for C++ !!!! :)) now do you think its not a good compiler or similar C++ compiler ?!!!!!! main can be void but it better be int ! we can use void because C++ inherit and built on C and we can use of C code in C++ and its not be wrong! please solve this code !! if i change void to int doesnt solve my error !
Last edited on
please solve why class "my" dont work !!! it must return negate of op but .... :(
my compile is "Microsoft Visual Studio Professional 2008 Sp 1" and its strongest IDE & compiler in the world for C++ !!!! :))


So many mistakes in that sentence that I'm not sure you actually understand what C++ is (or what a compiler is). Never mind, not understanding that seems to be no impediment to many people.
hey man what is your problem ?!!! i cant speak eng very well !!!! please solve my code ! im not here fighting with you !!!!!!!!
closed account (1vRz3TCk)
It compiles under VS2008 but not VS2010.

"Microsoft Visual Studio Professional 2008 Sp 1" and its strongest IDE & compiler in the world for C++ !!!!
They have either made VS worse or there is a problem with the implementation of STL (on either). But either which way that is some ugly code.

Last edited on
i cant under stand your mean but i write this code with vc 2010 :((((((((
just class "my" is wrong but i cant understand why ?!!!!!!! its very very very very interesting !!! i become crazy :(((

if you use not1( myfun ) its work correctly this mean myfun is right !!!
Calm down.
Again, Line 19: my(const T &o) : op( op ). You are not using the parameter.
It should be my(const T &parameter) : member(parameter)
oh oh oh very very very bad mistake X_X
tnx
and tnx all my friend
Topic archived. No new replies allowed.