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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:32:48+00:00 2026-05-29T19:32:48+00:00

I am writing a time varying profile class using templates and want to index

  • 0

I am writing a time varying profile class using templates and want to index the profile by either a numeric index or by a date and time as represented by a struct tm. The indexing by a numeric index works fine, but the indexing by a date doesn’t work with a pointer to the object. Here is some sample code containing approaches that work and approaches that don’t work.

#include "profile.h" // Class Profile<T> is declared and defined here.
float f;
int i;
struct tm d;
Profile<float> p;
Profile<float> *pPtr;

// Non-pointer syntax
f = p[i];                // this works.
f = p.operator[](i);     // this works, but its ugly.
f = p[d];                // this works.
f = p.operator[](d);     // this works, but its ugly.

// Pointer syntax
f = (*pPtr)[i];          // this works.
f = pPtr->operator[](i); // this works, but its ugly.
f = (*pPtr)[d];          // this isn't what I typed.  I did f = *(pPtr)[d];
f = pPtr->operator[](d); // this works, but its ugly.

This C++ code is being written in Visual Studio 2008. The compiler error message is error C2677 binary ‘[‘ : no global operator found which takes type ‘tm’ (or there is no acceptable conversion).

Given a pointer to a C++ object what are all the correct ways to call the operator[] function?

  • 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-29T19:32:51+00:00Added an answer on May 29, 2026 at 7:32 pm

    The code you’ve shown here is fine; probably in your previous attempts you were doing *(pPtr)[d] instead of (*pPtr)[d], which would understandably cause an error since operator* has lower precedence than operator[].

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

Sidebar

Related Questions

I'm writing a facebook desktop application for the first time using the PyFacebook api.
I am new to rails, and Im having hard time writing a query using
Disclaimer: This is my first time writing unit tests...be gentle! :) I am trying
Recently I spent quite some time writing various Visual Studio Extensions projects. Even though
I'll spend some time writing some (raw) SQL statements in Android (e.g. for creating
I am having a really hard time writing a SELECT query to get a
I feel like I spend a lot of time writing code in Python, but
I've recently started coding in C++, but I have long time writing in C.
I'm writing a benchmark for computing the time taken for serialization/de-serialization for OpenFast The
I find myself writing file and directory utility functions all the time, and I

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.