1

私は次のコードを持っています:

class asd {  
    public:  
    int b;  
    asd() { b = rand() % 10; }  
    bool operator<(asd &other) { return b < other.b; }  
};

int main() {  
    asd * c; c = new asd();  
    set <asd> uaua;  
    uaua.insert(c);  
}

しかし、それを実行すると、次のエラーが発生します。

main.cpp|36|error: no matching function for call to ‘std::set<asd, std::less<asd>, std::allocator<asd> >::insert(asd*&)’|

g++4.4.3を使用しています

誰かが私がどこで間違っているのか教えてもらえますか?私はしばらくの間これをクラックしようとしましたが、解決策を見つけることができないようです。ありがとう

4

2 に答える 2

4

のセットがありasd、ポインタを追加しようとしています。

使用する:

asd c; 
set <asd> uaua;
uaua.insert(c);
于 2010-06-26T22:45:20.160 に答える
0

set<asd*>だけでなく、宣言してみてくださいset<asd>

于 2010-06-26T22:46:28.150 に答える