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

  • SEARCH
  • Home
  • 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 431701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:00:04+00:00 2026-05-12T20:00:04+00:00

Here is a simplified version of what I have (not working): prog.h: … const

  • 0

Here is a simplified version of what I have (not working):

prog.h:

...
const string c_strExample1 = "ex1";
const string c_strExample2 = "ex2";
const string c_astrExamples[] = {c_strExample1, c_strExample2};
...

prog.cpp:

...
int main()
{
    int nLength = c_astrExamples.length();
    for (int i = 0; i < nLength; i++)
        cout << c_astrExamples[i] << "\n";
    return 0;
}
...

When I try to build, I get the following error:
error C2228: left of ‘.length’ must have class/struct/union

The error occurs only when I try to use member functions of the c_astrExamples.
If I replace “c_astrExamples.length()” with the number 2, everything appears to work correctly.

I am able to use the member functions of c_strExample1 and c_strExample2, so I think the behavior arises out of some difference between my use of strings vs arrays of strings.

Is my initialization in prog.h wrong? Do I need something special in prog.cpp?

  • 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-12T20:00:04+00:00Added an answer on May 12, 2026 at 8:00 pm

    Arrays in C++ don’t have member functions. You should use a collection like vector<string> if you want an object, or compute the length like this:

    int nLength = sizeof(c_astrExamples)/sizeof(c_astrExamples[0]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a simplified version of a problem I'm working on: I have a bunch
Here is simplified version of my requirement I have a java class say Processor
Here's a simplified version of the 3 data sets I have: Set A =
I have an html table. Here is a simplified version: <table> <tr> <td><div style=display:
Here's a simplified version of my needs. I have a program where every B
Here is very simplified version of code that i have: class PrintJob : IEntity
THE SITUATION So here's a simplified version of my situation: I have a Payment
I have 2 layout xml files: highlights.xml and highlights_cell.xml. Here is a simplified version
Here is a simplified version of the code I use. I need to rewrite
Here is a simplified version of one of my models: class ImportRule(models.Model): feed =

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.