Objects as members?
Is it possible to declare an object from a different class to be a member of a class? If so then how.
How many times do i have to punch the fucking monkey?
class foo{int foo;};class bar{foo my_foo;};
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Here is my code:
VC gives the following compiler error:
error C2059: syntax error : ''string''
class Obj{public: Obj(char file[128]); float vertArray[36]; void LoadBasicInfo(); void LoadFileData(); int GetNumVerts(); int GetNumFaces(); int GetNumVertNormals();private: typedef float vertex[3]; typedef float normals[3]; vertex *verts; normals *norms; bool fileLoad; char fileName[40]; int numVerts; int numVertNormals; int numFaces;};class Foo{ Obj obj("box.obj");};
VC gives the following compiler error:
error C2059: syntax error : ''string''
How many times do i have to punch the fucking monkey?
Im not sure if Im right but, I think you need to change:
Obj(char file[128]);
to:
Obj(char *file);
Obj(char file[128]);
to:
Obj(char *file);
Not quite.
In a class declaration you may only declare how the class is built up, but execute code.(only exception inline functions)
Btw: The declaration with the Obj(char file[128]); is absolutely valid.
This should work:
class Foo
{
Foo (void); // Or something
Obj obj;
};
in the header and then
Foo::Foo( void ):
Obj("whateverstringyouwant")
{
// other init stuff
}
By the way, if you wondered why sometimes you were able to use objects in your classes this is because the class of the object had a constructor using no arguments or no constructor at all (which results in a default public constructor)
class myclass
{
void myclass(void);
or
void myclass (sometype *something = 0 );
or
// no constructor declaration at all
};
Edited by - NextS on September 11, 2000 11:02:19 AM
In a class declaration you may only declare how the class is built up, but execute code.(only exception inline functions)
Btw: The declaration with the Obj(char file[128]); is absolutely valid.
This should work:
class Foo
{
Foo (void); // Or something
Obj obj;
};
in the header and then
Foo::Foo( void ):
Obj("whateverstringyouwant")
{
// other init stuff
}
By the way, if you wondered why sometimes you were able to use objects in your classes this is because the class of the object had a constructor using no arguments or no constructor at all (which results in a default public constructor)
class myclass
{
void myclass(void);
or
void myclass (sometype *something = 0 );
or
// no constructor declaration at all
};
Edited by - NextS on September 11, 2000 11:02:19 AM
You can use static object members for it or pointer to object ....
=============================
Denis "Mr.Snow" Kozhukhov
CEO & Lead programmer
Choco Snow Creation
dkcscPortal
=============================
=============================
Denis "Mr.Snow" Kozhukhov
CEO & Lead programmer
Choco Snow Creation
dkcscPortal
=============================
=============================Denis "Mr.Snow" KozhukhovCEO & Lead programmerChoco Snow CreationdkcscPortal=============================
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement