problems in class
ok.. this code is part from my program..
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
class Point
{
public: ;
Point(int xx, int yy, int zz);
~Point();
private: ;
int itsx;
int itsy;
int itsz;
}
Point::Point(int xx, int yy, int zz)
{
itsx = xx;
itsy = yy;
itsz = zz;
}
Point::~Point()
{
}
/////////////////////////////////////////////////
i get an error saying this:
return type specification for constructor invalid
i dont get whats going wrong.. ive checked this book and the class looks fine and dandy
also.. while im putting that up.. is it possable to create a new object from that class "Point" by going..
Point Name(..etc
where Name is a character string that say holds the word hello...
would it create a class object named hello.. or would it just error..
You require a ; after the class declaration.
As for the second question, I'm not quite sure what you mean. Do you mean that if you wrote it as mentioned, you'd have a new class called hello? I think you'd just end up with an instance of Point, or an error, depending on what you do within the parathensis.
class Point{public: ;Point(int xx, int yy, int zz);~Point();private: ;int itsx;int itsy;int itsz;}; // <-- right there
As for the second question, I'm not quite sure what you mean. Do you mean that if you wrote it as mentioned, you'd have a new class called hello? I think you'd just end up with an instance of Point, or an error, depending on what you do within the parathensis.
i mean that if i had
Point hello(...)
then the instance would be of point and would called hello...
but if i put a character string in place of hello.. would it create an instance of the class named whatever was in the character string?
and that solved problem 1.. i cant believe i didnt see that :(
Point hello(...)
then the instance would be of point and would called hello...
but if i put a character string in place of hello.. would it create an instance of the class named whatever was in the character string?
and that solved problem 1.. i cant believe i didnt see that :(
Quote:Original post by Origanlmaxin
but if i put a character string in place of hello.. would it create an instance of the class named whatever was in the character string?
No. C++ has no built-in facility for creating class instances by name. You would need to write a Factory to achieve that.
I don't think the factory pattern is what the OP is after. The factory pattern solves the problem "Someclass" object(parameters); whereas the OP seems to want KnownClass "somename"(parameters);. This can be done by, for example:
However, the situations where this is the right solution are limited (usually some form of scripting). What problem are you trying to solve? There may well be a better solution.
Enigma
std::map< std::string, KnownClass > mapping;mapping.insert(std::make_pair("somename", KnownClass(parameters)));mapping["somename"].someMemberFunction();
However, the situations where this is the right solution are limited (usually some form of scripting). What problem are you trying to solve? There may well be a better solution.
Enigma
ok.. basically ive decided i have no idea what im doing with my classes..
i am trying to write a 3d editor program.. but i dont know how exactly to go about it.. so i thought id start with how exactly you create/handle new points/ edges/ faces etc for objects.
i read up on linked lists which succesfully put new data into a list and pointed to its location at runtime... but then it seems quite hard to access any of that information dynamically once its there.. maybe im just an idiot..
then i tryed to look at the Standard Templat Library.. but that just confused me..
ive been lead to the conclusion that i use vectors.. or vertexs or vertices.. (one of them) to do handle objects etc.. but when ive tryed to look into these, all i find is a ton of information on "use this code to do this" .. without actually telling me what it is im working with (whats a vectors? .. what are vertices) .. and so i just read what im shown and have no idea what it does.. at best i would only be able to copy/paste any of it into my program..
perhaps someone can point me onto the right trail for how to solve handling objects and their data in a 3d editor.. or perhaps lead me in the right direction on how to go about creating an editor program for 3d objects?
i am trying to write a 3d editor program.. but i dont know how exactly to go about it.. so i thought id start with how exactly you create/handle new points/ edges/ faces etc for objects.
i read up on linked lists which succesfully put new data into a list and pointed to its location at runtime... but then it seems quite hard to access any of that information dynamically once its there.. maybe im just an idiot..
then i tryed to look at the Standard Templat Library.. but that just confused me..
ive been lead to the conclusion that i use vectors.. or vertexs or vertices.. (one of them) to do handle objects etc.. but when ive tryed to look into these, all i find is a ton of information on "use this code to do this" .. without actually telling me what it is im working with (whats a vectors? .. what are vertices) .. and so i just read what im shown and have no idea what it does.. at best i would only be able to copy/paste any of it into my program..
perhaps someone can point me onto the right trail for how to solve handling objects and their data in a 3d editor.. or perhaps lead me in the right direction on how to go about creating an editor program for 3d objects?
ive just had a thought about the earlier naming question...
if i created an object of a class.. i cant use a character like..
NewClass [Character]()
but could i use a pointer?
Newclass [Pointer]()
where [Pointer] is a pointer that points at a character string?..
it basically is exactly the same thing and probably doesnt work but its a thought
if i created an object of a class.. i cant use a character like..
NewClass [Character]()
but could i use a pointer?
Newclass [Pointer]()
where [Pointer] is a pointer that points at a character string?..
it basically is exactly the same thing and probably doesnt work but its a thought
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement