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

Confusion

Post by THe Floating Brain »

Well lately I have been developing a game engine that contains the following class.

Code: Select all

class MiscFucntions
{
public:
	class InstanceCreate
	{
		public:
			typedef class Instance;
			typedef std::vetcor<Instance> Vetcor;
			template<class Instance>
			Instance CreateInstance(Instance A)
			{
				
				return A;
			}
			
	};
	class InstanceDestroy
	{
	public:
		//Not done!!//
		typedef class InstanceToDestroy;
		template<class InstanceToDestroy>
		InstanceToDestroy DestroyInstance(InstanceToDestroy ClassInstanceToDestroy)
		{
		}
	};

};
The way I have used this function "CreateInstance" is the following...

Code: Select all

//"fedship" is a class an "fedships" is a std::vetcor.//
		MiscFucntions::InstanceCreate V;
		fedship A;
		fedship B;
		*fwrexp = 300;
		*fwreyp = 300;
		fedships.push_back(V.CreateInstance(A));
		*fwreyp += 100;
		fedships[0] = B.SetPosition(*fwrexp, *fwreyp, fedships[0]);
		fedships.push_back(V.CreateInstance(A));
//etc...///
If I create five "fedships" in the std::vector "fedships" this is my console output
OMG.PNG
OMG.PNG (35.59 KiB) Viewed 2188 times
(Hoping the messages are relatively understandable).
I have noticed every frame that "fedships" subtracts a "fedship" (35 on the first frame :/) but yet all instances of "fedship" remain functional and :/ Also I cannot modify "fedships" for example the "SetPosition" function that is up there does not work :-( .
I am getting the feeling that std::vectors are not the way to go for this and I was wondering if there was another type of container or something that would be like a std::vector but with no memory heap allocation? Also I was wondering (although not expecting) if anyone can understand the reason for this behavior in my program?
P.s I know I sometimes have a hard time getting my point across if anyone needs any clarification I will do my best to provide it.
P.s.s Sorry for making 2 posts in 1 week :-(
P.s.s.s Yes I know this is probably the most n00by pice of code your eyes have ever had to bear whitness to.
EDIT:
Also noticed after this post that another indicator in my log says that "fedships" is of the correct size 5.
Last edited by THe Floating Brain on Fri Jan 21, 2011 9:16 pm, edited 3 times in total.
"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
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Confusion

Post by dandymcgee »

I think you should seriously consider chilling out and letting your brain catch up to your ambition, at least until you read up on some fundamentals of C++.

First of all, you're not ready for templates. Perhaps not even pointers or classes. Check out the tutorials on this page from "Compound Data Types" forward:
http://www.cplusplus.com/doc/tutorial/

When you feel as though you thoroughly understand the concepts laid out there, then come back to play with the code you've posted.

Hope I did well not making this sound too harsh. 8-)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
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 »

It is not that I do not understand them I fully understand them (well maybe not stl stuff) I have been programming/learning for almost 3 years now(last year of that being programming only). Most of the problem lies in the fact that my code is going from spaghetti code to engine and I am getting a lot of crap like this. Sooo I was kinda thinking if someone could help me with this maybe I could use there help to figure out future problems, plus it is kinda late were I am so I probably seem kinda stupid right now XD
----EDIT----
I will admit I proabably took ten minutes then was like "OMG I JUST WANT TO MOVE ON!!" and made this post.
"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
xiphirx
Chaos Rift Junior
Chaos Rift Junior
Posts: 324
Joined: Mon Mar 22, 2010 3:15 pm
Current Project: ******** (Unkown for the time being)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Re: Confusion

Post by xiphirx »

Code: Select all

         typedef std::vetcor<Instance> Vetcor;
Stopped reading there.
StarCraft II Zerg Strategy, open to all levels of players!

Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of :)
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 »

Oh wooops ment to get rid of that (not being used).
"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
adikid89
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 94
Joined: Tue Apr 27, 2010 6:59 am
Current Project: small tiny-mini projects
Favorite Gaming Platforms: PC I guess...
Programming Language of Choice: c++

Re: Confusion

Post by adikid89 »

Code: Select all

         typedef class Instance;   //wuuuuuut.......
         typedef std::vetcor<Instance> Vetcor;
         template<class Instance>   
weird?
My first game C++/SDL Yoshi Combat! = http://www.youtube.com/watch?v=HQ9mMBEWSZg
==============================================================
Image
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 »

adikid89 wrote:

Code: Select all

 typedef class Instance; //wuuuuuut.......
typedef std::vetcor<Instance> Vetcor;
template<class Instance> 
weird?
The second line is suppost to be removed.
"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 »

adikid89 wrote:

Code: Select all

         typedef class Instance;   //wuuuuuut.......
         typedef std::vetcor<Instance> Vetcor;
         template<class Instance>   
weird?
+1

Does that honestly compile? :shock2:
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 »

VC++ 2008 FTW!! Howcome everyone keeps focusing on this one line?
"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:VC++ 2008 FTW!! Howcome everyone keeps focusing on this one line?
I'm not looking at the second line its the first:-

Code: Select all

typedef class Instance; // <---- This one
typedef std::vetcor<Instance> Vetcor;
template<class Instance>   
typedef defines types, but a class isn't a type so you should get a error/warning.

Why would you you want this anyway? and whats wrong with

Code: Select all

#define Instance class
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 »

As dipicted in most tutorials that is valid C++ syntex, reason being I dont use

Code: Select all

#define Instance class
is this is simply the way I thought of doing that.
"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 »

... It still begs the question... WHY?
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
xiphirx
Chaos Rift Junior
Chaos Rift Junior
Posts: 324
Joined: Mon Mar 22, 2010 3:15 pm
Current Project: ******** (Unkown for the time being)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Re: Confusion

Post by xiphirx »

Ginto8 wrote:... It still begs the question... WHY?
To make him write less... er
StarCraft II Zerg Strategy, open to all levels of players!

Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of :)
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 »

Beacuse I did not want to deal with pre-prosser commands
"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
xiphirx
Chaos Rift Junior
Chaos Rift Junior
Posts: 324
Joined: Mon Mar 22, 2010 3:15 pm
Current Project: ******** (Unkown for the time being)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Re: Confusion

Post by xiphirx »

THe Floating Brain wrote:Beacuse I did not want to deal with pre-prosser commands
wat

are you a troll by chance?
StarCraft II Zerg Strategy, open to all levels of players!

Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of :)
Post Reply