|
stl list of structs |
Frank Drebin
Member #2,987
December 2002
|
until now i only used classes with stl::list. mystructs.push_back(); or mystructs.push_back(mystruct); it seems i have to write mystructs.push_back(mysrtuct());
is this ok? |
juvinious
Member #5,145
October 2004
|
Hmm, what? typedef struct myStruct { int x; int y; }MYSTRUCT; list<MYSTRUCT>sList; MYSTRUCT obj; sList.push_back(obj);
__________________________________________ |
Frank Drebin
Member #2,987
December 2002
|
yes... but it won't compile this way |
juvinious
Member #5,145
October 2004
|
compiles for me __________________________________________ |
Archon
Member #4,195
January 2004
|
Quote: a struct doens't have a construcor, right? Isn't a struct in C++ just a class with default protection levels to public (IIRC from another thread in the past)? |
Hano Wair
Member #5,243
November 2004
|
Quote: Isn't a struct in C++ just a class with default protection levels to public (IIRC from another thread in the past)? It is. |
Frank Drebin
Member #2,987
December 2002
|
! |
Archon
Member #4,195
January 2004
|
Quote:
so how's a constructor defined in a struct (example)? Try defining it like you would define a class... |
CGamesPlay
Member #2,559
July 2002
|
There is absolutely no difference between this line:struct A {And this line:class A { public: [edit] -- Ryan Patterson - <http://cgamesplay.com/> |
Frank Drebin
Member #2,987
December 2002
|
why aren't the *structors called when i put brackets after mytest? |
CGamesPlay
Member #2,559
July 2002
|
Interesting. I'm sure it has something to do with this problem. The "fix" is this program:
-- Ryan Patterson - <http://cgamesplay.com/> |
ImLeftFooted
Member #3,935
October 2003
|
Quote: There is absolutely no difference between this line: struct A { And this line: class C { public: But A and C are different |
CGamesPlay
Member #2,559
July 2002
|
Heh, interesting typo. -- Ryan Patterson - <http://cgamesplay.com/> |
Indeterminatus
Member #737
November 2000
|
Quote: // test mytest(); //doesn't work It doesn't work because it's a forward declaration of a function with the name mytest. _______________________________ |
Matthew Dalrymple
Member #7,922
October 2006
|
Shouldn't this work though? test *mytest = new test();
=-----===-----===-----= |
Archon
Member #4,195
January 2004
|
Quote:
Shouldn't this work though? Yeah but that's using the heap memory. |
X-G
Member #856
December 2000
|
Quote: There is absolutely no difference between this line: Wrong! Structs have public inheritance by default. Classes do not. -- |
CGamesPlay
Member #2,559
July 2002
|
Quote: Structs have public inheritance by default. Classes do not. Could you post a code segment demonstrating the difference? -- Ryan Patterson - <http://cgamesplay.com/> |
X-G
Member #856
December 2000
|
gcc said:
classes.cpp: In function `int main(int, char**)':
-- |
Indeterminatus
Member #737
November 2000
|
Quote: Structs have public inheritance by default. Classes do not. [emphasis added, ed.]
struct Base { }; struct A : Base { // public inheritance by default }; class WhatEverBase { }; class A : public WhatEverBase { // not public by default }; Granted, it doesn't make a difference in the sample you posted (as there's no inheritance whatsoever), but it still has to be considered a difference between a class and a struct (their default visibility aside). _______________________________ |
CGamesPlay
Member #2,559
July 2002
|
Okay. That's what I thought, but I didn't know that struct A : Base was valid C++ -- Ryan Patterson - <http://cgamesplay.com/> |
|