static consts Class Vars - Compile Problem in VC6

B

Baget

Hello

this code does not compile on VC6, it compile fine on other compilers on
two OS (gcc, bcc, VC7 on windows, gcc on Linux).

I am getting error C2057 on VC6

what to do?

========== START CODE ============
#include <iostream>
#include <cstring>

using namespace std;

class Foo {
public:
Foo(const char *a);
const char *getArray() const;

private:
static const unsigned int MY_SIZE = 20;


char myarray_[MY_SIZE];
};

Foo::Foo(const char *a)
{
strncpy(myarray_, a, MY_SIZE);
}

const char* Foo::getArray() const
{
return myarray_;
}


int main()
{
Foo bar("Test");
cout<<bar.getArray()<<endl;
return 0;
}

========== END CODE ==============
 
N

Nemanja Trifunovic

VC6 does not support initialization of static members inside of the
class definition. What you need to do is to initialize MY_SIZE in a cpp
file instead.
 
B

Baget

Nemanja said:
VC6 does not support initialization of static members inside of the
class definition. What you need to do is to initialize MY_SIZE in a cpp
file instead.

how? i tried i'm getting the same error.



-=-=-
.... C code. C code run. Run, code, run! Please run.
 
E

Edernity

helo,
may be your should try recreating your project by empty project then
insert those files.
Edernity
--------
if it help (IT DON'T CAUSE YOU A CENT. JUST 1 EMAIL THEN FILLING FORMS)
please do help me provide better school supplies for childrenof
indonesia.
IN FACT, for those other who already read this plea and maybe finding
my post helpful, what is I give you one dollars for it. I don't believe
this, I'm paying to get people to donate to kids?!!!???that really
ugly!
it may be a donation but I merely ask you to letme send email to you
from one of the product of I'm affiliated and please register there on
mechant account free. If you even want you refund back on your dollar
of i-kard, its ok, I'll send you just use regular delivery on shipping
please. Please note this is very safe since this is a bonafid company.
remember your credit card company will confirm you on your purchase.
u can add or remove more credit cards into your account. you can/should
also ask for always confirmation on send out to you. That will get
those savage cracker bloke out. even u can use some more free teen
refillable visa/mastercard from your bank cc account (can be obtaion
free).
It is just unnerving seeing how can people do not do anything as so
they need so little. $10 could support {{{{{the child 1 month.}}}}
Still have doubts, sign on a personal account and let me contact you
again on it. just one mail pls
also
I'm also affiliated to this site:
www.getaportal.com/portals/eddy_ruslim
Unless u wanto e-gold it at 1369872
New to egold:www.e-gold.com/e-gold.asp?cid=1369872
NAH, previous way cost u zilch
God bless
 
F

Francis Glassborow

Baget said:
Hello

this code does not compile on VC6,

Why should it? VC++6 is a pre-standard compiler and the feature you are
using is a late addition to C++.
 
T

Tom Widmer

Baget said:
Hello

this code does not compile on VC6, it compile fine on other compilers on
two OS (gcc, bcc, VC7 on windows, gcc on Linux).

I am getting error C2057 on VC6

what to do?

Use an enum instead:
enum {MY_SIZE = 20};

That's the standard workaround for this particular deficiency of VC6.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top