2 libraries with the same class
May 14, 2009 at 10:26am UTC
Hi
I am performing some experiences in order to better understand how namespaces work.
Consider the following code:
equipaa.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#ifndef EQUIPAA_H
#define EQUIPAA_H
// ...
// ... coisas ...
// ...
class MinhaClasse{
public :
MinhaClasse() {x = 0;}
void setX(int novo_x) {x = novo_x;}
int getX() {return x;}
int dobro() {return 2 * x;}
private :
int x;
};
// ...
// ... e mais coisas coisas ...
// ...
#endif //EQUIPAA_H
equipab.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#ifndef EQUIPAB_H
#define EQUIPAB_H
// ...
// ... coisas ...
// ...
class MinhaClasse{
public :
MinhaClasse() {x = 0;}
void setX(int novo_x) {x = novo_x;}
int getX() {return x;}
int triplo() {return 3 * x;}
private :
int x;
};
// ...
// ... e mais coisas coisas ...
// ...
#endif //EQUIPAB_H
main.cpp
1 2 3 4 5 6 7 8
#include <iostream>
#include "equipab.h"
#include "equipab.h"
int main(){
MinhaClasse objecto;
objecto.setX(7);
objecto.triplo();
}
What is the reason for the compiler only consider an error when i try to use member-function dobro (from equipaa.h) instead of triplo ( from equipab.h )?
Thanks
Last edited on May 14, 2009 at 10:27am UTC
May 14, 2009 at 11:15am UTC
#include <iostream>
#include "equipab.h"
#include "equipab.h"
shouldn't that be equipaA.h ?
May 14, 2009 at 11:20am UTC
yeap ... so it was strange :))))))
God ... how i hate copy paste!
Thanks
Topic archived. No new replies allowed.