Jump to content
  • Advertisement
Sign in to follow this  
Origanlmaxin

problems in class

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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..

Share this post


Link to post
Share on other sites
Advertisement
You require a ; after the class declaration.


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.

Share this post


Link to post
Share on other sites
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 :(

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!