C++ Classes
C++ Classes
i am wondering if i can use the same class template over and over again, for example
class vehical
{
unsigned int theOwner;
drive();
}
could i do this:
vehical ford;
and then make another
vehical chevy; ? that would use two different classes both the same, or just rename it?
class vehical
{
unsigned int theOwner;
drive();
}
could i do this:
vehical ford;
and then make another
vehical chevy; ? that would use two different classes both the same, or just rename it?
Re: C++ Classes
Well firstly your drive() member function doesn't have any return type, so the compiler will most likely produce an error. You also finish the class definition by a trailing ';', so class Name {};. I also think you meant Vehicle instead of Vehical . The point of structures/classes is to define objects from them, so I don't see why you shouldn't be able to use the same class over again:GhostXoPCorp wrote:i am wondering if i can use the same class template over and over again, for example
class vehical
{
unsigned int theOwner;
drive();
}
could i do this:
vehical ford;
and then make another
vehical chevy; ? that would use two different classes both the same, or just rename it?
Code: Select all
class Vehicle
{
public:
void foo() { std::cout << "Hello foo()\n"; }
};
int main()
{
Vehicle Opel;
Vehicle Ford;
Vehicle BMW, Toyota;
Ford.foo(); // Calls 'foo' member function.
}
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
Re: C++ Classes
thank you, so in a class could i have
and then to call the function:
pepperoni.function();
or would i have to set the class up like this:
Code: Select all
int function() {
cout << "Example" << endl;
return 0;
};
class pizza
{
function();
};
pizza pepperoni;
pepperoni.function();
or would i have to set the class up like this:
Code: Select all
class pizza
{
int function(); //or void?
};
Re: C++ Classes
You must specify a complete prototype including return type when declaring any function.
When you define the function, you must prefix the name with the class name followed by two colons, unless it is defined inside the class definition block.
The primary advantage of classes is that they can be subclasses of other classes, and provide different implementations of the same functions.
When you define the function, you must prefix the name with the class name followed by two colons, unless it is defined inside the class definition block.
The primary advantage of classes is that they can be subclasses of other classes, and provide different implementations of the same functions.
- gravaera
- Member
- Posts: 737
- Joined: Tue Jun 02, 2009 4:35 pm
- Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.
Re: C++ Classes
Wow: this is nice. I like this valuable, teaching thread. I like how on an OS Development forum, where people are expected to be kernel developers, there are people who are asking how classes in C++ work. It's great reading, and it stimulates my mind. Nice to see that the community is moving forward.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
Re: C++ Classes
00000000000000000000000
Last edited by VolTeK on Wed Jun 02, 2010 8:10 pm, edited 1 time in total.
Re: C++ Classes
Well, gravaera's right, I don't really see what a 13-year old with a bad attitude is doing hanging out at a forum for OS developers. You've even stated in another thread that you're here to start fights with anyone who is critical of you.
Re: C++ Classes
0000000000000000000000000000000
Last edited by VolTeK on Wed Jun 02, 2010 8:11 pm, edited 1 time in total.
Re: C++ Classes
This is the General Programming forum not the OS Development forum and thus is in the correct place.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: C++ Classes
Exactly.
Two sub forums:
Operating system development\Everything else
Ull never guess where i posted this
Two sub forums:
Operating system development\Everything else
Ull never guess where i posted this