Confusion

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: Confusion

Post by GroundUpEngine »

xiphirx wrote:

Code: Select all

         typedef std::vetcor<Instance> Vetcor;
Stopped reading there.
I concur :lol:
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Confusion

Post by N64vSNES »

THe Floating Brain wrote:Beacuse I did not want to deal with pre-prosser commands
You're really not understanding what people are asking are you?

Why would you want your code to look this this?

Code: Select all

Instance MyClass {

};
I fail to see the point in this. Also testing that line in VC++ 2008 it gives a warning.
D-e-X
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 39
Joined: Tue Dec 28, 2010 6:49 pm

Re: Confusion

Post by D-e-X »

I'm giving you a tip, man, just please... go through the fundamentals of C++ one more time, and this time, make sure you UNDERSTAND every concept and how to use it... or at least, please brush up on it.
I remember when I used to be into nostalgia.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Confusion

Post by Ginto8 »

D-e-X wrote:I'm giving you a tip, man, just please... go through the fundamentals of C++ one more time, and this time, make sure you UNDERSTAND every concept and how to use it... or at least, please brush up on it.
also, please understand that a specific syntax is used by the language for a very specific reason. Using preprocessor to CHANGE the syntax of the language is like trying to chop off someone's legs just because you like midgets better.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
D-e-X
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 39
Joined: Tue Dec 28, 2010 6:49 pm

Re: Confusion

Post by D-e-X »

Ginto8 wrote:
D-e-X wrote:I'm giving you a tip, man, just please... go through the fundamentals of C++ one more time, and this time, make sure you UNDERSTAND every concept and how to use it... or at least, please brush up on it.
also, please understand that a specific syntax is used by the language for a very specific reason. Using preprocessor to CHANGE the syntax of the language is like trying to chop off someone's legs just because you like midgets better.
^ this is true.
I remember when I used to be into nostalgia.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Confusion

Post by N64vSNES »

Ginto8 wrote:
D-e-X wrote:I'm giving you a tip, man, just please... go through the fundamentals of C++ one more time, and this time, make sure you UNDERSTAND every concept and how to use it... or at least, please brush up on it.
also, please understand that a specific syntax is used by the language for a very specific reason. Using preprocessor to CHANGE the syntax of the language is like trying to chop off someone's legs just because you like midgets better.
What a genius way of putting it....
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Confusion

Post by Ginto8 »

N64vSNES wrote:
Ginto8 wrote:
D-e-X wrote:I'm giving you a tip, man, just please... go through the fundamentals of C++ one more time, and this time, make sure you UNDERSTAND every concept and how to use it... or at least, please brush up on it.
also, please understand that a specific syntax is used by the language for a very specific reason. Using preprocessor to CHANGE the syntax of the language is like trying to chop off someone's legs just because you like midgets better.
What a genius way of putting it....
crazy analogies are my specialty ;)
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Confusion

Post by avansc »

Not to pick any sides, or say one way is better than the other, but you do sometimes see typedefs going on.

for instance, with returning function pointers it is a lot easier to do.

Code: Select all

typedef float(*pFunc)(args, ...);
pFunc foo(args, ...);
also, if you have ever dabbled in C, you would have probably had to typedef some of your structs. (well not had to, but i dont wanna write struct out every time i have to declare one.)

Code: Select all

typedef struct
{
    bla bla bla
} bla, *pBla;

and then onto C++, you sometimes do see this aswell, usually to make things easier on the programmer, afterall, is that not what programming is about?
http://en.wikipedia.org/wiki/Typedef
"

Code: Select all

std::vector<std::pair<std::string, int> > values;
for (std::vector<std::pair<std::string, int> >::const_iterator i = values.begin(); i != values.end(); ++i)
{
   std::pair<std::string, int> const & t = *i;
   // do something
}

Code: Select all

typedef std::pair<std::string, int> value_t;
typedef std::vector<value_t> values_t;
 
values_t values;
for (values_t::const_iterator i = values.begin(); i != values.end(); ++i)
{
   value_t const & t = *i;
   // do something
}
"
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Confusion

Post by Ginto8 »

typedef'ing is fine. It does not actually change the syntax of the language. However, renaming the KEYWORD "class" to "Instance" is not only unnecessary, clumsy, and downright bad programming, it also misleads people as to what a program actually does. A class is not an instance, and therefore should not be called one. Renaming "class" to "type" would be just as unnecessary and clumsy, but it would be less bad because it does not mislead whoever reads the code.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Confusion

Post by N64vSNES »

What he said^ ;)

Although I've used it for function pointers.
User avatar
THe Floating Brain
Chaos Rift Junior
Chaos Rift Junior
Posts: 284
Joined: Tue Dec 28, 2010 7:22 pm
Current Project: RTS possible Third Person shooter engine.
Favorite Gaming Platforms: PC, Wii, Xbox 360, GAME CUBE!!!!!!!!!!!!!!!!!!!!!!
Programming Language of Choice: C/C++, Python 3, C#
Location: U.S

Re: Confusion

Post by THe Floating Brain »

Well lots of talk on this while I was gone XD. Reason being for that is just to make it easier to take any instance of any class for a function argument (the implimentation for this is show in the topic post).
A class is not an instance, and therefore should not be called one.
I am well aware that a class is not a instance. The purpose of this function is to feed a instance of a class into a element of a std::vector or a array.
I'm giving you a tip, man, just please... go through the fundamentals of C++ one more time, and this time, make sure you UNDERSTAND every concept and how to use it... or at least, please brush up on it.
I fully understand the fundamentals of C++, maybe im a little messy in my work but I do understand C++.
usually to make things easier on the programmer, after all, is that not what programming is about?
Thank you avansc :-) The whole reason for this typedef is simply to make things easier!
GroundUpEngine wrote:
xiphirx wrote:

Code: Select all

 typedef std::vector<Instance> Vector;
Stopped reading there.
I concur :lol:
I already explained that I was using that to test stuff (although agreed it is bad practices) and I forgot to take it out.
xiphirx wrote:
THe Floating Brain wrote:Because I did not want to deal with pre-prosser commands
wat

are you a troll by chance?
How is that trolling?!?!?!
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself

ImageImage
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Confusion

Post by N64vSNES »

THe Floating Brain wrote:Well lots of talk on this while I was gone XD. Reason being for that is just to make it easier to take any instance of any class for a function argument (the implimentation for this is show in the topic post).
A class is not an instance, and therefore should not be called one.
I am well aware that a class is not a instance. The purpose of this function is to feed a instance of a class into a element of a std::vector or a array.
I'm giving you a tip, man, just please... go through the fundamentals of C++ one more time, and this time, make sure you UNDERSTAND every concept and how to use it... or at least, please brush up on it.
I fully understand the fundamentals of C++, maybe im a little messy in my work but I do understand C++.
usually to make things easier on the programmer, after all, is that not what programming is about?
Thank you avansc :-) The whole reason for this typedef is simply to make things easier!
GroundUpEngine wrote:
xiphirx wrote:

Code: Select all

 typedef std::vector<Instance> Vector;
Stopped reading there.
I concur :lol:
I already explained that I was using that to test stuff (although agreed it is bad practices) and I forgot to take it out.
xiphirx wrote:
THe Floating Brain wrote:Because I did not want to deal with pre-prosser commands
wat

are you a troll by chance?
How is that trolling?!?!?!
Would you please listen to what people are saying? typedef's are there to make things easier but they're not to be abused.

To typedef a struct is perfectly understandable since it will make code easier to read.
To typedef a function pointer is fine they look like shit anyway.
To typedef the class keyword is just retarded.

Like I said before visual studio dosen't even approve of this:

Code: Select all

warning C4091: 'typedef ' : ignored on left of 'Instance' when no variable is declared
Level 3 warnings^
You shouldn't ignore your warnings. Remove this and you're one step closer to your program working properly.
User avatar
THe Floating Brain
Chaos Rift Junior
Chaos Rift Junior
Posts: 284
Joined: Tue Dec 28, 2010 7:22 pm
Current Project: RTS possible Third Person shooter engine.
Favorite Gaming Platforms: PC, Wii, Xbox 360, GAME CUBE!!!!!!!!!!!!!!!!!!!!!!
Programming Language of Choice: C/C++, Python 3, C#
Location: U.S

Re: Confusion

Post by THe Floating Brain »

Very well then I will admit I do not exactly read up on format :oops: . Is a template okey instead of a typedef? Please dont yell at me :cry: .
P.s
To typedef the class keyword is just retarded.
Correct term is "Developmentaly Challanged" use of the word "retared" is outdated. (Have worked with poeple whom actualy have that realy sad :-( ).
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself

ImageImage
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Confusion

Post by Ginto8 »

The term is mental retardation. They're very stupid because either their brain is not fully developed or it just doesn't function correctly, but being "Developmentally Challenged" is ambiguous and definitely not descriptive enough. Please cut the PC bullshit here. ;)
Also, the "any instance of any class" thing makes me think you're looking for polymorphism, or simply templating. Which it is, I can't tell, because your description is too vague and your understanding is obviously too little.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
THe Floating Brain
Chaos Rift Junior
Chaos Rift Junior
Posts: 284
Joined: Tue Dec 28, 2010 7:22 pm
Current Project: RTS possible Third Person shooter engine.
Favorite Gaming Platforms: PC, Wii, Xbox 360, GAME CUBE!!!!!!!!!!!!!!!!!!!!!!
Programming Language of Choice: C/C++, Python 3, C#
Location: U.S

Re: Confusion

Post by THe Floating Brain »

Ginto8 wrote:The term is mental retardation. They're very stupid because either their brain is not fully developed or it just doesn't function correctly, but being "Developmentally Challenged" is ambiguous and definitely not descriptive enough. Please cut the PC bullshit here. ;)
Also, the "any instance of any class" thing makes me think you're looking for polymorphism, or simply templating. Which it is, I can't tell, because your description is too vague and your understanding is obviously too little.
It is the updated term (http://www.wordwebonline.com/en/DEVELOP ... CHALLENGED)(basicly a more polite version of the term) I do not want to start a fight so that is all I will say. Anyway moving onto softwere development.
The best example I can think of is game maker 8's "instance_create(x, y, whatever)" function somehow you just type the name of the class you want to make and where yo uwant it and BAM it magicly appers on the screen what I have tried to do here is replicate it. Buuuuut the only way I have been able to figure out how to do this without memory heap allocation is by creating a instance(we will just call the instance of the class pizza for the purposes of explination) of what I want to make. Then inputing pizza into my CreatInstance function argument and having that function fill a element of a std::vector or array with a copy of the original instance(pizza)
Ex.

Code: Select all

//pseudo code.//
template<class Instance>
Instance CreateInstance(Instance A)
{
    return A;
}
class food
{
public:
};
food pizza;
std::vector<food> B;
B.push_back(CreateInstance(pizza));
I tried doing this through means of polymorphisim and a factory but I could not get it to work without memory heap allocation :-(
P.s What are you refering to when you say my understanding is to little the particlar topic, C++, format?(Again I do say I do understand C++)
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself

ImageImage
Post Reply