0

I showed my some code to you(c++), and I have to use my_len function for length.

How can I do it for my_len(?????) . What should I write as a function parameter? Should I create Constructor?

Thanks a lot.

Header:

class String
{
public:
..........
    .........
    int length();


private:
.........


};

My Codes:

int my_len(const char* p) {
    int c = 0;
    while (*p != '\0')
    {
        c++;
        p++;
    }
    return c;
}


int String::length() 
{
    my_len(?????);
}
Nedim Bak
  • 31
  • 6
  • You might want to take a look at [this](http://www.learncpp.com/cpp-tutorial/9-14-overloading-the-assignment-operator/) – George Jan 05 '17 at 13:32
  • Your `String` class should implement something like `c_str()`. – Hatted Rooster Jan 05 '17 at 13:34
  • [This should help](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – eerorika Jan 05 '17 at 13:34
  • @George Thank you i am checking now, but i am not sure which one is best solution for me. – Nedim Bak Jan 05 '17 at 13:35
  • @GillBates How can i do? Thank you – Nedim Bak Jan 05 '17 at 13:36
  • @user2079303 I am checking thank you.but i am not sure which one is best solution for me – Nedim Bak Jan 05 '17 at 13:36
  • You might want to put "c++ custom string class example" into a search engine. Some of the first hits I got were http://www.cplusplus.com/forum/beginner/15396/ and http://stackoverflow.com/questions/2843421/custom-string-class-c and https://www.cs.colorado.edu/~main/projects/chap04e.html which all look like something you might want to read anyway. In any case, writing ones own string class is a very good way to learn C++. When you are done, you might want to ask a question like "This is my string class: ... , it works, but are there ways to improve it in things like readability?" – Aziuth Jan 05 '17 at 15:06
  • 1
    `0xdeadbeef`, `100110` and `•••--•••` are _codes_. What you have in your question is called _code_. – ForceBru Jan 05 '17 at 15:36
  • 3
    An essential part of your class declaration is missing: how do you store the string itself? The question cannot be answered without this piece of information. – Roland W Jan 05 '17 at 16:46

0 Answers0