Question: I keep getting an error with implementation file in c++ Error- sh -c make -s /nix/store/039g378vc3pc3dvi9dzdlrd0i4q93qwf-binutils-2.39/bin/ld: /nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib/crt1.o: in function `_start': (.text+0x1b): undefined reference to `main'
I keep getting an error with implementation file in c++
Error- sh -c make -s /nix/store/039g378vc3pc3dvi9dzdlrd0i4q93qwf-binutils-2.39/bin/ld: /nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib/crt1.o: in function `_start': (.text+0x1b): undefined reference to `main' clang-12: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [Makefile:10: main] Error 1 exit status 2
Maybe i missed of forgot something
The header file is:
#ifndef MAIN_SAVITCH_SEQUENCE_H #define MAIN_SAVITCH_SEQUENCE_H
#include
namespace main_savitch_3 { class sequence { public: // TYPEDEFS and MEMBER CONSTANTS typedef double value_type; typedef size_t size_type; static const size_type CAPACITY = 30;
// CONSTRUCTOR sequence();
// MODIFICATION MEMBER FUNCTIONS void start(); void advance(); void insert(const value_type& entry); void attach(const value_type& entry); void remove_current();
// CONSTANT MEMBER FUNCTIONS size_type size() const; bool is_item() const; value_type current() const;
private: value_type data[CAPACITY]; size_type used; size_type current_index; }; }
#endif The implementation file is:
#include "sequence1.h" #include "iostream" namespace main_savitch_3 {
// CONSTRUCTOR sequence::sequence() { used = 0; current_index = CAPACITY; // Indicates there is no current item }
// MODIFICATION MEMBER FUNCTIONS void sequence::start() { if (used > 0) { current_index = 0; } }
void sequence::advance() { if (is_item()) { ++current_index; } }
void sequence::insert(const value_type& entry) { if (size() < CAPACITY) { if (!is_item()) // No current item, so insert at start { current_index = 0; } for (size_type i = used; i > current_index; --i) { data[i] = data[i-1]; } data[current_index] = entry; ++used; } }
void sequence::attach(const value_type& entry) { if (size() < CAPACITY) { if (!is_item()) // No current item, so attach at end { current_index = used - 1; } else // Attach after current item { ++current_index; for (size_type i = used; i > current_index; --i) { data[i] = data[i-1]; } } data[current_index] = entry; ++used; } }
void sequence::remove_current() { if (is_item()) { for (size_type i = current_index + 1; i < used; ++i) { data[i-1] = data[i]; } --used; if (current_index == used) { current_index = CAPACITY; // Indicates there is no current item } } }
// CONSTANT MEMBER FUNCTIONS sequence::size_type sequence::size() const { return used; }
bool sequence::is_item() const { return current_index < used; }
sequence::value_type sequence::current() const { if (is_item()) { return data[current_index]; } else { return 0; // This could be changed to throw an exception instead } }
} // end namespace main_savi
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
