C++ Question Solved

Hi all. I am new to the forums and have been working on a game application and have come across a somewhat annoying error i cannot seem to correct. This application is a port of another application just to add. Also just to add i am not a top level coder, i am very low level so im trying to do the best i can with what knowledge i do have.

I am trying to set a sound distortion code when using cheat codes are enabled. I figured it to be a simple if/else statement but every time i try to compile it spits out a error C2365: 'SetDistortion' : redefinition; previous definition was a 'data variable'

First in my main.cpp i had to add the function itself which is this:

1
2
3
4
5
6
7
  void SetDistortion() {
    Sound sound(emulator);
    if(SetDistortion)
        sound.SetGenie(true);
    else
        sound.SetGenie(false);
}


this compiles ok and fine. It's when i try to add the menu option for it that it starts giving me trouble. This is my function for the menu option itself:

1
2
3
4
5
6
7
8
if(GeneralOptionsSelected == 8) {
SetDistortion++;
if(SetDistortion > 1)
SetDistortion = 0;
if(SetDistortion == 1)								GeneralOptionsValueSettings[8] = "Enabled";					
else
GeneralOptionsValueSettings[8] = "Disabled";
return;


the other relevant files for this would be the place where the function itself is added in the original application though i dont think that is needed in this case. If someone does not minding maybe giving me a clue i would greatly appreciate it.

And yes, to confirm i am a newb at this and trying the best i can.

Edit** for some reason the code tag messed up and i cant fix it.

if(GeneralOptionsSelected == 8) {
SetDistortion++;
if(SetDistortion > 1)
SetDistortion = 0;
if(SetDistortion == 1)
GeneralOptionsValueSettings[8] = "Enabled";
else
GeneralOptionsValueSettings[8] = "Disabled";
return;
Last edited on
At the start, you define a function named SetDistortion
But within that function you're testing a variable named SetDistortion. Also later again using a variable named SetDistortion.

Either the function or the variable needs to have a different name.
Last edited on
sorry for my ignorance, i need to change the second part, correct? Would it help to include anything here? Also the second part is the menu.cpp code, would this be why the compiler is complaining as well? Thank you for your answer and time. :)
Well, it looks to me as though the variable SetDistortion is referenced about half a dozen times in the code you posted here. but the function void SetDistortion() is referred to just one single time. So why not change the name of the function?

Though in terms of choosing meaningful names, SetDistortion sounds like it would be the name of a function. So maybe it would be more appropriate to change the variable to have a more suitable name, such as distortionValue. But make sure whichever way you decide, be consistent and make the change everywhere throughout the entire code, possibly in multiple files.
solved **edited**





Last edited on
Sorry, I don't see any reference to SetDistortion anywhere in that last code you posted.

I just tried your advice and still get the same redef error.
At the same place in the code, or somewhere else?

Sounds like you either misunderstood or didn't correctly carry out the required changes.
Last edited on
lol that is because i thought i had to make new name and not use SetGenie which i thought would confuse the compiler. This code is in the original application that this port is based on, im trying to add the SetGenie function into my main.cpp so i can then draw the options to enable and disable the sound distortion option from the menu options. (the 2 code snippets from above i started with.

I tried to follow the way the other options were implemented. First you declare the function in main, then have the menu call on said option.

LOL i guess i am waaay off? :/
Last edited on
closed account (z1CpDjzh)
NES_DO_POKE? what is that? And why are you passing Hex and dec? I think you have when too low!

I would encourage you to look into these following:
http://www.cplusplus.com/doc/tutorial/variables/ - Variable types
http://www.cplusplus.com/doc/tutorial/other_data_types/ - Other data types
http://www.cplusplus.com/forum/beginner/44859/ - Enums
http://cplus.about.com/od/introductiontoprogramming/p/enumeration.htm - More On Enums(becasue come on you shouldn't be using Hex and Dec unless your programming for Microsoft... or making direct calls to the cpu(which you shouldn't))...
http://www.cplusplus.com/doc/tutorial/classes/ - Classes
http://en.wikipedia.org/wiki/C%2B%2B_classes - More On Classes

And a Dozen Namespaces:
http://www.cplusplus.com/doc/tutorial/namespaces/
http://www.cprogramming.com/tutorial/namespaces.html
http://stackoverflow.com/questions/41590/how-do-you-properly-use-namespaces-in-c
http://www.tutorialspoint.com/cplusplus/cpp_namespaces.htm

Followed by Modern C++(aka Templates):
http://www.codeproject.com/Articles/257589/An-Idiots-Guide-to-Cplusplus-Templates-Part
http://en.wikipedia.org/wiki/Template_(C%2B%2B)
http://www.tutorialspoint.com/cplusplus/cpp_templates.htm
http://msdn.microsoft.com/en-us/library/y097fkab.aspx
http://www.yolinux.com/TUTORIALS/Cpp-Templates.html

//|---------------------------------------------------------------------------------------------------|\\

Some Libraries You make use in game programming(I recomend you do.... expecialy if its a 3D game):

-Direct x
-OpenGl
-SFML
-QT
-WXWidgets
-FLTK
-CEGUI
-Boost
Last edited on
thanks for the reply. I never said i had high level coding experience. Ill look into all of these tuts.

all of this code comes from an open source application so i do not know what you are talking about when you say programming for microsoft lol. There is a reason why im here in the beginner forums, im simply just trying to add a menu option and having trouble with it. :)
Last edited on
closed account (z1CpDjzh)
i do not know what you are talking about when you say programming for microsoft lol

If you look at winapi you'll see that most of the code is in Hex, Dec and macros which are defiend to equal a Hec or Dec

There is a reason why im here in the beginner forums,

This is the beginners? I never check which forum i am on...
im simply just trying to add a menu option and having trouble with it. :)


QT, WXWidgets, FLTK and CEQUI ain't game libraries... there GUI libraries...
SFML has got Guis, Networking, audio, 2d rendering and system stuff like threading.
OpenGL is a 3D rendering libraries.
DirectX is a library giving you direct accesses to hardware and adio and 3d and 2d rendering but only works on Windows...

EDIT: Boost is what most of C11's new features come from...
Last edited on
no worries. Thank you for the list of tuts, i will spend some time looking through them. There's a lot i dont know as stated so i prob should not start looking through code with C++ code waaayy over my head. Im a newb, as stated. Ill start off nice and easy with something simple.
Last edited on
closed account (z1CpDjzh)
Oh, and if ya dont like reading thenewboston's got tons of tutorials:
https://www.youtube.com/watch?v=tvC1WCdV1XU
And don't use the sourcecode you got cuase its atleast 2000000 years old:)
Last edited on
thanks! I can do both actually and prefer to read and see it. Ill check this out!

haha thanks! lol. I tried to start out with something big, and yea it proved to be too much for me. The application is in fact, very old. lmao. :P
Last edited on
Topic archived. No new replies allowed.