Mam problem z wskaźnikiem, chcę zrobić żeby wskaźnik "pointer" pokazywał na następny obiekt:
#include <iostream>
#include <conio.h>
using namespace std;
class B;
class A
{
public:
B *pointer;
};
class B
{
public:
int c;
B() { c = 0; }
};
int main()
{
A *wsk = new A;
wsk->pointer = new B[10];
for (int i = 0; i < 10; i++)
{
wsk->pointer->c = i; // działa ale pokazuje tylko na jeden obiekt
}
for (int i = 0; i < 10; i++)
{
cout << wsk->pointer->c << endl; // działa ale pokazuje tylko na jeden obiekt
}
_getch();
return 0;
}
Gdy zamienię wsk->pointer->c = i; na wsk->pointer[i]->c = i; to IDE podpowiada mi że wsk musi mieć typ wskaźnika, jak podpowiem mu robiąc to tak ((A)wsk)->pointer[i]->c = i;, IDE nadal nie zmienia zdania podpowiada i nadal nie wie że ((A)wsk) wskazuje na obiekt typu A.
Błąd kompilatora:
1>------ Build started: Project: classpointer and function, Configuration: Debug Win32 ------
1> Source.cpp
1>c:\users\administrator\documents\visual studio 2013\projects\classpointer and function\classpointer and function\source.cpp(27): error C2819: type 'B' does not have an overloaded member 'operator ->'
1> c:\users\administrator\documents\visual studio 2013\projects\classpointer and function\classpointer and function\source.cpp(15) : see declaration of 'B'
1> did you intend to use '.' instead?
1>c:\users\administrator\documents\visual studio 2013\projects\classpointer and function\classpointer and function\source.cpp(27): error C2232: '->B::c' : left operand has 'class' type, use '.'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Proszę o pomoc