Standard Compliance Check

closed account (3hM2Nwbp)
I have the following that works fine with VS2010, but something tells me it's too good to be true standard compliant. This code is something of a refactoring project to simplify the end-user interface for the library that contains it. Please direct attention to line 11.

Does line 11 conform to the C++ bible? Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef FORMAL_HEADER_PROTOCOL_HPP_INCLUDED
#define FORMAL_HEADER_PROTOCOL_HPP_INCLUDED

#include <boost/shared_array.hpp>

template<typename DownstreamPacket_Type, const unsigned int Header_Length>
class FormalHeaderProtocolDecoder
{
public:

	static const unsigned int HEADER_LENGTH = Header_Length; // <-- This Line

	virtual unsigned int decodeHeader(unsigned char header[HEADER_LENGTH]) const = 0;

	virtual DownstreamPacket_Type decodeBody(boost::shared_array<unsigned char> data, unsigned int length) const = 0;

};

#endif 
Last edited on
Have you tried it with GCC? If not, Why not?
closed account (3hM2Nwbp)
helios wrote:
Have you tried it with GCC? If not, Why not?


My command-line-fu is weak.

On a serious note - I've done something to break my GCC installation and didn't want to spend the time debugging it right now. (Code::Blocks always says that there is nothing to build??) I'm also ill-informed on how well GCC complies with the standard without the -pedantic flag (I think that's right). I'm also not sure how to set the pedantic flag on any of the various online compilers.

I guess it all boils down to: I thought that I could get a simple yes / no answer in a minute or two by posting this thread rather than trying to figure something out that might not be correct on my own.

:-\

*You can be sure that when I make a topic on this site it's the next resort if I'm not confident with finding an answer for myself.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

template <int N>
struct A{
	static const int a=N;
};

int main(){
	A<8> a;
	A<9> b;
	std::cout <<a.a<<std::endl;
	std::cout <<b.a<<std::endl;
}
is accepted by GCC (with --pedantic) and produces the expected output.
The inline declaration of static const member of integral types and enums is part of the standard.

I don't have the standard to hand, but this is Stroustrup's, take:
http://www2.research.att.com/~bs/bs_faq2.html#in-class

Andy

P.S. Note his comment about taking the address.
Last edited on
closed account (3hM2Nwbp)
Thanks, helios, andy.
Topic archived. No new replies allowed.