LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C++ simple problem, doesn't recognize some std::cout (https://www.linuxquestions.org/questions/programming-9/c-simple-problem-doesnt-recognize-some-std-cout-564645/)

itz2000 06-26-2007 02:22 PM

C++ simple problem, doesn't recognize some std::cout
 
I don't know what's goin' on, it happens to me in every project but I don't know what I'm doing wrong! looked for solution in the code for over a hour.


here's some code :
Code:

<b>main.cpp</b>

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <iostream>
#include <cstdlib>

// int main(int argc, char *argv[])
int main()
{
       
        std::cout << "Hello, world!" << std::endl;
        int nCounter=5;
        CImage myClass(nCounter)
        return 0;
//        return EXIT_SUCCESS;
}


<b> cimage.cpp</b>

#include "cimage.h"


CImage::CImage(int nCount)
{
        int m_nCount=nCount;
        <b>cout << m_nCount << endl;</b>
}


CImage::~CImage()
{
}



<b> cimage.h</b>
#ifndef CIMAGE_H
using namespace std;
#define CIMAGE_H



class CImage{
public:
    CImage(int nCount);

    ~CImage();
        static const int m_nCount=0;

};


The problem is that it says that the cout and endl in that bold line are not in std
even if I do instead std::cout and std::endl
Thanks for your help!

Dark_Helmet 06-26-2007 02:27 PM

Because you still need to
Code:

#include <iostream>
in any source files that use cout, cerr, endl, etc.

itz2000 06-28-2007 02:07 PM

Quote:

Originally Posted by Dark_Helmet
Because you still need to
Code:

#include <iostream>
in any source files that use cout, cerr, endl, etc.

Is there more error?
it says now that there are multiple definitions for the constructor...

weird//

Quote:

cd '/home/zuki/Scripts/stigno2/debug' && WANT_AUTOCONF_2_5="1" WANT_AUTOMAKE_1_6="1" gmake -k
gmake all-recursive
Making all in src
/bin/sh ../libtool --tag=CXX --mode=link g++ -O0 -g3 -o stigno2 stigno2.o cimage.o
g++ -O0 -g3 -o stigno2 stigno2.o cimage.o
cimage.o(.text+0x104): In function `CImage::CImage(int)':
/home/zuki/Scripts/stigno2/src/cimage.cpp:26: multiple definition of `CImage::CImage(int)'
stigno2.o(.text+0x104):/home/zuki/Scripts/stigno2/src/cimage.cpp:26: first defined here
cimage.o(.text+0x112): In function `CImage::CImage(int)':
/home/zuki/Scripts/stigno2/src/cimage.cpp:26: multiple definition of `CImage::CImage(int)'
stigno2.o(.text+0x112):/home/zuki/Scripts/stigno2/src/cimage.cpp:26: first defined here
cimage.o(.text+0x120): In function `CImage::~CImage()':
/home/zuki/Scripts/stigno2/src/cimage.cpp:33: multiple definition of `CImage::~CImage()'
stigno2.o(.text+0x120):/home/zuki/Scripts/stigno2/src/cimage.cpp:33: first defined here
cimage.o(.text+0x126): In function `CImage::~CImage()':
/home/zuki/Scripts/stigno2/src/cimage.cpp:33: multiple definition of `CImage::~CImage()'
stigno2.o(.text+0x126):/home/zuki/Scripts/stigno2/src/cimage.cpp:33: first defined here
collect2: ld returned 1 exit status
gmake[2]: *** [stigno2] Error 1
gmake[2]: Target `all' not remade because of errors.
gmake[2]: Nothing to be done for `all-am'.
gmake[1]: *** [all-recursive] Error 1
gmake: *** [all] Error 2
*** Exited with status: 2 ***


graemef 06-28-2007 08:18 PM

You need to #endif at the end of cimage.h
Do you by any chance #include cimage.cpp in any other files?, the #include should be cimage.h, the header file not the source code.


All times are GMT -5. The time now is 07:05 AM.