How can I define and declare a class and its functions at the same time? Is this posssible?
declaring and defining at the same time
Collapse
X
-
Tags: None
-
You don't define a class. You declare it.
The definition is the creation of an object of that class.
The class methods ar typically declared by having the function prototypes inside the class declaraion. You can put the function definition there (the code) but that makes the methods inline and that may not be what you want. -
Originally posted by curious2007How can I define and declare a class and its functions at the same time? Is this posssible?
[code=cpp]
class Test
{
public:
void testrun() { cout << "BLAH BLAH" << endl; };
}
[/code]
The functions that are defined in the class will be inline.Comment
-
OK, thanks but what happens if a function is inline? Does this put restrictions on what I can do with it? Also, if I make this function declerations and definitions in one file, is this going to be an hpp or cpp?Comment
-
Originally posted by curious2007OK, thanks but what happens if a function is inline? Does this put restrictions on what I can do with it? Also, if I make this function declerations and definitions in one file, is this going to be an hpp or cpp?Comment
-
Originally posted by curious2007OK, thanks but what happens if a function is inline? Does this put restrictions on what I can do with it? Also, if I make this function declerations and definitions in one file, is this going to be an hpp or cpp?
The compiler needs to see the function definition in oreder o insert it in line. That means the inline function definition goes in a header file.Comment
Comment