Pointer w Array

How do you call a pointer in a class

TO the main ?

Last edited on
anyone
If you write a proper complete question - with an example maybe? Then you might get some answers.

9 / 12 words is too brief.
test
Last edited on
test
Last edited on
sd is the list of shapes, ShapeTwoDD is an individual shape. Do you want to access the x values of the shapes in sd?

To do this you need to dereference the iterator and call the GetX function. Or use the -> operator with the iterator directly.

http://www.cplusplus.com/reference/stl/list/


Now for the organisation of your code.

The normal situation is to have the class declaration in a header file, all the class function definitions in a .cpp file, then a file containing main(). This better than having 100's of lines of code in one file

If you are using an IDE, you can use the class wizard to create the files, it creates skeleton of the code also.

The IDE should be able to create function stubs in the .cpp file when you declare in the header file.

Hop all goes well.
I'm not going to read 340 lines of code, but to answer your original question:
1
2
3
4
5
6
int* SomeFunc() // Just use the int* type as your return type.
{
    int* MyPointer = new int[ArraySize];
    // Do something with MyPointer;
    return MyPointer; // Just remember to delete the array somewhere else.
}


Wait... reading through some of the 340 lines of code I see that x is not a pointer or array. You've defined it as a plain old int on line 19. You need to define it as int* if you want it to be an array. A change like that will require some work for you to change all of the instances of x, to an array.

In the constructor, allocate the arraysize for x with the new[] keyword.

Your getX function would then look like:
1
2
3
4
5
void getX(int i)
{
    cout <<"X[i] is "<<x[i];

}
Last edited on
Topic archived. No new replies allowed.