Hello everyone,
I'm attempting to write a program for an assignment dealing with a class in C++. As you may have guessed, classes are new to me. And it seems as though that is what is giving me these errors:

1>c:...main.cpp(90) : error C2228: left of '.number' must have class/struct/union
1>c:...main.cpp(91) : error C2228: left of '.sieve' must have class/struct/union
1>c:...\main.cpp(92) : error C2228: left of '.print_primes' must have class/struct/union

I have searched for an answer, but it seems as though this error pops up if there is anything at all wrong with the class. I cannot figure out what is wrong with mine. Thanks for any help!!

Here is my code:

#include <iostream>
using namespace std;

class Prime_Finder {
public:
	Prime_Finder();
	~Prime_Finder();

	void number();
	void print_primes();
	//void get_number();
private:
	void sieve();
	int *IntArray;
	int Input_Number;
protected:
};

Prime_Finder::Prime_Finder()
{
	IntArray = new int[Input_Number];
}

Prime_Finder::~Prime_Finder()
	{
	}

void Prime_Finder::number()
{
	
	cout<<"Please input a value: ";
	cin>>Input_Number;
}

/*void get_number()
	{
	return(Input_Number);
	}
	*/
void Prime_Finder::sieve()
{
	for ( int index=2; index <= Input_Number; index++ )
		{
		if ( IntArray[index] == 1 )
			for ( int i = index+1; i <= Input_Number; i++ )
				if (  i % index == 0 )
					IntArray[i]=0;
	}
}

void Prime_Finder::print_primes()
{
int count=1;
	for( int index = 2; index <=Input_Number; index++)
		if ( IntArray[index] == 1 )
			{
			count++;
			if ( count % 10 == 0 )
				cout<<index<< endl;
			else
				cout<< index << " ";
			}	
		cout << endl;	
}



int main()
{

Prime_Finder findprimes();

findprimes.number();
findprimes.sieve();
findprimes.print_primes();

}

Recommended Answers

All 2 Replies

Prime_Finder findprimes();

You've independently discovered a rather subtle problem with C++'s grammar. This line is actually interpreted as a function declaration. The function is called findprimes, has no parameters, and returns and object of type Prime_Finder.

To define an object with the default constructor, omit the empty parens:

Prime_Finder findprimes;

Thank you, that solved 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.