944,030 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4003
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
May 24th, 2005
0

Visual Studio 6: Initializing static class member

Expand Post »
The following works on solaris, but doesn't compile on windows visual studio 6. is there a way to do this differently so it compiles in both places?

In ComandLineArg.h
-------------------------
class CommandLineArg
{
private:
..etc..
static int longestDescr;
..etc..
};

In CommandLineArg.cpp
-------------------------------

CommandLineArg::longestDescr=0;

Error on visual studio:
error C2501: 'longestDescr' : missing storage-class or type specifiers
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
May 24th, 2005
0

Re: Visual Studio 6: Initializing static class member

You forgot the type:
C++ Syntax (Toggle Plain Text)
  1. int CommandLineArg::longestDescr=0;
Reputation Points: 35
Solved Threads: 3
Posting Whiz in Training
Dogtree is offline Offline
232 posts
since May 2005
May 24th, 2005
0

Re: Visual Studio 6: Initializing static class member

I didn't realize I needed to. Why do I need to specify the datatype? (The syntax looks to me as if it is supposed to return an int rather than that it IS an int..)


(Also, why do I not need to on Solaris Workshop compiler?)
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
May 24th, 2005
0

Re: Visual Studio 6: Initializing static class member

>> Why do I need to specify the datatype?
It's a definition. Any valid definition is also a valid declaration, and standard C++ disallows implicit int declarations.

>> The syntax looks to me as if it is supposed to return an int rather than that it IS an int..
How does an object return anything? It might evaluate to something, but only after its definition during use.

>> Also, why do I not need to on Solaris Workshop compiler?
It's either pre-standard implicit int, where if a type is needed, int is assumed, or it's a compiler extension. I would guess the former.
Reputation Points: 35
Solved Threads: 3
Posting Whiz in Training
Dogtree is offline Offline
232 posts
since May 2005
May 24th, 2005
0

Re: Visual Studio 6: Initializing static class member

I added the int on it and it worked both on Sun and Visual Studio. Thanks.


(I now have to try and deal with all of MS VStudio's other really complicated STL related warnings and errors - of course all of the rest of the code works fine on SUN as well...)
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
May 24th, 2005
0

Re: Visual Studio 6: Initializing static class member

Here's another good one for you. This also compiles (and runs fine on Solaris)

Properties.h
C++ Syntax (Toggle Plain Text)
  1. template <class K, class V> class Properties : public Printable
  2. {
  3. ...etc...
  4. protected:
  5.  
  6. map<K,V> myMap;
  7. void addMap( map<K,V> mapToAdd);
  8.  
  9. ...etc..
  10. };

Properties.hpp
C++ Syntax (Toggle Plain Text)
  1. template <class K, class V> void Properties<K,V>::addMap( map<K,V> mapToAdd)
  2. {
  3. myMap.insert( mapToAdd.begin(), mapToAdd.end() );
  4. }

And the wonderfully succint error:
c:\development\danlibs\src\properties.hpp(129) : error C2664: 'class std::_Tree<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<
char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<class std::basic_string<char,struct std::char_traits<char
>,class std::allocator<char> > > >::_Kfn,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<
char> > > >::iterator __thiscall std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::bas
ic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::insert(class std::_Tree<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >,struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char
> > >,struct std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struc
t std::char_traits<char>,class std::allocator<char> > >,
class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::_Kfn,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<cl
ass std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::iterator,const struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,st
ruct std::char_traits<char>,class std::allocator<char> > > &)' : cannot convert parameter 2 from 'class std::_Tree<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::pair<class std::basic_string<char,
struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocat
or<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<class std::basic_strin
g<char,struct std::char_traits<char>,class std::allocator<char> > > >::_Kfn,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<class std::basic_string<char,struct std::char
_traits<char>,class std::allocator<char> > > >::iterator' to 'const struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std:
:allocator<char> > > &'
Reason: cannot convert from 'class std::_Tree<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > co
nst ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_trai
ts<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<cha
r> > > >::_Kfn,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::iterator' to
'const struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\program files\microsoft visual studio\vc98\include\xmemory(70) : while compiling class-template member function 'void __thiscall Properties<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std:
:basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::addMap(class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>
,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >
)'
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
May 24th, 2005
0

Re: Visual Studio 6: Initializing static class member

Quote originally posted by winbatch ...
And the wonderfully succint error:
http://www.bdsoft.com/tools/stlfilt.html
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
May 24th, 2005
0

Re: Visual Studio 6: Initializing static class member

Dave,

(It looks like I have to install perl for this to work, is that correct?)
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
May 24th, 2005
0

Re: Visual Studio 6: Initializing static class member

I was meaning to try to mess with it, but I never got around to it -- but I believe so.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
May 24th, 2005
0

Re: Visual Studio 6: Initializing static class member

Are you trying to define that function outside of the header? That ussually can cause problems.
Reputation Points: 14
Solved Threads: 4
Junior Poster
prog-bman is offline Offline
108 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Array data not setting
Next Thread in C++ Forum Timeline: Overloading operators





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC