thanks John.
i have another question about inline function
I wrote a class to calculate lines in cpp files or head files.
class clsCalculateLines
{
long lNullline;
char* p_FileName;
public:
clsCalculateLines(char* m_FilePara):p_FileName(m_FilePara);
{
lNullline=0;
};

};

my question is why the constructor function must be a inline function. if i
define the constructor outside the class definition, i could not compile it
correctly, i thought ":p_FileName(m_FilePara)" brought the trouble to me,
right?

Re: another question about inline function. by Ulrich

Ulrich
Thu Mar 01 02:10:07 CST 2007

Lorry Astra wrote:
> class clsCalculateLines
> {
> long lNullline;
> char* p_FileName;
> public:
> clsCalculateLines(char* m_FilePara):p_FileName(m_FilePara);
> {
> lNullline=0;
> };
> };

This won't compile. Also, who owns m_FilePara/p_FileName? In case you can't
answer that, use std::string instead.

> my question is why the constructor function must be a inline function.

It doesn't. Look up the way that functions inside and outside the class
definitions are defined, the same applies to special functions like ctors
and dtors.

> [...] i could not compile it correctly, i thought [...] brought the
> trouble to me, right?

Yeah, sure, my crystal ball tells me the same. Above code doesn't compile.
Nobody except you knows the error message yet. Maybe John knows, but if
this is supposed to be a follow-up to a previous posting, nobody except you
knows to which posting.

Uli


Re: another question about inline function. by LorryAstra

LorryAstra
Thu Mar 01 02:38:25 CST 2007

Sorry uli ,i forgot to delete the semicolon, i'll paste my question again:
i have another question about inline function
I wrote a class to calculate lines in cpp files or head files.
class clsCalculateLines
{
long lNullline;
char* p_FileName;
public:
clsCalculateLines(char* m_FilePara):p_FileName(m_FilePara)
{
lNullline=0;
}

};

"clsCalculateLines(char* m_FilePara):p_FileName(m_FilePara)" is a inline
function in this class. But if i define this function outside the class, i
can not compile it correctly.
for example:

in a head file:
class clsCalculateLines
{
long lNullline;
char* p_FileName;
public:
clsCalculateLines(char* m_FilePara):p_FileName(m_FilePara);
};

in a cpp file:

clsCalculateLines(char* m_FilePara):p_FileName(m_FilePara)
{
.......
}

why?

Re: another question about inline function. by Paul

Paul
Thu Mar 01 04:39:58 CST 2007

> in a head file:
> class clsCalculateLines
> {
> long lNullline;
> char* p_FileName;
> public:
> clsCalculateLines(char* m_FilePara):p_FileName(m_FilePara);
> };

class clsCalculateLines
{
long lNullline;
char* p_FileName;
public:
clsCalculateLines(char* FilePara); // no ":p_FileName(m_FilePara)"
};

> in a cpp file:
>
> clsCalculateLines(char* m_FilePara):p_FileName(m_FilePara)
> {
> .......
> }

clsCalculateLines::clsCalculateLines(char* FilePara) : p_FileName(FilePara)
// added "clsCalculateLines::" to indicate scope
{
//...
}



Re: another question about inline function. by David

David
Thu Mar 01 04:45:41 CST 2007

Lorry Astra wrote:

> in a head file:
> class clsCalculateLines
> {
> long lNullline;
> char* p_FileName;
> public:
> clsCalculateLines(char* m_FilePara):p_FileName(m_FilePara);
> };
>
> in a cpp file:
>
> clsCalculateLines(char* m_FilePara):p_FileName(m_FilePara)
> {
> .......
> }
>
> why?

Because you must write:

clsCalculateLines::clsCalculateLines(char*
m_FilePara):p_FileName(m_FilePara)
{
.......
}

If you made this mistake as often as I do, you would get good at
recognizing it :).

David Wilkinson

Re: another question about inline function. by LorryAstra

LorryAstra
Thu Mar 01 10:23:37 CST 2007

OK, thanks David, I got it :)


Re: another question about inline function. by Ben

Ben
Fri Mar 02 09:47:04 CST 2007


"Lorry Astra" <LorryAstra@discussions.microsoft.com> wrote in message
news:F5D7B052-7D59-4A97-ACA4-8A6B22B28A72@microsoft.com...
> thanks John.
> i have another question about inline function
> I wrote a class to calculate lines in cpp files or head files.
> class clsCalculateLines
> {
> long lNullline;
> char* p_FileName;
> public:
> clsCalculateLines(char* m_FilePara):p_FileName(m_FilePara);
> {
> lNullline=0;
> };
>
> };
>
> my question is why the constructor function must be a inline function. if
> i
> define the constructor outside the class definition, i could not compile
> it
> correctly, i thought ":p_FileName(m_FilePara)" brought the trouble to me,
> right?

Glad you had your question answered, but just wanted to mention that any
time you want someone else to look at your code, it's a good idea to follow
common conventions. You have used m_ as a prefix on a parameter, and p_ on
a member, when common sense dictates the opposite.