これら 2 つの文字列でエラーが発生する理由を理解していただけますか: 1) C2143: 構文エラー: ';' がありません '*' の前 2) エラー C4430: 型指定子がありません - int と見なされます。注: C++ は default-int をサポートしていません。
MyString* m_pStr; // Link to a dynamically created string.
MyString* pPrev; // Pointer to the next counter.
MyString.h
#pragma once
#include <iostream>
#include "counter.h"
using namespace std;
class MyString
{
char* m_pStr; //String which is a member of the class.
void CreateArray(const char * pStr);
Counter* m_pMyCounter; // Pointer to its own counter.
public:
MyString(const char* pStr = "");
MyString(const MyString & other);
MyString(MyString && other);
~MyString();
const char * GetString();
void SetNewString(char * str);
void printAllStrings();
void ChangeCase();
void printAlphabetically();
};
MyString.cpp
#include "myString.h"
#include <iostream>
using namespace std;
MyString::MyString(const char* pStr){
this->CreateArray(pStr);
strcpy(m_pStr, pStr);
};
void MyString:: CreateArray(const char * pStr){
int size_of_string = strlen(pStr)+1;
m_pStr = new char[size_of_string];
}
MyString::MyString(const MyString & other){
this->CreateArray(other.m_pStr);
strcpy(m_pStr, other.m_pStr);
}
MyString::MyString(MyString && other){
this->m_pStr = other.m_pStr;
other.m_pStr = nullptr;
}
MyString::~MyString(){
delete[] m_pStr;
}
const char * MyString:: GetString(){
return m_pStr;
}
void MyString:: SetNewString(char * str){
this->CreateArray(str);
strcpy(m_pStr, str);
}
counter.h
#pragma once
#include "myString.h"
#include <iostream>
using namespace std;
class Counter{
private:
MyString* m_pStr; // Link to a dynamically created string.
int m_nOwners; // Counter of users of this string.
MyString* pPrev; // Pointer to the next counter.
public:
Counter();
//Copy constructor.
~Counter();
void AddUser();
void RemoveUser();
};