I made my own string class and for some reason, the intellisense is not picking up methods that I clearly defined and am trying to use. Not only is the intellisense not picking up these methods, but I get a build error when I try to compile.
The only method that the intellisense is picking up is Display(). Test() and GetString() are no where to be found in the String class and say There is no member Test() and no member GetString when I try to compile.
string.cpp
#include "String.h"
#include <iostream>
using std::cout;
using std::endl;
String::String() :m_SingleChar('\0'), m_CString(nullptr)
{ }
String::String(char Character) : m_SingleChar(Character)
{ }
String::String(char * CharacterString)
{
if (CharacterString != nullptr)
{
m_CString = new char [strlen(CharacterString) + 1];
strcpy (m_CString, CharacterString);
}
}
String::~String()
{
delete [] m_CString;
}
String::String(const String & copy) : m_SingleChar(copy.m_SingleChar)
{
if (copy.m_CString != nullptr)
{
m_CString = new char [strlen(copy.m_CString) + 1];
strcpy (m_CString, copy.m_CString);
}
}
String & String::operator = (const String & rhs)
{
if (this != &rhs)
{
delete [] m_CString;
if(rhs.m_CString == nullptr)
m_CString = nullptr;
else
{
m_CString = new char[strlen(rhs.m_CString) + 1];
strcpy (m_CString, rhs.m_CString);
}
m_SingleChar = rhs.m_SingleChar;
}
return *this;
}
char * String::GetString(String m_CString)
{
char * Cstring = m_CString.m_CString;
return Cstring;
}
void String::Test()
{
}
void String::Display()
{
cout << "Single character: " << m_SingleChar << endl;
cout << "C String: " << m_CString << endl;
}
string.h
#ifndef STRING_H
#define STRING_H
class String
{
public:
String();
String(char Character);
String(char * CharacterString);
~String();
String(const String & copy);
String & operator = (const String & rhs);
char * GetString (String CString);
void Test();
void Display();
private:
char m_SingleChar;
char * m_CString;
};
#endif
The exact error occurs at this line with the error message:
Error 1 error C2039: 'Test' : is not a member of 'String'
23 1 Potion Class 2
...
int * Potion::GetMoney (int * coins)
{
String something;
something.Test(); //Error occurs here
return coins;
}
Does anyone know why the class won't compile?
Does anyone know why the compiler is saying void Test() and char * GetString is not recognizing them as members of my string class??
<cstring>, but then it compiles cleanly. And that's definitely not an SSCCE. coliru.stacked-crooked.com/a/e6ba596a1cf473aa