Question

In: Computer Science

Hi, I don’t know why I keep getting this error and I’ve spent a while on...

Hi, I don’t know why I keep getting this error and I’ve spent a while on it now. I am coding in C++.

Here is my .h

___

#ifndef CARD_H
#define CARD_H

#include <iostream>
#include <string>
using namespace std;

class Card 
{
    private: 
    
    int powerLevel;
    string element;
    
    public:
    
    Card();
    Card(string, int);
    string getElement();
    int getPowerLevel();
    void displayCard();
};

#endif

___

Here is my .cpp

___

#include <iostream>
#include "Card.h"
#include <string>
using namespace std;

Card::Card()
{
    element = "";
    powerLevel = 0;
}

Card::Card(string e, int a)
{
    element = e;
    powerLevel = a;
}

string Card::getElement()
{
    return element;
}

int Card::getPowerLevel()
{
    return powerLevel;
}

void Card::displayCard()
{
    cout << element << "-" << powerLevel << endl;
}

___

This is the error message

___

/tmp/ccOrFltm.o: In function `Card::Card()':
Card.cpp:(.text+0x0): multiple definition of `Card::Card()'
/tmp/ccRpEdKb.o:Card.cpp:(.text+0x0): first defined here
/tmp/ccOrFltm.o: In function `Card::Card()':
Card.cpp:(.text+0x0): multiple definition of `Card::Card()'
/tmp/ccRpEdKb.o:Card.cpp:(.text+0x0): first defined here
/tmp/ccOrFltm.o: In function `Card::Card(std::string, int)':
Card.cpp:(.text+0x64): multiple definition of `Card::Card(std::string, int)'
/tmp/ccRpEdKb.o:Card.cpp:(.text+0x64): first defined here
/tmp/ccOrFltm.o: In function `Card::Card(std::string, int)':
Card.cpp:(.text+0x64): multiple definition of `Card::Card(std::string, int)'
/tmp/ccRpEdKb.o:Card.cpp:(.text+0x64): first defined here
/tmp/ccOrFltm.o: In function `Card::getElement()':
Card.cpp:(.text+0xd0): multiple definition of `Card::getElement()'
/tmp/ccRpEdKb.o:Card.cpp:(.text+0xd0): first defined here
/tmp/ccOrFltm.o: In function `Card::getPowerLevel()':
Card.cpp:(.text+0xfe): multiple definition of `Card::getPowerLevel()'
/tmp/ccRpEdKb.o:Card.cpp:(.text+0xfe): first defined here
/tmp/ccOrFltm.o: In function `Card::displayCard()':
Card.cpp:(.text+0x10e): multiple definition of `Card::displayCard()'
/tmp/ccRpEdKb.o:Card.cpp:(.text+0x10e): first defined here
collect2: error: ld returned 1 exit status

___

Thank you for your time

Solutions

Expert Solution

main.cpp

#include <iostream>

#include "Card.h"

#include <string>

using namespace std;

Card::Card()

{

element = "";

powerLevel = 0;

}

Card::Card(string e, int a)

{

element = e;

powerLevel = a;

}

string Card::getElement()

{

return element;

}

int Card::getPowerLevel()

{

return powerLevel;

}

void Card::displayCard()

{

cout << element << "-" << powerLevel << endl;

}

int main(){

Card c("AC",10);

c.displayCard();

}

Card.h

#ifndef CARD_H

#define CARD_H

#include <iostream>

#include <string>

using namespace std;

class Card

{

private:

int powerLevel;

string element;

public:

Card();

Card(string, int);

string getElement();

int getPowerLevel();

void displayCard();

};

#endif

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

I don't know why I keep getting the following error: AttributeError: 'tuple' object has no attribute...
I don't know why I keep getting the following error: AttributeError: 'tuple' object has no attribute 'size' I am using python in Anaconda. import numpy as np def information_gain(x_array, y_array): parent_entropy = entropy(x_array) split_dict = split(y_array) for val in split_dict.values(): freq = val.size / x_array.size child_entropy = entropy([x_array[i] for i in val]) parent_entropy -= child_entropy* freq return parent_entropy x = np.array([0, 1, 0, 1, 0, 1]) y = np.array([0, 1, 0, 1, 1, 1]) print(round(information_gain(x, y), 4)) x = np.array([0,...
HI. I have been trying to run my code but I keep getting the following error....
HI. I have been trying to run my code but I keep getting the following error. I can't figure out what I'm doing wrong. I also tried to use else if to run the area of the other shapes but it gave me an error and I created the private method. Exception in thread "main" java.util.InputMismatchException at java.base/java.util.Scanner.throwFor(Scanner.java:939) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at project2.areacalculation.main(areacalculation.java:26) My code is below package project2; import java.util.Scanner; public class areacalculation { private static...
I do not know why I keep getting this question wrong, I triple checked my work!...
I do not know why I keep getting this question wrong, I triple checked my work! A distribution of values is normal with a mean of 80 and a standard deviation of 18. From this distribution, you are drawing samples of size 23. Find the interval containing the middle-most 40% of sample means: ANSWER HERE Enter your answer using interval notation. In this context, either inclusive or exclusive intervals would be acceptable. Your numbers should be accurate to 1 decimal...
Syntax error in C. I am not familiar with C at all and I keep getting...
Syntax error in C. I am not familiar with C at all and I keep getting this one error "c error expected identifier or '(' before } token" Please show me where I made the error. The error is said to be on the very last line, so the very last bracket #include #include #include #include   int main(int argc, char*_argv[]) {     int input;     if (argc < 2)     {         input = promptUserInput();     }     else     {         input = (int)strtol(_argv[1],NULL, 10);     }     printResult(input);...
My code works in eclipse, but not in Zybooks. I keep getting this error. Exception in...
My code works in eclipse, but not in Zybooks. I keep getting this error. Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanner.throwFor(Scanner.java:937) at java.base/java.util.Scanner.next(Scanner.java:1478) at Main.main(Main.java:34) Your output Welcome to the food festival! Would you like to place an order? Expected output This test case should produce no output in java import java.util.Scanner; public class Main {    public static void display(String menu[])    {        for(int i=0; i<menu.length; i++)        {            System.out.println (i + " - " + menu[i]);...
I keep getting the same error Error Code: 1822. Failed to add the foreign key constraint....
I keep getting the same error Error Code: 1822. Failed to add the foreign key constraint. Missing index for constraint 'test_ibfk_5' in the referenced table 'appointment', can you please tell me what is wrong with my code: -- Table III: Appointment = (site_name [fk7], date, time) -- fk7: site_name -> Site.site_name DROP TABLE IF EXISTS appointment; CREATE TABLE appointment (    appt_site VARCHAR(100) NOT NULL, appt_date DATE NOT NULL, appt_time TIME NOT NULL, PRIMARY KEY (appt_date, appt_time), FOREIGN KEY (appt_site)...
Why do I keep getting the error "More columns than column names" when trying to import...
Why do I keep getting the error "More columns than column names" when trying to import the following data into R Studio?: PRICE   YEARSOLD   MILES   COLOR   TITLESTATUS   TRANSMISSION   4500   11   170000   SILVER   CLEAN   MANUAL           34590   1   2000   SILVER   CLEAN   AUTOMATIC   4500   14   203000   SILVER   CLEAN   AUTOMATIC   11990   6   53337   GRAY   CLEAN   AUTOMATIC   10490   8   36543   RED   CLEAN   AUTOMATIC   2800   19   208000   SILVER   CLEAN   MANUAL       1200   19   244000   SILVER   CLEAN   AUTOMATIC   2500   19   208000   BROWN   CLEAN   AUTOMATIC   2000  ...
I keep getting an error that I cannot figure out with the below VS2019 windows forms...
I keep getting an error that I cannot figure out with the below VS2019 windows forms .net framework windows forms error CS0029 C# Cannot implicitly convert type 'bool' to 'string' It appears to be this that is causing the issue string id; while (id = sr.ReadLine() != null) using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; namespace Dropbox13 { public partial class SearchForm : Form { private List allStudent = new List(); public SearchForm() { InitializeComponent(); } private void SearchForm_Load(object...
I am making a html game with phaser 3 I keep getting an error at line...
I am making a html game with phaser 3 I keep getting an error at line 53 of this code (expected ;) I have marked the line that needs to be fixed. whenever I add ; my whole code crashes const { Phaser } = require("./phaser.min"); var game; var gameOptions = {     tileSize: 200,     tileSpacing: 20,     boardSize: {     rows: 4,     cols: 4     }    }    window.onload = function() {     var gameConfig = {         width: gameOptions.boardSize.cols * (gameOptions.tileSize +             gameOptions.tileSpacing) + gameOptions.tileSpacing,...
Why am I getting this error using 000webhost , but I do not get this error...
Why am I getting this error using 000webhost , but I do not get this error running XAMPP? Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd2/006/14881006/public_html/test/index.php:1) in /storage/ssd2/006/14881006/public_html/test/index.php on line 8 Code is below. ******************************************************************************************************************** <!DOCTYPE html> <?php    //Determine if the submit button has been clicked to set the cookie name and value    if (isset($_POST['name'])){            $cookie_name = $_POST['name'];            $cookie_value = $_POST['value'];            setcookie($cookie_name, $cookie_value,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT