OOP in C++: Objects failing

A

Anonymous

I am writing a test to try out OOP in C++. I am trying to get it to create
objects, then activate their functions in a specific order (the commented
section at the bottom). However, even without that section (which should be
ignored since it is commented out), I get errors:

ooptest.cpp:19: ISO C++ forbids defining types within return type
ooptest.cpp:19: return type specification for constructor invalid
ooptest.cpp:19: default argument given for parameter 5 of
`Vehicle::Vehicle(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int, int = 200)'
ooptest.cpp:16: after previous specification in
`Vehicle::Vehicle(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int, int = 200)'

What am I doing wrong?

Anonymous
 
A

Alf P. Steinbach

* Anonymous:
What am I doing wrong?

1) You're posting anonymously.
2) You don't include the code.
3) You don't have a standard signature delimiter.
 
M

Mike Wahler

Anonymous said:
I am writing a test to try out OOP in C++. I am trying to get it to create
objects, then activate their functions in a specific order (the commented
section at the bottom). However, even without that section (which should be
ignored since it is commented out), I get errors:

ooptest.cpp:19: ISO C++ forbids defining types within return type
ooptest.cpp:19: return type specification for constructor invalid
ooptest.cpp:19: default argument given for parameter 5 of
`Vehicle::Vehicle(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int, int = 200)'
ooptest.cpp:16: after previous specification in
`Vehicle::Vehicle(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int, int = 200)'

What am I doing wrong?

As soon as you show us the code we'll tell you.

-mike
 
V

Victor Bazarov

Alf P. Steinbach said:
* Anonymous:

1) You're posting anonymously.

Why is that wrong?
2) You don't include the code.

I agree with that.
3) You don't have a standard signature delimiter.

What's a signature delimiter?

In any case, to the OP: you probably have code like this:

class MyClass {
blah-dee-blah
}

MyClass::MyClass() {
blahblahblah-dee-blah
}

What's wrong? Semicolon is missing after the class definition.

Alf, did you mean the semicolon by a "signature delimiter"?

V
 
A

Alf P. Steinbach

* Victor Bazarov:
Why is that wrong?

For one, there is a much greater chance of the OP being a troll,
and correspondingly less chance for herim to get a decent answer.

Alf, did you mean the semicolon by a "signature delimiter"?

No, I meant
 
V

Victor Bazarov

Alf P. Steinbach said:
* Victor Bazarov:

No, I meant

--

I stopped putting my signature in about a year ago. Nobody
complained yet... Are you going to flame me for not having
a signature delimiter?

V, looking for his asbestos shorts...
 
M

Mike Wahler

Anonymous said:
Sorry. I intended to attach it, but forgot.

Don't post attachments to comp.lang.c++ (or any group where
they're not specifically allowed). I (and probably
many others) cannot see your attachment. Paste the text
of your code directly into your message.
BTW, I have corrected one error
(suggested by Victor Bazarov, adding the semicolon after the class
definition), but I am still getting the following errors:

I'm still waiting to see your code. :)

-Mike
 
I

Ivan Vecerina

Pretty much what the compiler says: the default value of a parameter
shall only be given once (usually in the interface/declaration).
So after declaring Vehicle::Vehicle, the "= 200" must be omitted from
the definition:
Vehicle::Vehicle(string _make, string _model, string _colour
, int _price, int _maxspeed )
{ /*...*/ }

Also:
bool Vehicle::buy(int& account) {
account-=price;
owned = true;
owned_by_user = true;
//MISSING A RETURN STATEMENT HERE
}
bool Vehicle::sell(int& account) {
account+=((price/10)*8);
owned_by_user = false;
//MISSING A RETURN STATEMENT HERE
}

I didn't do any further checks...


I hope this helps,
Ivan
 
A

Alan Krueger

Anonymous said:
As I tried to send earlier, I corrected one error (by adding a semicolon on
to the end of the class definition), but I'm still getting:

It tells you what's wrong.
[...] default argument given for parameter 5 [...] after previous specification [...]

You're re-defining a default parameter in that constructor.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top