473,395 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

declaring and defining at the same time

How can I define and declare a class and its functions at the same time? Is this posssible?
Sep 8 '07 #1
5 1467
weaknessforcats
9,208 Expert Mod 8TB
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.
Sep 8 '07 #2
ilikepython
844 Expert 512MB
How can I define and declare a class and its functions at the same time? Is this posssible?
Do you mean like this:?
Expand|Select|Wrap|Line Numbers
  1. class Test
  2. {
  3.     public:
  4.         void testrun() { cout << "BLAH BLAH" << endl; };
  5. }
  6.  
The functions that are defined in the class will be inline.
Sep 8 '07 #3
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?
Sep 9 '07 #4
ilikepython
844 Expert 512MB
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?
An inline functions means whenever that function is called the compiler puts the code from that function in that specific spot. Regular functions (not inline) are called and the code executes the function. That might cause some overhead. That's why if a function is small and is called many times, it might be good to make it inline. But, it is dangerous because your file will grow in size depending on the size of the function. If you want to make you functions inline in a class just declare in the class declaration them in the .hpp file.
Sep 9 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
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?
An inline function is not called. Instead, the definition is inserted in line. That means there is no function. That means there can be no function address. That means no virtual functions. That means no object-oriented programming using inline functions.

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.
Sep 9 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sriram Chadalavada | last post by:
Hello everyone, I am a newbie to Python with experience in C programming. For my project, I am re-writing C routines as Python functions. I am currently using raw numerical values and was...
7
by: Bob Rock | last post by:
Hello, this may seem a strange question, but is there a way of being able to call methods of a class through an array of that class when not referencing a specific object in the array. In other...
3
by: Mac | last post by:
Is it legal to declare errno after you've included errno.h? For example: #include<errno.h> .... int main (void) {
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
1
by: Gary Wessle | last post by:
Hi can I declare an ofstream in a class declaration in .h file and define it inside a method in the .cpp file? if so, what does the syntax of defining it looks like. I tried .... ofstream...
8
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
5
by: =?Utf-8?B?RWl0YW4=?= | last post by:
Hello, I am declaring an element like this: public static List<myListElementmyList = new List<myListElement>(); I would like to declare an array of this myList. How would I modify the...
8
by: nguillot | last post by:
Hello. If I have the following classes: class B {}; typedef B tB; if A is: class A
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.