Sign in to follow this  
Ultima79

dont know what's wrong

Recommended Posts

ok, so I have a function called isNum which is used by some of my classes and my main cpp so i decided to make it into a .h file so i did and i included it at the top of every file that uses isNum since it wont compile if i dont. the problem is it now says i have one or more multiply defined symbols for isNum. some one please help i am working with VC++ 6

Share this post


Link to post
Share on other sites
Use #ifndef/#define/#endif. #pragma once is compiler specific.

Like this:
// blah.h
#ifndef _BLAH_H_
#define _BLAH_H_

// code here

#endif



-RC

Edit: since you're using MSVC, #pragma once should work just fine. If #pragma once isn't working, something else is wrong, and we probably can't help you without more information.
Edit again: does the compiler complain, or does the linker? If it's the linker, then you need to make sure you have the declaration in the header file and the implementation somewhere else.

Share this post


Link to post
Share on other sites
that's what i have actually
here is what i've done in case it helps


//strops.h
#ifndef STROPS_H
#define STROPS_H

bool isNum(...)
{...}

#endif




//someclass.h
#ifndef SOMECLASS
#define SOMECLASS
class someClass
{
void doSomething();
};
#endif




//someclass.cpp
#include "someclass.h"
#include "strops.h"

void someClass::doSomething()
{
...
isNum(...)
...
}





//main.cpp
#include <iostream>
#include "strops.h"
using namespace std;

int main()
{
...
isNum(...)
...
return 0;
}


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this