473,394 Members | 1,658 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,394 software developers and data experts.

member function definition inside and outside class..function already defined error..

Hi all,

what's difference does it make when we define the member function
inside and outside a class?

I am using vc7.
when i define the member functions outside a class with the scope
resolution operator and put everything inside a .h file (also note that
i have put the include guard to avoid multiple inclusion of the same
header file accedently ) and include this file in multiple source file
from a same project then i get the error of "function already defined
in some *.obj file.."
so to avoid that now when i put all the member function definitions
inside a class the same project compiles successfully...
could any please tell me the reason behind this behaviour?
Regards,
Yogesh Joshi

Jan 9 '06 #1
1 4347
yp*********@indiatimes.com wrote:
Hi all,

what's difference does it make when we define the member function
inside and outside a class?

I am using vc7.
when i define the member functions outside a class with the scope
resolution operator and put everything inside a .h file (also note that
i have put the include guard to avoid multiple inclusion of the same
header file accedently ) and include this file in multiple source file
from a same project then i get the error of "function already defined
in some *.obj file.."
so to avoid that now when i put all the member function definitions
inside a class the same project compiles successfully...
could any please tell me the reason behind this behaviour?
Regards,
Yogesh Joshi


To define the member function in the .h file, use:

inline
return_type Class::Function(arg_t arg)
{
}

Member functions defined inside the class declaration are implicitly
inline.

See: http://www.parashift.com/c++-faq-lit...s.html#faq-9.8
/S
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de
Jan 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bo Sun | last post by:
hi: please take a look at the following code fragment: class Test{ public: static int i; Test() {i = 33;} };
5
by: rossum | last post by:
Either I have found a puzzle, or I am just being stupid. Inside a namespace I have a class with a static const double member. The member is not an int so I cannot initialise it within the class,...
3
by: Tran Tuan Anh | last post by:
Dear all, I am new with C++ and very confused with some features. Really appreciate if you can explain to me some of stuffs below. I define a class: class A { static A* instance = 0; };
3
by: Dave | last post by:
Hello all, Please consider this code: #ifndef FOO_INCLUDED #define FOO_INCLUDED // File: foo.h class foo {
5
by: Martin Vorbrodt | last post by:
so if i have this: // header.h class X { public: static int s = 1; }; i still need this:
6
by: Bill Rubin | last post by:
The following code snippet shows that VC++ 7.1 correctly compiles a static member function invocation from an Unrelated class, since this static member function is public. I expected to compile the...
10
by: stonny | last post by:
I read the following sentence from a c++ website, but can not understand why. can anyone help me with it? " An important detail to keep in mind when debugging or implementing a program using a...
21
by: H9XLrv5oXVNvHiUI | last post by:
Hi, I have a question about injecting friend functions within template classes. My question is specific to gcc (version 3.4.5) used in combination with mingw because this code (or at least code...
4
by: aaragon | last post by:
Hi everyone, I have a linking error when using gcc4.2 and static member variables. The class template definition is something around the following: template<> class Element<L2_t: public...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.