now the non-const String::operator[] returns a Char class instead of a
primitive
This commit is contained in:
parent
44ef56941e
commit
4a1709d626
@ -10,5 +10,5 @@ find_package(GTest REQUIRED)
|
||||
include_directories(${GTEST_INCLUDE_DIRS})
|
||||
link_libraries(${GTEST_BOTH_LIBRARIES})
|
||||
|
||||
set(SOURCE_FILES String.cpp String.h StringValue.cpp StringValue.h test.cpp)
|
||||
set(SOURCE_FILES String.cpp String.h StringValue.cpp StringValue.h Char.cpp Char.h test.cpp)
|
||||
add_executable(cpp11NHF1_refcountedString ${SOURCE_FILES})
|
@ -1,4 +1,5 @@
|
||||
#include "String.h"
|
||||
#include "Char.h"
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
@ -114,9 +115,9 @@ const char& String::operator[](size_t index) const
|
||||
}
|
||||
|
||||
// reuse const operator[]
|
||||
char& String::operator[](size_t index)
|
||||
Char String::operator[](size_t index)
|
||||
{
|
||||
return const_cast<char&>(const_cast<const String*>(this)->operator[](index));
|
||||
return Char(_str->index_of(&const_cast<char&>(const_cast<const String*>(this)->operator[](index))), *this);
|
||||
}
|
||||
|
||||
size_t String::size() const
|
||||
|
5
String.h
5
String.h
@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include "StringValue.h"
|
||||
#include "Char.h"
|
||||
class Char;
|
||||
|
||||
|
||||
|
||||
@ -30,12 +32,13 @@ public:
|
||||
String& operator+=(char);
|
||||
bool operator==(const String&) const;
|
||||
const char& operator[](size_t) const;
|
||||
char& operator[](size_t);
|
||||
Char operator[](size_t);
|
||||
|
||||
size_t size() const; // does not include null-terminator
|
||||
const char* c_str() const;
|
||||
|
||||
friend std::istream& operator>>(std::istream&, String&);
|
||||
friend class Char;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream&, const String&);
|
Loading…
Reference in New Issue
Block a user