Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7519571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:55:35+00:00 2026-05-30T01:55:35+00:00

So, I’ve got this code: #include <string> #include <set> class Section; class Config; class

  • 0

So, I’ve got this code:

#include <string>
#include <set>

class Section;
class Config;

class SettingBase {
public:
    virtual ~SettingBase() { }
};

template<typename T>
class Setting : private SettingBase {
    friend class Section;
public:
    std::string const &get_name() { return name; }
    T const &get_value() { return value; }

private:
    Setting(std::string name, T value) : name(name), value(value) { }

    std::string name;
    T value;
}; // Class Setting

class Section {
    friend class Config;
public:
    std::string const &get_name() { return name; }

    template<typename T>
    void add(std::string const &name, T const &value) {
        settings.insert(new Setting<T>(name, value));

        return;
    }

    template<typename T>
    bool remove(std::string const &name) {
        std::set<SettingBase*>::iterator it;

        for (it = settings.begin(); it != settings.end(); it++) {
            if ((static_cast< Setting<T> *>(*it))->name.compare(name) == 0) {
                settings.erase(*it);
                return true;
            }
        }

        return false;
    }

    template<typename T>
    T const &get(std::string const &name) {
        std::set<SettingBase*>::iterator it;

        for (it = settings.begin(); it != settings.end(); it++) {
            if ((static_cast< Setting<T> *>(*it))->name.compare(name) == 0) return (static_cast< Setting<T> * >(*it))->value; // fuuuuuck.
        }

        // TODO: exception
        throw;
    }

private:
    Section(std::string name) : name(name) { }

    std::string name;
    std::set<SettingBase*> settings;
}; // Class Section

class Config {
public:
    Config(std::string filename) : filename(filename) { };

    void add(std::string const &name) {
        sections.insert(Section(name)); // here's the error.

        return;
    }

    bool remove(std::string const &name) {
        std::set<Section>::iterator it;

        // TODO: exceptions
        for (it = sections.begin(); it != sections.end(); it++) {
            if ((*it).name.compare(name) == 0) {
                sections.erase(*it);
                return true;
            }
        }

        return false;
    }


    Section const &get(std::string const &name) {
        std::set<Section>::iterator it;

        for (it = sections.begin(); it != sections.end(); it++) {
            if ((*it).name.compare(name) == 0) return *it;
        }

        // TODO: exception
        throw;
   }

private:
    std::string filename;
    std::set<Section> sections;
}; // Class Config


int main(int argc, char *argv[]) {
    Config tmp(std::string("this should be a file.txt"));
    tmp.add(std::string("this is a section's name"));
    Section sec = tmp.get(std::string("this is a section's name"));
    sec.add<int>(std::string("test"), 46541);

    return sec.get<int>(std::string("test"));

}

which can’t be compiled because:

julian@vanaheimr ~/Workspace/PlusConfig/src $ gcc plusconfig.cpp 
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.5.3/include/g++-v4/string:50:0,
                 from plusconfig.cpp:4:
/usr/lib/gcc/i686-pc-linux-gnu/4.5.3/include/g++-v4/bits/stl_function.h: In member function ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Section]’:
/usr/lib/gcc/i686-pc-linux-gnu/4.5.3/include/g++-v4/bits/stl_tree.h:1184:4:   instantiated from ‘std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(const _Val&) [with _Key = Section, _Val = Section, _KeyOfValue = std::_Identity<Section>, _Compare = std::less<Section>, _Alloc = std::allocator<Section>]’
/usr/lib/gcc/i686-pc-linux-gnu/4.5.3/include/g++-v4/bits/stl_set.h:408:29:   instantiated from ‘std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = Section, _Compare = std::less<Section>, _Alloc = std::allocator<Section>, typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator = std::_Rb_tree_const_iterator<Section>, value_type = Section]’
plusconfig.cpp:78:38:   instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.5.3/include/g++-v4/bits/stl_function.h:230:22: error: no match for ‘operator<’ in ‘__x < __y’

but I’m not overloading operator <, and I can’t figure out what this means….

Thanks,

Julian.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:55:36+00:00Added an answer on May 30, 2026 at 1:55 am

    Well, you need a way of comparing stuff that you put in a std::set. If you don’t give one explicitly, the template expects that ‘<‘ over instances of your objects be available somehow; like by overloading said operator. I think that’s the problem in your code. I noticed that in some cases you do sets of pointers, and in others of objects. For pointers ‘<‘ is defined, for objects you need to take care of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
i got an object with contents of html markup in it, for example: string
Does anyone know how can I replace this 2 symbol below from the string
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.