dynamic array problem

am new to C++ trying to create a dynamic instance of my class Genie & having issues, not sure what i'm doin wrong, help? Created in Codeblocks & these are the compiler errors I get.

Genie.h|12|error: ISO C++ forbids declaration of `Cinreader' with no type|
Genie.h|12|error: expected `;' before '*' token|
Genie.h|13|error: `new' cannot appear in a constant-expression|
Genie.h|13|error: ISO C++ forbids declaration of `reader' with no type|
Genie.h|13|error: ISO C++ forbids initialization of member `reader'|
Genie.h|13|error: making `reader' static|
Genie.h|13|error: ISO C++ forbids in-class initialization of non-const static member `reader'|
Genie.h|14|error: ISO C++ forbids declaration of `reader' with no type|
Genie.h|14|error: expected `;' before '->' token|
Genie.h|31|error: expected unqualified-id before "delete"|

1 #pragma once
2 #include "Cinreader.h"
3 #include <iostream>
4 #include <string>
5 using namespace std;
6
7 CinReader reader;
8
9 class Genie
10 {
11 public:
12 Cinreader* reader;
13 reader = new CinReader;
14 reader -> readString();
15
16 string name;
17
18 void sayHello ();
19
20 void giveFortune ();
21
22 //int doubleNumber (int aNumber);
23
24 double carTravel (double distance, double rate);
25
26 double Genie::tipMeal (double mealAmt, double Item_1 = .10,
27 double Item_2 = .15,double Item_3 =.20,double Item_4 = .25);
28
29 //int youAlive (int yearN, int days, int hrsD, int minD, int secD);
30
31 delete reader;
32
33 };
Not sure how the topic title and your question correlate, but in any case you misspelled CinReader in line 12.

Edit: looks like that's not all. You can't just dump code inside a class declaration. "reader = new CinReader;reader -> readString();" looks like it should go into the constructor and "delete reader;" should go into the destructor.
You also should not write Genie::tipMeal inside the class declaration.

Do NOT use using namespace in headers. It's fine if you want to use it in your own source files, but you should not force it on the users of your class.

And please use code tags next time.
Last edited on
Oi! That's a class you're doing likes 12-14 in! You can't do those!

-Albatross
Topic archived. No new replies allowed.