Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Inline class members used in vc 2005

Reply
Thread Tools

Inline class members used in vc 2005

 
 
Allen
Guest
Posts: n/a
 
      12-05-2006
Last time, i post a topic about inline class member declaration in C++.
And in VC6, it does not support inline class member.

Now I upgrade to VC 2005. But the compiler doesnot completely support
it.

// Logger.h
class CLogger
{
public:
static const int nameLen = 16;
};

// FileLogger.cpp
#include "Logger.h"

void CFileLogger::Write()
{
char szBuf[CLogger::nameLen];
...
}

// DnetLogger.cpp
#include "Logger.h"

void CDnetLogger::Write()
{
char szBuf[CLogger::nameLen];
...
}

As shown above, CLogger::nameLen was used in serval cpp files.
I am confused by vc 2005 that one of the cpp files failed to compile.
It says that CLogger::nameLen is illegal, syntax error.
Why?

 
Reply With Quote
 
 
 
 
Salt_Peter
Guest
Posts: n/a
 
      12-05-2006

Allen wrote:
> Last time, i post a topic about inline class member declaration in C++.
> And in VC6, it does not support inline class member.
>
> Now I upgrade to VC 2005. But the compiler doesnot completely support
> it.
>
> // Logger.h
> class CLogger
> {
> public:
> static const int nameLen = 16;
> };


What book are you reading that doesn't explain how to define a static
variable?
http://www.parashift.com/c++-faq-lite/ctors.html

// Logger.cpp
const int CLogger::nameLen = 16;

>
> // FileLogger.cpp
> #include "Logger.h"
>
> void CFileLogger::Write()
> {
> char szBuf[CLogger::nameLen];
> ...
> }


personally, i'ld write the class with a template parameter:

template< const size_t Size >
class FileLogger
{
char buffer[Size];
public:
void write() const ();
};

int main()
{
FileLogger< 16 > flog;
}

// or ...

#include <vector>
class FileLogger
{
std::vector< char > vc;
public:
FileLogger() : vc(16) { }
FileLogger(size_t sz) : vc(sz) { }
void write() const ();
};

>
> // DnetLogger.cpp
> #include "Logger.h"
>
> void CDnetLogger::Write()
> {
> char szBuf[CLogger::nameLen];
> ...
> }
>
> As shown above, CLogger::nameLen was used in serval cpp files.
> I am confused by vc 2005 that one of the cpp files failed to compile.
> It says that CLogger::nameLen is illegal, syntax error.
> Why?


 
Reply With Quote
 
 
 
 
Allen
Guest
Posts: n/a
 
      12-06-2006

"Salt_Peter д
"
> template< const size_t Size >
> class FileLogger
> {
> char buffer[Size];
> public:
> void write() const ();
> };
>
> int main()
> {
> FileLogger< 16 > flog;
> }
>


It is not convenient to use in this way.
Now I find the answer. Because in another header file, there is a
#define nameLen 16
macro definition.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a vb 2005 usercontrol be used in asp 2005? billsahiker@yahoo.com ASP .Net 5 05-17-2007 09:56 AM
class members vs instance members hdixon Python 3 07-09-2006 06:56 PM
To inline or not to inline? Alvin C++ 7 05-06-2005 03:04 PM
Can nested class members access private members of nesting class? CoolPint C++ 8 12-14-2003 02:30 PM
inline or not to inline in C++ Abhi C++ 2 07-03-2003 12:07 AM



Advertisments