pointers to custom class help

So I have a class and a question for manipulating this class with pointers..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Rain : public AnotherClass
{
};

// now i try to make a pointer to an array of that class.

typdef Rain* pRain;
pRain *p;

Rain drops[300];

p = drops;
(*p+j).SetPosition(Randomfloatx[j], Randomfloaty[j]);


Why cant I use pointer arithmetic on this special class?
Last edited on
It basically says in the compiler that my only options to add diffClass operator+(diffclass, diffclass)

Does this mean I have to redesign that operator for pointer arithmetic?


raintest.cpp:73: error: no match for ‘operator+’ in ‘* p + j’
/usr/local/include/SFML/Graphics/Color.hpp:131: note: candidates are: sf::Color sf::operator+(const sf::Color&, const sf::Color&)
Last edited on
bump :D
can't tell exactly what's going on because you have errors in your code

Line 8: should be
pRain p;

compiler error seems to indicate that Rain's superclass? Color already has an operator+() which is interfering with your pointer arithmetic

you should try:
(p+j)->SetPosition(Randomfloatx[j], Randomfloaty[j]);

...kind of taking wild guesses here, as your code doesn't seem to make sense (compile) in its present form

edit: Line 7 has a typo for typedef
Last edited on
Oh i see, that's what i forgot about the pointers to classes. They use the '->' to use members etc.

EDIT: Actually that doesn't work.

Here's my code... But it is exceptionally bad. I hven't really even checked the logic... It was all on the fly coding... so I was actually just trying to get it to work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <SFML/Graphics.hpp>
#define RAIN "(((( Just a bit file of a non-black dot))))"
#include <stdlib.h>
#include <time.h>
#include <string>


class Rain : public sf::Sprite
{
std::string PathName;

public:
	Rain (){}
	Rain (sf::Image);
	void set( sf::Image Pather){SetImage(Pather);}
};

Rain::Rain (sf::Image Path)
{
	set(Path);
}	
	



void start();

int main()
{
start();

return EXIT_SUCCESS;	
}

void start ()
{
	sf::RenderWindow RainApp(sf::VideoMode(800,600,32), "Test 1");
	
	int Randoms[10];
	float Randomfloatx[300];
	float Randomfloaty[300];	
	srand (time(NULL));
	typedef Rain* pDrop;
	Rain * p; 
	sf::Image Drops;
	if(!Drops.LoadFromFile(RAIN))
		return ;
	Rain drops[300];
	p = drops;
	int count = 1;
	int balance;
	int j;
	while(RainApp.IsOpened())
	{
		sf::Event ev1;
		while(RainApp.GetEvent(ev1))
			if(ev1.Type == sf::Event::Closed)
				RainApp.Close();

			if (count == 1)
				 j = 0;
			if (count >= 2)
				 j = 10;
			
			for ( j * count - 10; j < 10 * count; j++)
			{
				if (j < 0)
				j = 0;
				Randomfloatx[j] = rand() % 800;
				Randomfloaty[j] = rand() % 600;
				
				(*p+j)->SetPosition(Randomfloatx[j], Randomfloaty[j]);
				

			}
			RainApp.Clear();
	
		for ( int i = 0; i < 10 * count ; i++)
		{	(*p+j)->Move(0, .1f);
			RainApp.Draw((*p+j));
		}
		count++;
		RainApp.Display();		
			
	}

}

Last edited on
Nvm, the code compiles to object... it just sucks and doesn't work :(
Last edited on
Hey, can someone tell me why I wouldn't need the * in the (*p+j)->SetPosition(Randomfloatx[j], Randomfloaty[j]);

is it simply because it points to an array?
Topic archived. No new replies allowed.