Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3975902
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:44:27+00:00 2026-05-20T04:44:27+00:00

The set functions’ idea: First argument is a reference, allocates space to hold copy

  • 0

The set functions’ idea:

First argument is a reference, allocates space to hold copy of testing, sets str member of beany to point to the new block, copies testing to new block, and sets ct member of beany.

Problem:

1) Line that contains:

for (int i = 0; i < temp.length(); i++)

Error:expression must have a class
type

2) Line that contains:

temp[i] = cstr[i];

Error: expression must have
pointer-to-object type

3) overload of function show() for stringy type can’t find matching function signature due to presence of const

Very new to these concepts, could someone explain the reason for the errors?

#include "stdafx.h"
#include <iostream>
using namespace std;
#include <cstring>
#include <cctype>
struct stringy {
    char * str; //points to a string
    int ct; //length of string(not counting '\0')
};

void set(stringy & obj,  char cstr);
void show(const stringy & obj, int times=1);
void show(const char * cstr, int times = 1);

int _tmain(int argc, _TCHAR* argv[])
{
    string beany;
    char testing[] = "Reality isn't what it used to be.";

    set(beany, testing);
    show(beany);
    show(beany, 2);
    testing[0] = 'D';
    testing[1] = 'u';
    show(testing);
    show(testing, 3);
    show("Done");
    return 0;
}

void set(stringy & obj, char cstr)
{
    char * temp = new char[cstr];
    obj.str = temp;
    for (int i = 0; i < temp.length(); i++)
    temp[i] = cstr[i];
}

void show(const stringy & obj, int times)
{
    for (int i = 0; i < times; i++)
        cout << obj.str;
}

void show(const char * cstr, int times)
{
    for (int i = 0; i < times; i++)
        cout << cstr;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:44:28+00:00Added an answer on May 20, 2026 at 4:44 am

    temp is a const char*. That type does not provide any kind of length facilities- it is not an object and does not have a length() member method. Use a std::string– that is what it is for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of functions that I declare in a header like this:
Is there a set of functions that give you the file and/or the folder
I'm writing a set of functions in c++ which can be called by excel.
Is there a class or set of functions built into the .NET Framework (3.5+)
I am trying to define a set of functions where I can pass in
I have a problem with a javascript set of functions that I made. This
what I am trying to do is to set up functions that can perform
I have a set of five functions, that could be called one of five
I am dealing with a set of native functions that return data through dynamically-allocated
Let's say I define a set of get and set functions for a given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.