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 6907575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:27:08+00:00 2026-05-27T08:27:08+00:00

So I have an assignment for school that requires me to create a fixed

  • 0

So I have an assignment for school that requires me to create a fixed length string class using templates for use as part of a larger project but I’m having trouble getting started with the fixed length string so I thought I’d come here for help. I don’t have much experience with templates which is what is causing me problems. My current problem is in the copy constructor which is giving me errors I don’t know how to deal with. So here is my class definitions:

template <int T>
    class FixedStr
    {
    public:
                            FixedStr        ();
                            FixedStr        (const FixedStr<T> &);
                            FixedStr        (const string &);
                            ~FixedStr       ();
        FixedStr<T> &       Copy            (const FixedStr<T> &);
        FixedStr<T> &       Copy            (const string &);

    private:
        string Data;
    };

And here is the copy constructor that is giving me problems:

template <int T>
    FixedStr<T>::FixedStr (const string & Str)
    {
        if (Str.length() == <T>)
            strcpy (FixedStr<T>.Data, Str);
    }

Can anyone give me some advice as to how to handle this? Is there are easy error you see or am I approaching the problem the wrong way? Thanks for any help you can give me.

  • 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-27T08:27:08+00:00Added an answer on May 27, 2026 at 8:27 am

    Untested: I think it should be

    if (Str.length() == T)
            Data = Str;
    

    First, you don’t use angle brackets when accessing template arguments. Second, you don’t use strcpy for C++ strings, they support copying via assignment.

    Note that there is no need for a custom destructor or copy constructor in your class.

    The letter T is commonly used for type parameters. I’d just use Length or N instead.

    Here is a modified version of your class:

    #include <string>
    
    template<int N> class FixedStr {
    public:
      FixedStr(const std::string&);
    
    private:
      std::string Data;
    };
    
    template<int N> FixedStr<N>::FixedStr(const std::string& Str) {
      if (Str.length() == N) Data = Str;
    }
    
    int main() {
      FixedStr<11> test("Hello World");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment in a language-independent class, and part of it is using
For an assignment at school, we have to use structs to make matrices that
I currently have a school assignment that involves both PHP and asp.net. Now the
For a database assignment I have to model a system for a school. Part
I have an assignment to create a GUI using MATLAB GUIDE and am having
I am working on a school assignment that requires operator overloading. I am having
i have an erd for a school assignment that contains a many to many
I've been working on a school assignment that makes pretty heavy use of vectors,
I have an assignment for school that is really got the best of me.
I have this school assignment that I've been working on and am totally stumped

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.