How to create a test function in c++ and compile it?

Hi Team

I am new in C++, my code has a class and constructor, i only implemented one method void assign. But i am struggling to create a test function to test all of my logic and really need some help so can compile it. the comments are the implementation that needs to be put on that method.

// current code
#include <iostream>
#include <map>

class interval_map {
    friend void IntervalMapTest();
    V m_valBegin;
    typedef std::map<K,V> m_map;
    // constructor associates whole range of K with val
    interval_map(V const& val)
    : m_valBegin(val)

    // Assign value val to interval [keyBegin, keyEnd).
    // Overwrite previous values in this interval.
    // Conforming to the C++ Standard Library conventions, the interval
    // includes keyBegin, but excludes keyEnd.
    // If !( keyBegin < keyEnd ), this designates an empty interval,
    // and assign must do nothing.
    void assign( K const& keyBegin, K const& keyEnd, V const& val )
        for( auto it = m_map.find( keyBegin ); * it != keyEnd; ++it )
            * it = val;
    // look-up of the value associated with key
    V const& operator[]( K const& key ) const {
        auto it=m_map.upper_bound(key);
        if(it==m_map.begin()) {
            return m_valBegin;
        } else {
            return (--it)->second;

Welcome to the Forums!

It looks like you might be trying to code in the wrong file. Usually you tend to code in the main.cpp file in the Vex v5 Pro application. You can find instructions on how to code like this on these links


or you can look at this thread here asking about help coding in C++

1 Like