object not created.

Hi everyone,

I have a bit of a problem with the following code. It won't compile, giving a couple of errors (semi-colons missing that I can't track down, class not found etc)
The main problem I think is that for some reason, there is not object created.
The sad thing is, it's not even that big of a code. Must be going blind.

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
//main.cpp
#include <iostream>
#include <string>

//header files
#include "lotto.h"

//declare functions:
void menuLottoPrint();

int main ()
{
	menuLottoPrint(); 
	
};

void menuLottoPrint()
{
	lotto oLotto;
	int menuLottoChoice = 0; 
	std::cout <<	"This is a Quick Pick generator for a Lotto \n"
					"What sort of lotto would you like to play ? \n"
					"1. Lotto \t 2.SuperLotto \t 3.Euromillions \n"; 
	std::cin >> menuLottoChoice; 
	oLotto.menuLottoOption(menuLottoChoice);
};


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
//lotto.cpp
#include "lotto.h"
#include <iostream> 

void lotto::menuLottoOption(int option)
{
	while (mType != 1 && mType != 2 && mType != 3)
		{
			std::cout << "Please enter either 1, 2, 3 as selection \n"; 
			std::cin >> kind; 
		}
	switch (mType)
	{
	case 1:
		std::cout << "\t Lotto \n";
		break;
	case 2:
		std::cout << "\t SuperLotto \n";
		break; 
	case 3:
		std::cout << "\t MultiMillions \n"; 
		break;
	}


};

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//lotto.h
#ifdef LOTTO_H
#define LOTTO_H

class lotto
{
	//methods
public:
	void generateLotto(); 
	void menuLottoOption(int option);
	//data members
private:
	int mType; //1 for Lotto, 2 for SuperLotto, 3 for Euromillions
};

#endif 
Last edited on
You have posted lotto.cpp twice.
lets see your .h file. The real one.

should look something like:
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef L_H
#define L_H
class lotto
{
 public:
 lotto(); //you technically don't need this but I don't see where mType is being initialized.
 void menuLottoOption(int option);

 private:
 int mType;
};
#endif 
Last edited on
Sorry, I must have copied them over wrong. Will fix them in the original post with an edit.

Edit: fixed original post
Last edited on
I think you have too many semi-colons, try removing the ones after main, menuLottoPrint and menuLottoOption.
I did not have them before, but when I got the compile error I kind of went bananas with them. That's the only reason they are there really.
Compiles for me without those semi-colons, though I did put all the code into one file. What is the exact error you receive.

EDIT: Change menuLottoPrint to
1
2
3
4
5
6
7
8
9
10
void menuLottoPrint()
{
	lotto oLotto;
	int menuLottoChoice = 0; 
	std::cout <<	"This is a Quick Pick generator for a Lotto \n"
					<<"What sort of lotto would you like to play ? \n"
					<<"1. Lotto \t 2.SuperLotto \t 3.Euromillions "<<std::endl; 
	std::cin >> menuLottoChoice; 
	oLotto.menuLottoOption(menuLottoChoice);
}
Last edited on
#ifdef LOTTO_H should be #ifndef LOTTO_H .
Numerous:
The most notable are:

Main.cpp:
C2065: 'oLoto' undeclared identifier. (line 24)
C2146: syntax error: missing ';' before identifier 'oLotto' (line 18)
C2653: 'lotto' : is not a class or namespace. (line 4)

The other are related to the data members and methods not found.

Basically, it just won't let me create the object, even though they are included


See my edit and Peter87's post.
Thanks guys, it's working now!

Sure will look out for that #ifndef next time, so easy to overlook.
Topic archived. No new replies allowed.