This is my first post here on Daniweb and I intend to do things right. I actually did read the "READ THIS FIRST" thread and instead of posting 500 lines of code I whipped up a test program I aptly titled test.cpp

First I will walk you through my problem. The overall purpose is irrelevant but I am trying to create an array of pointers that point to different instances of objects that I created from my own class. For the purpose of the test I called my class test. I then want to set multiple values to my objects and then have them return these values to the screen. I have done this in three files: test.cpp, a.cpp, a.h

test.cpp

#include <iostream>
#include "a.h"
using namespace std; 

int main() 
{
	Test *test[1];
	int value = 2;
	
	test[0] = new Test(); 
	
	test.setValue(value);
	
	cout << test.getValue(); //Should output 2 to my understanding. 
}

a.cpp

#include "a.h"
using namespace std; 

Test::Test()
{
}

void Test::setValue(int inValue)
{
	value = inValue;
}

int Test::getValue()
{
	return value; 
}

a.h

class Test
{
	
public:
	
	Test();
	
	void setValue(int inValue);
	
	int getValue();
	
private:
	
	int value; 
	
	
};

When compiling these I get the error:

/Programming Projects/CSCI211/Project 2/Calendar/test/main.cpp:12:0 /Programming Projects/CSCI211/Project 2/Calendar/test/main.cpp:12: error: request for member 'setValue' in 'test', which is of non-class type 'Test* [1]'

Honestly I am not in that big of a rush right now. I have been programming most of the last two days and I am ready for a break. It is probably the fact that I have been working on this for a while that I can't see the problem.

Anyway, any and all help, suggestions and criticism would be welcome with open arms ;)

Cheers,
Takeshi91k

Duki commented: Excellent first post. +7

>>test.setValue(value);

test[0].setValue(value);

I'll let someone else criticize your code. Feel too lazy right now.

Member Avatar for embooglement

firstPerson, that's still not right, because test is an array of pointers. It'd be

test[0]->setValue(value)

To the op: test is an array, which means you have to refer to a specific element. The other catch is that it's an array of pointers, which means you must also dereference it.

commented: Very helpful and friendly. Thanks a bunch. +0

Thanks embooglement. I fixed it shortly after your post. Appreciate it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.