JMV12
JMV12

Reputation: 1045

C++ UNIX Error: Undefined first referenced symbol in file

I am writing a code for the first time in a while and I have run into the error stated in the tile when I try and compile the code I have right now. The whole error states "Undefined first referenced symbol in file _ZN6My_vecD1Ev /var/tmp/ccwgvyoJ.o ld: fatal: symbol referencing errors. No output written to a.out". I'm not sure what this means or how to fix it in order to make a vector of class My_vec and finish the code.

main.cpp

#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include "My_vec.h"

int main()
{
    try
    {
    // define an object v of My_vec type
    vector<My_vec> v;
    // insert 'B' at the rank 0 into the vector v
    // use the overloaded operator << to display vector elements
    // display the vector v size
}

    catch(exception &error)
    {
         cerr << "Error: " << error.what() << endl;
    }
}

#include <iostream>
#include <stdexcept>
#include "My_vec.h"

My_vec.cpp

void My_vec::set_values(int s, int c, char p)
{
    size = s;
    capacity = c;
    *ptr = 'p';
}

My_vec.h

#ifndef _MY_VEC
#define _MY_VEC

#include <ostream>

using namespace std;

class My_vec 
{   
//member variables
int size, capacity;
char *ptr;

public: 
    //member functions
    My_vec();
    ~My_vec();
    My_vec(const My_vec& vec);
    My_vec& operator=(const My_vec& vec);
    int get_size() const;
    int get_capacity() const;
    char& operator[](int i) const;
    char& operator[](int i);
    bool is_empty() const;
    char& elem_at_rank(int r) const;
    void insert_at_rank(int r, const char& elem);
    void replace_at_rank(int r, const char& elem);
    void remove_at_rank(int r);
    void set_values(int, int, char);    //I Put In
};

ostream& operator<<(ostream& out, const My_vec& vec);
int find_max_index(const My_vec& v,int size);
void sort_max(My_vec& vec);

#endif

Upvotes: 0

Views: 805

Answers (1)

Slava
Slava

Reputation: 44278

To see what is missing you need to demangle the symbol:

echo "_ZN6My_vecD1Ev" | c++filt

it shows this symbol My_vec::~My_vec(). So obviously you did not implement My_vec's destructor.

Upvotes: 2

Related Questions