Home > Back-end >  C undefined reference to ` vtable for XXX ` error
C undefined reference to ` vtable for XXX ` error

Time:04-22

Wrote a parsed GPS message class, but when the test has been an error
C: \ Users \ LeoYAO \ AppData \ Local \ Temp \ cc1ecCYe o: function In ` main ':
F:/Coding/Cpp/Project/receiver/test_main Cpp: 8: undefined reference to ` StrSentence: : StrSentence (STD: : __cxx11: : basic_string & lt; Char, STD: : char_traits & lt; Char> , STD: : allocator Const&) '
C: \ Users \ LeoYAO \ AppData \ Local \ Temp \ cc1ecCYe o: test_main. CPP. : (rdata $. Refptr. _ZTV11StrSentence [. Refptr. _ZTV11StrSentence] + 0 x0) : undefined reference to ` vtable for StrSentence '
Collect2. Exe: error: ld returned 1 exit status
The source code
 # # ifndef MSGSENTENCEBASE_H 
# define MSGSENTENCEBASE_H
#include

Class MsgSentenceBase//abstract base class
{
Public:
Virtual ~ MsgSentenceBase () {};
Virtual STD: : string content (const)=0;
Virtual int length (const)=0;
Virtual bool SumChk (const)=0;
};

# endif

 # # ifndef STRSENTENCE_H 
# define STRSENTENCE_H
# include "MsgSentenceBase. H"
#include
#include
#include
#include
#include

The class StrSentence: public MsgSentenceBase
{
Public:
StrSentence (const STD: : string&);

STD: : string content () const override {return sentence; }
Int length () const override {return. What size (); }
Bool SumChk () const override;
Private:
STD: : string sentence;
STD: : from & lt; std::vector Part_vec;
};

# endif

 # include "StrSentence. H" 
Using STD: : vector;
Using STD: : string;
Using STD: : from;
Using STD: : make_shared;
Using STD: : stoi;
Using STD: : bitset;
Using STD: : regex;
Using STD: : sregex_token_iterator;

StrSentence: : StrSentence (const string& S)
: sentence (s), part_vec (new vector)
{
The regex reg (" [$, *] ");
Sregex_token_iterator beg (sentence. The begin (), sentence. The end (), reg, 1);//1, the regular type that matches the item as a delimiter
Auto end=STD: : sregex_token_iterator ();//the default constructor end - of - the sequence iterator
Beg++;
//omitted emptyfor (; Beg!=end; + + beg)
{
Part_vec - & gt; Push_back (beg - & gt; STR ());
}
}

Bool StrSentence: : SumChk (const)
{
Auto check_sum=stoul (part_vec - & gt; The back (), nullptr, 16);
Auto str_to_chk=sentence. Substr (1, what size () - (4);

Auto beg_str=str_to_chk. Cbegin ();
Auto end_str=str_to_chk. Cend ();
Bitset<8 & gt; The sum (0 x00);
for (; Beg_str!=end_str; Beg_str + +)
{
The sum ^=bitset<8 & gt; (* beg_str);
}
Return the sum. To_ulong ()==check_sum;
}

 # include "StrSentence. H" 

using namespace std;
Int main ()
{
Hold the string STC="$XXXXXXXXXX";
Hold StrSentence s (STC);
system("pause");
}

CodePudding user response:

I was using a dev
c + +Add compiler options: - STD=gnu++ 11

 # include & lt; Iostream> 

/* run this program using the console pauser or add your own getch, system (" pause ") or the input loop */
#include
#include
#include
#include
#include
#include
using namespace std;

Class MsgSentenceBase//abstract base class
{
Public:
Virtual ~ MsgSentenceBase () {};
Virtual STD: : string content (const)=0;
Virtual int length (const)=0;
Virtual bool SumChk (const)=0;
};


The class StrSentence: public MsgSentenceBase
{
Public:
StrSentence (const STD: : string&);

STD: : string content () const override {return sentence; }
Int length () const override {return. What size (); }
Bool SumChk () const override;
Private:
STD: : string sentence;
STD: : from & lt; std::vector Part_vec;
};


StrSentence: : StrSentence (const string& S)
: sentence (s), part_vec (new vector)
{
The regex reg (" [$, *] ");
Sregex_token_iterator beg (sentence. The begin (), sentence. The end (), reg, 1);//1, the regular type that matches the item as a delimiter
Auto end=STD: : sregex_token_iterator ();//the default constructor end - of - the sequence iterator
Beg++;
//omitted emptyfor (; Beg!=end; + + beg)
{
Part_vec - & gt; Push_back (beg - & gt; STR ());
}
}

Bool StrSentence: : SumChk (const)
{
Auto check_sum=stoul (part_vec - & gt; The back (), nullptr, 16);
Auto str_to_chk=sentence. Substr (1, what size () - (4);

Auto beg_str=str_to_chk. Cbegin ();
Auto end_str=str_to_chk. Cend ();
Bitset<8 & gt; The sum (0 x00);
for (; Beg_str!=end_str; Beg_str + +)
{
The sum ^=bitset<8 & gt; (* beg_str);
}
Return the sum. To_ulong ()==check_sum;
}
Int main (int arg c, char * * argv) {
Hold the string STC="$XXXXXXXXXX";
Hold StrSentence s (STC);
system("pause");
return 0;
}
nullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related