Hello All,

I'm compiling my program, and i keep getting this error:

obj/Debug/fubar.o||In function `fubar::fubarl(int*, int*)':|
/home/miguel/Documents/pointersandref/fubar.cpp|7|multiple definition of `fubar::fubarl(int*, int*)'|
obj/Debug/fubar.o:/home/miguel/Documents/pointersandref/fubar.cpp|7|first defined here|
||=== Build finished: 2 errors, 0 warnings ===|

This is my complete source code

fubar.cpp

#include <string.h>
#include <stdio.h>
#include "fubar.h"



void fubar::fubarl(int *foo, int *bar)
 {
     int drawx = 0;
     int drawy = 0;
     static int timesrun = 0;
     while(drawx < *foo)
       {

           printf("*");
           drawx++;
           timesrun++;

           if (timesrun = *foo)
           {
             printf("\n");
             timesrun = 0;
           }
       }
 }

fubar.h

#ifndef FUBAR_H_INCLUDED
#define FUBAR_H_INCLUDED

class fubar
{
    public:
    void fubarl(int *foo, int *bar);

    private:
};


#endif // FUBAR_H_INCLUDED

main.cpp

#include <iostream>
#include <string>
#include "fubar.h"
#include <stdlib.h>
#include <ctype.h>


using namespace std;

int main()
{   /*** Starting Values ***/
    int x = 0;
    int y = 0;

    /*** Holds the values entered by the user ***/
    int valuex;
    int valuey;

    /*** Pointers to our values ***/
    int *Px = &x;
    int *Py = &y;

    cout << "Please enter value for width of a rectangle(Between 3 and 20):\n";
    cin >> valuex;

    if (valuex >= 3 && valuex <= 20)
      {
          /*** Just a place holder lololol ***/
          valuex = valuex;
      }
     else
      {
          cout << "Error, bad input!!!\n";
      }

    cout << "Please enter value for height of a rectangle(Between 5 and 50):\n";
    cin >> valuey;

     if (valuey >= 5 && valuey <= 50)
      {
          /*** Just a place holder lololol ***/
          valuey = valuey;
      }
     else
      {
          cout << "Error, bad input!!!\n";
      }


     fubar newbar;
     newbar.fubarl(Px, Py);

    return 0;
}

How do i fix this, and explain why this happens

The project is set up like this?

And you're sure that the code is #include-ing the header and not the source?

#include "fubar.h" // like this
#include "fubar.cpp" // not like this


That latter is a usual suspect for this type of error.

As posted in #1, the code builds fine for me. Running the code brings up other issues.

Attachments fubar.jpg 11.6 KB

The project is set up like this?
[attach]10466[/attach]
And you're sure that the code is #include-ing the header and not the source?

#include "fubar.h" // like this
#include "fubar.cpp" // not like this

That latter is a usual suspect for this type of error.

As posted in #1, the code builds fine for me. Running the code brings up other issues.

Yeah, I'm sure...and i know running it would have some probs, it's not done yet

This article has been dead for over six months. Start a new discussion instead.