Kuribo64
Views: 19,856,696 Home | Forums | Uploader | Wiki | Object databases | IRC
Rules/FAQ | Memberlist | Calendar | Stats | Online users | Last posts | Search
03-29-24 01:09 PM
Guest:

0 users reading Error C2084 visual C++ | 1 bot

Main - Computers and technology - Error C2084 visual C++ Hide post layouts | New reply


FinalShroom81
Posted on 01-25-17 11:24 PM Link | #81091
This may or may not be the right place for this but I have a problem that I need to get fixed. So I was writing a program in C++ when I came across an annoying error. The error is C2084. You can click here for more info about the error. I have looked through many stackoverflow posts to find an answer but to no success. But I have some clues. First I know that this error is a runtime error and has nothing to do with syntax. Second, My program has two classes and both include many header files which may be the source of my problem. I have a whole video on this error. click here to watch it. For some reason, I feel like this error is specific to the visual C++ compiler and if I were to try it in another compiler(e.g. GNU GCC or G++) then it would compile and run just fine. I have yet to try it but I will if I don't find a solution soon.

So here is the code were the error is occuring:(Terminal.cpp)
#include "stdafx.h"
#include "Terminal.h"
#include <iostream>
#include <string>
#include <conio.h>
#include "StringReverse.h"


Terminal::Terminal()
{
}

Terminal::~Terminal()
{
}

void Terminal::Setup()
{
system("title Cooper City High Showcase Program by Javier Martinez 2017");
//.c_str() is for converting the std::string to const char*
system(_lightGreen.c_str());
}

void Terminal::RenderMainMenu()
{
std::string input;
std::cout << "\tMAIN MENU\t" << "Type number to select option:\n\n";
std::cout << "1. Preferences\n\n";
std::cout << "2. Word Reversal\n\n";
std::cout << "3. Description\n\n";
std::cout << "4. Exit Program\n\n";
std::cout << "________________________\n\n";
std::cin >> input;
Terminal::NavigateBasedOnSelection(input);
}

void Terminal::NavigateBasedOnSelection(std::string in)
{
if (in == "1")
{
Terminal::RenderPreferencesMenu();
}
else if (in == "2")
{
Terminal::NotImplementedNotification();
}
else if (in == "3")
{
Terminal::DisplayDescription();
}
else if (in == "4")
{
system("EXIT");
}
else
{
Terminal::ResetBackToMainMenu();
}
}

void Terminal::ResetBackToMainMenu()
{
std::cout << "Invalid Selection, Please try again.";
_getch();
system("cls");
Terminal::RenderMainMenu();
}

void Terminal::RenderPreferencesMenu()
{
system("cls");
std::string input;
std::cout << "\tPREFERENCES MENU\t" << "Change the font color:\n";
std::cout << "1. Gray\n\n";
std::cout << "2. Blue\n\n";
std::cout << "3. Light Green\n\n";
std::cout << "4. Aqua\n\n";
std::cout << "5. Light Aqua\n\n";
std::cout << "6. Light Red\n\n";
std::cout << "7. Light Purple\n\n";
std::cout << "8. Yellow\n\n";
std::cout << "9. Return to Main Menu\n";
std::cout << "____________________________\n\n";
std::cin >> input;
Terminal::ColorSwitchBasedOnSelection(input);
}

void Terminal::ColorSwitchBasedOnSelection(std::string in)
{
if (in == "1")
{
system(_gray.c_str());
Terminal::BasicReset();
}
else if (in == "2")
{
system(_blue.c_str());
Terminal::BasicReset();
}
else if (in == "3")
{
system(_lightGreen.c_str());
Terminal::BasicReset();
}
else if (in == "4")
{
system(_aqua.c_str());
Terminal::BasicReset();
}
else if (in == "5")
{
system(_lightAqua.c_str());
Terminal::BasicReset();
}
else if (in == "6")
{
system(_lightRed.c_str());
Terminal::BasicReset();
}
else if (in == "7")
{
system(_lightPurple.c_str());
Terminal::BasicReset();
}
else if (in == "8")
{
system(_yellow.c_str());
Terminal::BasicReset();
}
else if (in == "9")
{
/*Not a color switch but brings the user back
to the main menu of the program*/
Terminal::BasicReset();
}
else
{
std::cout << "Invalid Selection, please try again.";
_getch();
RenderPreferencesMenu();
}
}

void Terminal::BasicReset()
{
system("cls");
Terminal::RenderMainMenu();
}

void Terminal::NotImplementedNotification()
{
system("cls");
std::cout << "This feature has not yet been Implemented.";
_getch();
BasicReset();
}

void Terminal::DisplayDescription()
{
system("cls");
std::cout << _description << "\n\n1/6/2017 - 1/14/2017";
_getch();
Terminal::BasicReset();
}

void Terminal::RenderWordReversal()
{
std::string input;
std::cout << "\tWORD REVERSAL\t" << "Type in a word and press return:\n\n";
std::cout << "Type anything then press enter:\t";
std::cin >> input;
std::string reverInput = StringReverse::ReverseWord(input);
std::cout << "\n\nThe word in reverse:\t" << reverInput << "\n\n";
_getch();
Terminal::BasicReset();
}
If you all need anymore info then I will be happy to give it to you. Thank you all in advance, I truly appreciate every response I can get.

Yami
Posted on 01-26-17 06:11 AM Link | #81100
Funny how you can compile something using G++, while having "#include "stdafx.h"" or "system("cls");" in your code, which are all Visual C++-specific stuff...

But any errors you get would be more helpful to know, than some incomplete code that we could get from the video you linked to as well.

Also, never use "system" in C++.
http://www.cplusplus.com/forum/articles/11153/

Arisotura
Posted on 01-26-17 01:18 PM Link | #81101
where did he state that he compiled it under G++?

____________________
NSMBHD - Kafuka - Jul
melonDS the most fruity DS emulator there is

zafkflzdasd

poudink
Posted on 01-26-17 05:47 PM Link | #81104
He said he used visual C++.

____________________
Nothing to say, so jadnjkfmnjamnfjkldnajfnjkanfjdksan jsdnvj m.

Yami
Posted on 01-26-17 07:22 PM Link | #81106
Posted by StapleButter
where did he state that he compiled it under G++?

Posted by FinalShroom81
and if I were to try it in another compiler(e.g. GNU GCC or G++) then it would compile and run just fine.


Arisotura
Posted on 01-26-17 08:22 PM Link | #81108
Posted by FinalShroom81
I feel like this error is specific to the visual C++ compiler and if I were to try it in another compiler(e.g. GNU GCC or G++) then it would compile and run just fine.

which says he hasn't actually done it.



regardless, having the full error message and line it's occuring on, could help us there.

having a blob of code and an error number alone isn't very helpful.

____________________
NSMBHD - Kafuka - Jul
melonDS the most fruity DS emulator there is

zafkflzdasd

FinalShroom81
Posted on 01-26-17 09:14 PM Link | #81110
Does anyone know of any sites I can post my full code on? I want to do this so that you can get the full context and help me figure out the source of this error. Also, I have not tried anything with GNU GCC or G++ yet. I said that I feel like it would work. As for using "system()" in c++ I have my reasoning for using it. First, I don't know of any other way to execute windows commands right now. Second, This is a windows console application and I won't be running this program on any other operating system. I will post more code here on this post for the time being.

Arisotura
Posted on 01-26-17 09:18 PM Link | #81111
having the full error message would be helpful

you can zip the code and put it on our uploader

____________________
NSMBHD - Kafuka - Jul
melonDS the most fruity DS emulator there is

zafkflzdasd

FinalShroom81
Posted on 01-26-17 09:19 PM Link | #81112
Here is all of my Terminal.h code
#pragma once
#include <iostream>
#include <string>
#include "StringReverse.h"

class Terminal
{

public:
Terminal() {}
~Terminal();
static void Setup();
static void RenderMainMenu();
static void NavigateBasedOnSelection(std::string in);
static void ResetBackToMainMenu();
static void RenderPreferencesMenu();
static void ColorSwitchBasedOnSelection(std::string in);
static void BasicReset();
static void RenderWordReversal();

private:
static void NotImplementedNotification();
static void DisplayDescription();
//Values to be passed into the system();
static std::string _gray;
static std::string _blue;
static std::string _lightGreen;
static std::string _aqua;
static std::string _lightAqua;
static std::string _lightRed;
static std::string _lightPurple;
static std::string _yellow;
//Full Description variable:
static std::string _description;
};
//All static members must be initialized outside of the class:
std::string Terminal::_gray = "COLOR 8";
std::string Terminal::_blue = "COLOR 1";
std::string Terminal::_lightGreen = "COLOR A";
std::string Terminal::_aqua = "COLOR 3";
std::string Terminal::_lightAqua = "COLOR B";
std::string Terminal::_lightRed = "COLOR C";
std::string Terminal::_lightPurple = "COLOR D";
std::string Terminal::_yellow = "COLOR 6";
The error seems to be caused by line 10 of this file.

Arisotura
Posted on 01-26-17 09:22 PM Link | #81113
Terminal() {}
that's why. you're trying to declare a second body for that function.

____________________
NSMBHD - Kafuka - Jul
melonDS the most fruity DS emulator there is

zafkflzdasd

FinalShroom81
Posted on 01-26-17 09:36 PM Link | #81114
Posted by StapleButter
Terminal() {}
that's why. you're trying to declare a second body for that function.

If I remove that then a huge amount of errors will appear, according to the last time I tried but I will attempt it again.

Arisotura
Posted on 01-26-17 09:47 PM Link | #81115
Terminal();
shouldn't it be like that?

____________________
NSMBHD - Kafuka - Jul
melonDS the most fruity DS emulator there is

zafkflzdasd

FinalShroom81
Posted on 01-26-17 11:12 PM Link | #81116
Posted by StapleButter
Terminal();
shouldn't it be like that?

So I tried your solution but It failed. I got 19 errors saying this:

Error is LNK2005
Severity Code Description Project File Line Suppression State
Error LNK2005 "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > Terminal::_lightGreen" (?_lightGreen@Terminal@@0V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in CCHS_ShowcaseProgram.obj CCHS_ShowcaseProgram C:\Users\NIKE\Desktop\code projects\CCHS_ShowcaseProgram\CCHS_ShowcaseProgram\StringReverse.obj 1

Arisotura
Posted on 01-26-17 11:39 PM Link | #81117
oh lord


try moving the "std::string Terminal::_gray = "COLOR 8";" lines to the .cpp file maybe

____________________
NSMBHD - Kafuka - Jul
melonDS the most fruity DS emulator there is

zafkflzdasd

FinalShroom81
Posted on 01-26-17 11:44 PM Link | #81118
Posted by StapleButter
oh lord


try moving the "std::string Terminal::_gray = "COLOR 8";" lines to the .cpp file maybe

I will try. Thank you so much for all of the help you are giving me

Arisotura
Posted on 01-26-17 11:53 PM Link | #81119
well, I'm trying. I hate compiler errors that are a pile of nonsense, especially when it's something dumb like forgetting a ;.

____________________
NSMBHD - Kafuka - Jul
melonDS the most fruity DS emulator there is

zafkflzdasd

FinalShroom81
Posted on 01-26-17 11:57 PM Link | #81121
Posted by StapleButter
well, I'm trying. I hate compiler errors that are a pile of nonsense, especially when it's something dumb like forgetting a ;.

I know the error has nothing to do with syntax so don't worry about that. The error has something to do with the Linker.

FinalShroom81
Posted on 01-30-17 09:50 PM Link | #81163
Posted by StapleButter
oh lord


try moving the "std::string Terminal::_gray = "COLOR 8";" lines to the .cpp file maybe

Hello StapleButter. I would like notify you with some good news. your solution worked and my program is up and running. Thank you so much for all of your help. I don't know of any way I can repay you. If you need help with something feel free to message me about it. :)

Arisotura
Posted on 01-30-17 10:02 PM Link | #81164
oh, you're welcome :P glad it works!

____________________
NSMBHD - Kafuka - Jul
melonDS the most fruity DS emulator there is

zafkflzdasd


Main - Computers and technology - Error C2084 visual C++ Hide post layouts | New reply

Page rendered in 0.059 seconds. (2048KB of memory used)
MySQL - queries: 29, rows: 233/233, time: 0.009 seconds.
[powered by Acmlm] Acmlmboard 2.064 (2018-07-20)
© 2005-2008 Acmlm, Xkeeper, blackhole89 et al.