Problem with code or gcc?

Kedzierski, Artur CIV NAVSURFWARCENDIV CORONA artur.kedzierski@navy.mil
Tue Sep 27 14:57:00 GMT 2005


	Philippe and Ryan, thank You for your responses.
	One thing that I find it strange is that I can use
MyStruct::CONST in other ways without a problem:

MyStruct m;
int a = m.CONST
std::vector<int> v;
v.push_back(static_cast<int>(m.CONST));
if (b == m.CONST) 
  ...

	However, only when I use 'v.push_back(m.CONST)', I
get a linker error. Shouldn't I get a linker error in
those other cases?


-----Original Message-----
From: Philippe Haution [mailto:philippe_haution@yahoo.fr]
Sent: Tuesday, September 27, 2005 7:13
To: Kedzierski, Artur CIV NAVSURFWARCENDIV CORONA; gcc-help@gcc.gnu.org
Subject: RE: Problem with code or gcc?


Hello,

This is not a valid C++ code, you cannot define the
value of CONST inside the struct declaration.

A more correct code would be :

struct MyStruct {
 static const int CONST;
};

const int MyStruct::CONST = 1;

Regards,

PH

--- "Kedzierski, Artur CIV NAVSURFWARCENDIV CORONA"
<artur.kedzierski@navy.mil> a écrit :

> 	Could anybody tell me if this is a valid C++ code
> or
> a problem with GCC?
> 
> test_prog.cc:
> #include <vector>
> struct MyStruct {
> 	static const int CONST = 1;
> };
> 
> int main() {
> 	std::vector<int> l;
> 	MyStruct z;
> 	l.push_back(z.CONST);
> }
> 
> 
> 	I get an undefined reference to MyStruct::CONST
> when 
> I try to compile it.
> 	I appreciate any help.
> 
> 	Artur Kedzierski
> 



	

	
		
________________________________________________________________________
___ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo!
Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 4051 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20050927/9b2224ea/attachment.bin>


More information about the Gcc-help mailing list