[I read the sticky and I'm trying to give useful information so someone can help me but I'm a little frustrated so if I'm overlooking something tell me]
I've got a really odd compile error and some more typical ones:
main.cpp: In constructor `cup::cup()':
main.cpp:9: error: `int container::cap' is private
main.cpp:23: error: within this context
main.cpp:9: error: `int container::cap' is private
main.cpp:23: error: within this context
main.cpp:10: error: `int container::full' is private
main.cpp:23: error: within this context
main.cpp:10: error: `int container::full' is private
main.cpp:23: error: within this context
main.cpp: At global scope:
main.cpp:27: error: new types may not be defined in a return type
main.cpp:27: error: two or more data types in declaration of `main'
main.cpp:27: error: extraneous `int' ignored
main.cpp:27: error: `main' must return `int'
make.exe: *** [main.o] Error 1
For this code:
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
|
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
class container
{
int cap;
int full;
string type;
protected:
container()
{cap = 0; full = 0;}
container(int a, int b)
{cap = a; full = b;}
}
class cup : public container
{
public:
cup()
{cap = 50; full = 0;}
}
int main()
{
cup();
cout << "hello.";
return 0;
}
|
I'm running Dev-C++ on XP if that helps.
I don't see what the problem is with line 27, though I did find a way to prevent the error. I removed the cup class and it successfully compiled, but I can't figure out for the life of me how the errors for line 27 are related to the class and what's wrong with it. Also, I expected the cup class to inherit the cap and full variables from the container class and be able to access them from the cup() constructor without a problem whether they're private or not because they're in the same class. Umm, any help? They're probably glaringly obvious mistakes but I'm pretty new to programming.