0

I receive an error that I cannot set delimiter without object. I am not sure where I went wrong.

main.cpp

using namespace sd;

int main() {
    Utilities::setDelimiter(',');
    return 0;
}

Utilities.h

namespace sd {
    class Utilities {

        static char m_delimiter;

        public:

        void setDelimiter(const char c) { m_delimiter = c;    }
        const char getDelimiter() const { return m_delimiter; }
    }
}

Utilities.cpp

namespace sd {

    char Utilities::m_delimiter = ',';

}
1

1 Answer 1

1

You must call a normal member function on a object instance:

Utilities util;
util.setDelimiter(',');

In your case, maybe changing it to a static method?

static void setDelimiter(....)
Sign up to request clarification or add additional context in comments.

1 Comment

static void setDelimiter() removed my compile error... this is needed as one file use ',' and the other '|' as delimiter... both are stored inside an array of one object type vector<Item> inventory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.