const struct declaration

Hi,

I am new to C++ and cannot find any information about my question. I have declared a struct and defined two constants of it.

1
2
3
4
5
6
7
8
9
struct Bounds
{
	int min;
	int max;
};

const struct Bounds B1 = {3, 14};

const Bounds B2 = {3, 14};


Can somebody explain to me what the difference betweed B1 and B2 is?

Thanks a lot,
Xoric

I believe the second will not compile in C
Neither will compile in C since C does not have the "const" keyword.

Line 7 requires 7 additional keystrokes to type over line 9. And that's the only difference.
jsmith wrote:
since C does not have the "const" keyword.

Actually, it does.
Take it for what it's worth:
(moorecm@dhcp43-172-16-101)~/<2>test3:131$ ls
main.cpp
(moorecm@dhcp43-172-16-101)~/<2>test3:132$ cat main.cpp
struct Bounds
{
    int min;
    int max;
};

const struct Bounds B1 = {3, 14};
const Bounds B2 = {3, 14};

int main()
{
    return 0;
}
(moorecm@dhcp43-172-16-101)~/<2>test3:133$ gcc main.cpp
(moorecm@dhcp43-172-16-101)~/<2>test3:134$ ls
a.out*  main.cpp
(moorecm@dhcp43-172-16-101)~/<2>test3:135$ gcc --version
gcc (GCC) 4.1.2 20071124 (Red Hat 4.1.2-42)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

(moorecm@dhcp43-172-16-101)~/<2>test3:136$ 
Last edited on
Hmm, so it does.

Though when you pipe a .cpp file into gcc, it compiles it using the C++ compiler, not
the C compiler. Otherwise "const Bounds B2 = { 3, 14 };" wouldn't compile since
C requires "struct".
Whoa! That was my mistake, I meant to use a .c extension. I pasted it into an existing file (that was previously C++).


#ifndef RESIM_YUKLEYICI_H_INCLUDED
#define RESIM_YUKLEYICI_H_INCLUDED
#include <iostream>
#include <stdlib.h>
#include <bfd.h>

class Resim{
public:

Resim( char* nokta ,int c,int d);
~Resim();


char* noktalar;
int boy;
int en;

};

Resim* ResimYukle(*filename);

#endif


I want to compose a header file such as this.But take these error message:

[Linker error] undefined reference to `ResimYukle(char const*)'
[Linker error] undefined reference to `Resim::~Resim()'
ld returned 1 exit status

can u help me?I abstracted examples with about struct and destructor in the internet.But can not never an idea.Thanks everybody now.
İ am using Dev-c++
You need to link in the source that defines the methods of your class.
Thank you for your replies.
I now understand there is no difference in C++ between these two definitions.

Greetings,
Xoric
Ok ok.I tried everything methods.But it didn't work.Can u give example codes me?

Topic archived. No new replies allowed.