IDE seems to be confused about classes

L

Leszek L.

Hello, I am new to this group; if my question is OT then please
excuse me and tell me where to go.

I am using MS Visual C++ with some of its graphics libraries.

Now the compiler tells me that one of the member functions
that I am trying to use is not a member of that class.

The sad irony is that when I type the name of an object
of that class, followed by a dot, the IDE helpfully displays
a pop-up list of members - and guess what, the function
is right there!

So apparently, the IDE (the source editor, in fact) and the compiler
can't agree on the class structure.

In another class (also part of a library that came with the IDE),
one of the member functions has a different set of parameters
than the pop-up help would have me believe. I managed to guess
the right set of parameters and this part compiles OK.

Is there a typical mistake made by a programmer (i.e. yours truly)
that makes Visual behave in such incoherent ways?

Thanks in advance for any enlightment,
Leszek L.
 
T

Tom Smith

Leszek said:
Hello, I am new to this group; if my question is OT then please
excuse me and tell me where to go.

I am using MS Visual C++ with some of its graphics libraries.

Now the compiler tells me that one of the member functions
that I am trying to use is not a member of that class.

The sad irony is that when I type the name of an object
of that class, followed by a dot, the IDE helpfully displays
a pop-up list of members - and guess what, the function
is right there!

This doesn't mean that the function "exists" - just that your IDE thinks it does.
So apparently, the IDE (the source editor, in fact) and the compiler
can't agree on the class structure.

Here's an absolute rule: your compiler is right. Always.
In another class (also part of a library that came with the IDE),
one of the member functions has a different set of parameters
than the pop-up help would have me believe. I managed to guess
the right set of parameters and this part compiles OK.

Is there a typical mistake made by a programmer (i.e. yours truly)
that makes Visual behave in such incoherent ways?

The mistake you've made is relying on your IDE. As for what's going on with your
particular error, you haven't really given us enough (any) information: can you
post a relevant piece of code and the actual error message? (See
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8 for details). If
it turns out to be an error in the library (which I doubt), you'll want to find
a more appropriate group; you might also want to try a Windows-specific or
VC-specific group, for instance comp.os.ms-windows.programmer.misc.
Thanks in advance for any enlightment,
Leszek L.

Tom
 
T

tugboat90

On a note about your error, it seems like the IDE is being confused
over function names. Are you using (fairly) original function names?

If you are not including the correct #include directories and you are
using fairly common function names then there is a chance that the IDE
is picking out the functions from the wrong file.

....although I can't be sure without seeing some code or error messsages
;)

Hope that's a place to start looking anyways...
 
L

Leszek L.

Thank you for your quick reply.

U¿ytkownik "Tom Smith" <[email protected]> napisa³ w wiadomo¶ci

Here's an absolute rule: your compiler is right. Always.

I am ready to recognize its authority as only second to divine.
The problem is it only tells me that I am wrong, not what I can do
to be right.

As for what's going on with your particular error, you haven't really
given us enough (any) information: can you post a relevant piece of code
and the actual error message? (See

Here is the source file and the header. Complying with the FAQ, I'm not
cutting
out any part of the code, so it's rather lengthy, but I put a "LOOK HERE"
comment
in the offending line. My purpose in that particular fragment is simply to
read in
an image file and then run through its pixels one by one, doing different
things
depending on whether each successive pixel is white or black. And they are
all either white or black; I made the image that way - so I figured I can
just take
any of the three color components and compare it to a threshold.

The error message is:

! error C2039: 'GetRed' : is not a member of 'System::Drawing::Color'

I also tried GetR(), which the headers define as synonymous with GetRed.
The result was the same.
Thanks again - L.

< ------- lengthy source file begins, stand back! ----- >

#include "StdAfx.h"
#include ".\k3palette.h"
// #include <atlsecurity.h>
#include <atlimage.h>
// #include <gdiplusbase.h> //* not included originally!
// #include <gdiplusheaders.h>
// #include <gdipluscolor.h>
// #include <gdiplusbitmap.h>

#using <mscorlib.dll>
#using <system.dll>
#using <system.drawing.dll>
// #using <system.windows.forms.dll> //* these lines were commented

using namespace System;
using namespace System::IO;
using namespace System::Collections; //*
using namespace System::Resources; //*
using namespace System::Drawing;
// using namespace System::Windows::Forms; //*


void K3Log(char *);

K3Palette::K3Palette(long unsigned NCol, char PaletteType)
{ // NCol =Number of colours;
// PaletteType= (uppercase letters only)
// 'G'-greyscale,
// 'H'-rainbow of hues,
// 'F'-scan full colour space
long unsigned i,k,j,j8;

N=NCol;
MyInks=new int[NCol][3];

switch(PaletteType) {
case 'G':
for(i=0;i<NCol;i++) {
MyInks[0]=MyInks[1]=MyInks[2]=(int)( ((double)i)/((double)NCol)
* 255.0);
};
break;
case 'H':
{
int rg=4;
int gb=3;
int br=5;
int SumCoeff;

SumCoeff=rg+gb+br;
rg=(NCol*rg)/SumCoeff;
gb=(NCol*gb)/SumCoeff;
br=NCol-rg-gb;

for(i=0;i<NCol;i++) {
// K3Log("Playing colors");
if(i<=rg) {
MyInks[0]=255*(rg-i)/rg;
MyInks[1]=255*i/rg;
MyInks[2]=0;
}
else if(i<=rg+gb) {
MyInks[0]=0;
MyInks[1]=255*(rg+gb-i)/gb;
MyInks[2]=255*(i-rg)/gb;
if(i==rg+gb) {
MyInks[0]=MyInks[1]=128;
};
}
else {
MyInks[0]=255*(i-rg-gb)/br;
MyInks[1]=0;
MyInks[2]=255*(rg+gb+br-i)/br;
};
};
};
break;
// case 'F': included in default!
// break; All other values of PaletteType treated as 'F'.
default:
for(i=0;i<NCol;i++) {
k=(long unsigned)( ((double)i) / ((double)NCol) * 16777216.0 );

// avoid zeros, scatter values.

MyInks[0]=MyInks[1]=MyInks[2]=0;
for(j=0;j<8;j++) { // now reshuffle the bits so that neighbouring..
for(j8=0;j8<3;j8++) { //.. numbers have different colours.
MyInks[j8]*=2;
MyInks[j8]+=(k&1);
k=k/2;
};
};
};

};
}

void K3Palette::GetInk(unsigned long i, unsigned long *deliver) {

// *deliver=(i&1) ? 200 : 0;
// *(deliver+1)=(i&2) ? 200 : 0;
// *(deliver+2)=(i&4) ? 200 : 0;

i=i%N;
if(i<0) {
K3Log("Negative ink number!");
i=0;
}
else
if (i>(N-1)) {
K3Log("ESceSSive ink number!");
i=N-1;
};
*deliver=MyInks[0];
*(deliver+1)=MyInks[1];
*(deliver+2)=MyInks[2];
};

long unsigned K3Palette::GetN() {
return(N);
};

void K3Palette::DumpLegend(char *filnam) {
// create bitmap file with given name,
// featuring 10 rows per color.
Bitmap *MujBitmap;
long i,j,k;
Color K3Ink,K3Ink2,Paper;
COLORREF PaperCOLORREF;
K3Log("Legending!");
K3Log(filnam);

MujBitmap=new Bitmap(300,10*N);
MujBitmap->SetResolution(300.0,300.0);
MujBitmap->FromFile("C:\\K3RF\\TextLegend.jpg");

for(k=0;k<N;k++) {
K3Log("another legend color");
K3Ink=Color::FromArgb(MyInks[k][0],MyInks[k][1],MyInks[k][2]);
if(MyInks[k][0]/3+MyInks[k][1]/3+MyInks[k][2]/3<127) {
K3Ink2=Color::FromArgb(255,255,255);
} else {
K3Ink2=Color::FromArgb(0,0,0);
};
for(i=0;i<300;i++) {
for(j=10*k;j<10*k+10;j++) {
Paper=MujBitmap->GetPixel(i,j);
// PaperCOLORREF=Paper.ToCOLORREF();
if(((int)(Paper.GetRed()))>210) { // LOOK HERE

MujBitmap->SetPixel(i,j,K3Ink);
}
else {
MujBitmap->SetPixel(i,j,K3Ink2);
};
};
};
};

K3Log("Saving legend");
K3Log(filnam);
MujBitmap->Save(filnam);
K3Log("Legend saved");

};





K3Palette::~K3Palette(void)
{
}


< --- and here is my header file ".\k3palette.h" --->
#pragma once

class K3Palette
{
public:
K3Palette(long unsigned, char);
~K3Palette(void);
void GetInk(long unsigned, long unsigned*);
long unsigned GetN(void);
void DumpLegend(char *filnam);
private:
int (*MyInks)[3];
long unsigned N;
};
 
L

Leszek L.

U¿ytkownik "tugboat90 said:
On a note about your error, it seems like the IDE is being confused
over function names. Are you using (fairly) original function names?

You mean - for my own functions? Yes, I usually try to be original,
prefixing names with K3 (my personal code name from long ago)
or Muj (which is misspelled Polish for "My"), or twisting the words
in other ways. But the error concerns a library function, which I neither
beget nor baptized.
If you are not including the correct #include directories and you are

This might be the case; I have the disastrous tendency to take
the existence of library functions for granted and forget where each
of them came from, or even which libraries I am using.
using fairly common function names then there is a chance that the IDE
is picking out the functions from the wrong file.

This seems to be the case - but assuming that I am including the wrong
headers and leaving the right ones out, why does the IDE not interpret
my [erroneous] #include directives in the same way the compiler does?
They are both looking at the same source file, aren't they, no matter
how many mistakes I may (must) have made in it.

Thanks for your input.
L.
 
S

Salt_Peter

Leszek said:
Thank you for your quick reply.

U¿ytkownik "Tom Smith" <[email protected]> napisa³ w wiadomo¶ci



I am ready to recognize its authority as only second to divine.
The problem is it only tells me that I am wrong, not what I can do
to be right.



Here is the source file and the header. Complying with the FAQ, I'm not
cutting
out any part of the code, so it's rather lengthy, but I put a "LOOK HERE"
comment
in the offending line. My purpose in that particular fragment is simply to
read in
an image file and then run through its pixels one by one, doing different
things
depending on whether each successive pixel is white or black. And they are
all either white or black; I made the image that way - so I figured I can
just take
any of the three color components and compare it to a threshold.

The error message is:

! error C2039: 'GetRed' : is not a member of 'System::Drawing::Color'

I also tried GetR(), which the headers define as synonymous with GetRed.
The result was the same.
Thanks again - L.

< ------- lengthy source file begins, stand back! ----- >

#include "StdAfx.h"
#include ".\k3palette.h"
// #include <atlsecurity.h>
#include <atlimage.h>
// #include <gdiplusbase.h> //* not included originally!
// #include <gdiplusheaders.h>
// #include <gdipluscolor.h>
// #include <gdiplusbitmap.h>

#using <mscorlib.dll>
#using <system.dll>
#using <system.drawing.dll>
// #using <system.windows.forms.dll> //* these lines were commented

using namespace System;
using namespace System::IO;
using namespace System::Collections; //*
using namespace System::Resources; //*
using namespace System::Drawing;
// using namespace System::Windows::Forms; //*

<snipped>

the following declaration declares Paper as type Color.
Color K3Ink,K3Ink2,Paper;

and i don't see
#using namespace System::Drawing::Color;
anywhere

ignoring the if and old_time cast to integer, is GetRed() a member
function of the Color class?
if(((int)(Paper.GetRed()))>210) { // LOOK HERE

You should learn a little standard C++, you'ld find it much, much
easier to write a program like this one.
 
L

Leszek L.

Leszek L. wrote:


the following declaration declares Paper as type Color.


and i don't see
#using namespace System::Drawing::Color;
anywhere

OK, I'll try adding that; but I thought if the class is declared
then it comes with all its member functions? And if the class
were undeclared, why would the compiler accept the
declaration of Paper and only protest when I'm calling
a function?

[OO]PS: Just tried adding the declaration you suggest. Got this
error message:

! error C2867: 'System::Drawing::Color' : is not a namespace

and then the usual:

! error C2039: 'GetRed' : is not a member of 'System::Drawing::Color'

ignoring the if and old_time cast to integer, is GetRed() a member
function of the Color class?

Yes it is, at least according both to the IDE _and_ to the headers.
You should learn a little standard C++, you'ld find it much, much
easier to write a program like this one.

Thanks; I'm trying to learn on the go. I had a difficult childhood
with plain C and Matlab.

Cheers,
Leszek.
 
L

Leszek L.

A friend took a good look at this mess and found that the IDE
and the help system were referring to the class System::Drawing::Color,
while the actual thing used by the compiler was "struct Color" from
a different library.

Thanks to all who responded,
Leszek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,137
Messages
2,570,799
Members
47,347
Latest member
edward_eden

Latest Threads

Top