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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:39:53+00:00 2026-06-14T16:39:53+00:00

Having problems with array of pointers. I have a custom class called C .

  • 0

Having problems with array of pointers.
I have a custom class called C. C has a variable double c1. I have to sort an array of C-s by c1 using a custom written sorting algorithm. I am guessing that since I have to move objects in array, it would be much more eficient to just move pointers to objects, therefore I have to use not an array of objects, but an array of pointers to objects.

I initialized the array like that:

C** someC;
someC = new C*[size];
for(int i = 0; i < size; i++) {
    // a and b are of type CPoint
    someC[i] = new C(a,b);
}

Am I doing this part correctly? It is the calling of C objects that then causes problems:

someC[i]->a.x

gives me an error: left of ‘->a’ must point to class/struct/union/generic type

I am new to C++ so I may be missing something obvious, but I did some research and did not find anything. Maybe I am not understanding well how pointers work…


UPDATE

The header file of C class:

#pragma once

class C
{
public:
    CPoint a;
    CPoint b;
    double c1;
    C(void);
    C(CPoint,CPoint);
    ~C(void);
};

the implementation:

#include "StdAfx.h"
#include "C.h"
#include <math.h>

C::C(void)
{
}

C::C(CPoint a, CPoint b)
{
    this->a=a;
    this->b=b;

    double c1_x = a.x - b.x;
    double c1_y = a.y - b.y;
    c1= sqrt( (c1_x * c1_x) + (c1_y * c1_y));
}

C::~C(void)
{
}

UPDATE

The problem was in the code I provided in the comments, I did not notice I was calling the array in a wrong way like this:

pDC->MoveTo(someC[i]->a.x, someC->a.y)

So the second call was incorrect. Thank you all for your help

  • 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-06-14T16:39:55+00:00Added an answer on June 14, 2026 at 4:39 pm

    Philosophy aside, this is pretty telling from your comment (emphasis added):

    “I am actually calling someC in OnDraw method like that: pDC->MoveTo(someC[i]->a.x, someC->a.y); someC is defined as public in the header file”

    Specifically, this in your parameter list :

    someC[i]->a.x, someC->a.y
    

    This tells me one of these is wrong. Judging by your error, I’m going to go with the first one. It would solidify that if we could see the definition of your object that is implementing OnDraw() and where exactly it is getting someC from.

    • If someC is a C* in your containing object, the second parameter is correct, the first is wrong.
    • If someC is a C** in your contained object then the first parameter is correct and the second is wrong.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problems building an hierarchistic array structure - I have almost got
I'm having a lot of problems initializing an array of bools. When using the
I am having problems with array pointers. I've looked through Google and my attempts
I am practicing using pointers. I have a pointer to an array of 3
I am having problems declaring a pointer into my 4d array. I have declared
I'm writing a C program but I keep having problems with my array of
im having problems on how to save the content of an array in an
I am having problems passing a javascript array to an MVC3 controller, not sure
Hi I am having a problems displaying my array via JSON object. I passed
I'm having problems to iterate twice on the same array: <? $indice=0 ?> <?php

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.