about some peace of code from egui library

Hi,
I found a gui libarary EGUI and trying to learn from it, there's some interesting code I don't understand

a struct default_ is used a lot in the status_bar.cpp
http://egui.codeplex.com/SourceControl/changeset/view/81799#166136
1
2
3
4
5
6
7
8
9
    temporary_icon get_pane_icon(int val) const {
        return default_();
    }
    string get_pane_tip_text(int val) const {
        return default_();
    }
    rectangle get_pane_rect(int val) const {
        return default_();
    }

it is used to return all kinds of stuff, the implementation of default_:
http://egui.codeplex.com/SourceControl/changeset/view/81799#151405
1
2
3
4
struct default_ {
    template<class type> 
	operator type() const { return type(); }
};


why it doesn't compile for std::string?
1
2
3
std::string default_text() {
	return default_(); // this causes error C2668: ambiguous call to overloaded function ....
}
Last edited on
> why it doesn't compile for std::string?

Can't say without seeing more of the code base.
In isolation, it will compile cleanly.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <string>

struct default_ { template< typename T > operator T() const { return T() ; } };

std::string default_text() { return default_() ; }

int main()
{
    std::cout << default_text().size() << '\n' ;
}


Check if the library has specializations of default_; it should.
Did you include <string> ?
Did you include <string> ?

yes I did include <string>

In isolation, it will compile cleanly.

I tried your code, it doesn't compile either.. maybe it's compiler problem? I'm using vs2012

the screenshot
http://i1021.photobucket.com/albums/af333/aj3423/default__zpsac8adc65.png
Last edited on
Yeah, VS gives an error if there are multiple single argument constructors, even if only one of them is a default constructor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
struct default_ { template< typename T > operator T() const { return T() ; } };

struct A { A( int = 0 ) {} A( double ) {} A( const A& ) {} A( A&& ) {} A( char, char ) {} } ;

A default_A() { return default_() ; }

int main()
{
    A a = default_A() ;
}

/*

error C2668: 'A::A' : ambiguous call to overloaded function
1>  could be 'A::A(A &&)'
1>  or 'A::A(double)'
1>  or 'A::A(int)'
*/

thanks a lot
Topic archived. No new replies allowed.