error: expected ‘}’ at end of input

Dec 23, 2011 at 9:37pm
I have a program here (from a textbook):

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
int main() {
        using std::cout;
        using std::endl;

        baseDMA shirt("Portabelly", 8);
        lacksDMA balloon("red", "Blimpo", 4);
        hasDMA map("Mercator", "Buffalo Keys", 5);

        cout << shirt << endl;
        cout << balloon << endl;
        cout << map << endl;

        lacksDMA balloon2(balloon);
        hasDMA map2;
        map2 = map;

        cout << balloon2 << endl;
        cout << map2 << endl;


        return 0; 

} /*This is line 44*/



And when compiling with g++, I am given this response:

usedma.cpp:44:1: error: expected ‘}’ at end of input
usedma.cpp:44:1: error: expected unqualified-id at end of input

Now, I'm not too sure as to what is going on here. Surely it recognizes a '}'.

I am grateful for any input.

Thank you.
Last edited on Dec 23, 2011 at 9:38pm
Dec 23, 2011 at 10:44pm
no that means you have one too many of these also it would be nice if you showed ur whole code
Dec 23, 2011 at 10:44pm
cause the problem is at line 44
Dec 23, 2011 at 11:14pm
I'll introduce the other files:

dma.h
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
#ifndef DMA_H_
#define DMA_H_

#include <iostream>


/*Base Class using DMA*/
class baseDMA {
private:
        char* label;
        int rating;

public:
        baseDMA(const char* l = "null", int r = 0);
        baseDMA(const baseDMA & rs);
        virtual ~baseDMA();
        baseDMA & operator=(const baseDMA & rs);
        friend std::ostream & operator<<(std::ostream & os, const baseDMA & rs);
};

/*
 * Derived class without DMA
 * No destructor needed
 * Uses implicit copy constructor
 * Uses implicit assignment operator
 */
class lacksDMA : public baseDMA {
private:
        enum {COL_LEN = 40};
        char color[COL_LEN];

public:
        lacksDMA(const char* c = "blank", const char* l = "null", int r = 0);
        lacksDMA(const char* c, const baseDMA & rs);
        friend std::ostream & operator<<(std::ostream & os, const lacksDMA & rs);

};


/*Derived class with DMA*/
class hasDMA : public baseDMA {
private:
        char* style;
public:
        hasDMA(const char* s = "none", const char* l = "null", int r = 0);
        hasDMA(const char* s, const baseDMA & rs);
        hasDMA(const hasDMA & hs);
        ~hasDMA();
        hasDMA & operator=(const hasDMA);
        friend std::ostream & operator<<(std::ostream & os, const hasDMA & rs);
};

#endif /*DMA_H_*/







dma.cpp
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
/*Base DMA Methods*/
baseDMA::baseDMA(const char* l, int r) {
        label = new char[std::strlen(l) + 1];
        std::strncpy(label, l);
        rating = r;
}

baseDMA::baseDMA(const baseDMA & rs) {
        label = new char[std::strlen(rs.label) + 1];
        std::strncpy(label, rs.label);
        rating = rs.rating;
}

baseDMA::~baseDMA() {
        delete [] label;
}
baseDMA & baseDMA::operator=(const baseDMA & rs) {
        if(this == &rs)
                return *this;
        delete [] label

        label = new char[std::strlen(rs.label) + 1];
        std::strcpy(label, rs.label);
        rating = rs.rating;
        return *this;
}

std::ostream & operator<<(std::ostream & os, const baseDMA & rs) {
        os << "Label: " << rs.label << std::endl;
        os << "Rating: " << rs.rating << std::endl;
        return os;
}

/*lacksDMA Methods*/
lacksDMA::lacksDMA(const char * c, const char* l, int r) : baseDMA(l,r) {
        std::strncpy(color, c, 39);
        color[39] = '\0';
}

lacksDMA::lacksDMA(const char* c, const baseDMA & rs) : baseDMA(rs) {
        std::strncpy(color, c, COL_LEN - 1);
        color[COL_LEN] = '\0';
}

std::ostream & operator<<(std::ostream & os, const lacksDMA & ls) {
        os << (const baseDMA &) ls;
        os << "Color: " << ls.color << std::endl;
        return os;
}

/*hasDMA Methods*/
hasDMA::hasDMA(const char* s, const char* l, int r) : baseDMA(l, r) {
        style = new char [std::strlen(s) + 1];
        std::strcpy(style, s);
}

hasDMA::hasDMA(const char* s, const baseDMA & rs) : baseDMA(rs) {
        style = new char[std::strlen(hs.style) + 1];
        std::strcpy(style, hs.style);
}

hasDMA::~hasDMA() {
        delete [] style;
}
hasDMA & hasDMA::operator=(const hasDMA & hs) {
        if(this == &hs)
                return *this;
        baseDMA::operator=(hs); /*Copying base portion*/
        style = new char[std::strlen(hs.style) + 1];
        std::strcpy(style, hs.style);
        return *this;
}

std::ostream & operator<<(std::ostream & os, const lacksDMA & ls) {
        os << (const baseDMA &) ls;
        os << "Style: " << hs.style << std::endl;
        return os;
}
}; /*For those reading this, the error was directed here, as there was a missing brace. g++ mistakenly took it for the main function. Probably due to the destructor. */



Aramil of Elixia, thank you for asking me to put this up, I wouldn't have spotted the failure at the end without you. Thanks
Last edited on Dec 25, 2011 at 6:51pm
Dec 23, 2011 at 11:34pm
ur welcome just to let you know about
usedma.cpp:44:1: error: expected ‘}’ at end of input
usedma.cpp:44:1: error: expected unqualified-id at end of input

the issue is in file usedma.cpp at line 44 column 1 just learn what the problems mean
Dec 24, 2011 at 12:01am
In dma.h you didn't close the brace of class hasDMA.
Dec 25, 2011 at 6:51pm
Aramil: I know that, but, clearly, there was a brace there, so I just wondered.

Galik: I had fixed that in the real file, but thank you for pointing it out here.
Topic archived. No new replies allowed.