473,566 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

illegal call of non-static member compile error question

Ook
What am I doing wrong? This code gives a compile error:
'SortedList<T>: :insert' : illegal call of non-static member function. I've
tried several variations of this, but keep getting the same error.
template <typename T>
class SortedList
{
public:
void insert( T item); // Write this
};
//-------------------------------------------------
template <typename T>
void SortedList<T>:: insert( T item)
{
}
int main()
{
int i = 123;
SortedList<int> ::insert(i);
return 0;
}
Oct 19 '05 #1
7 32085
Ook wrote:
What am I doing wrong? This code gives a compile error:
'SortedList<T>: :insert' : illegal call of non-static member function. I've
tried several variations of this, but keep getting the same error.
template <typename T>
class SortedList
{
public:
void insert( T item); // Write this
};
//-------------------------------------------------
template <typename T>
void SortedList<T>:: insert( T item)
{
}
int main()
{
int i = 123;
SortedList<int> ::insert(i);
return 0;
}


It looks like you are trying to call a member function from a class,
which cannot be done.

Try this insted:

int main() {
int i = 123;
SortedList<int> slist;
slist.insert(i) ;
}

--John Ratliff
Oct 20 '05 #2
Ook

"John Ratliff" <us**@example.n et> wrote in message
news:4pB5f.2580 71$084.103411@a ttbi_s22...
Ook wrote:
What am I doing wrong? This code gives a compile error:
'SortedList<T>: :insert' : illegal call of non-static member function.
I've tried several variations of this, but keep getting the same error.
template <typename T>
class SortedList
{
public:
void insert( T item); // Write this
};
//-------------------------------------------------
template <typename T>
void SortedList<T>:: insert( T item)
{
}
int main()
{
int i = 123;
SortedList<int> ::insert(i);
return 0;
}


It looks like you are trying to call a member function from a class, which
cannot be done.

Try this insted:

int main() {
int i = 123;
SortedList<int> slist;
slist.insert(i) ;
}

--John Ratliff


I don't get it - where am I trying to call it from the class?
Oct 20 '05 #3
Ook wrote:
"John Ratliff" <us**@example.n et> wrote in message
news:4pB5f.2580 71$084.103411@a ttbi_s22...
Ook wrote:
What am I doing wrong? This code gives a compile error:
'SortedList<T>: :insert' : illegal call of non-static member function.
I've tried several variations of this, but keep getting the same error.
template <typename T>
class SortedList
{
public:
void insert( T item); // Write this
};
//-------------------------------------------------
template <typename T>
void SortedList<T>:: insert( T item)
{
}
int main()
{
int i = 123;
SortedList<int> ::insert(i);
return 0;
}


It looks like you are trying to call a member function from a class, which
cannot be done.

Try this insted:

int main() {
int i = 123;
SortedList<int> slist;
slist.insert(i) ;
}

--John Ratliff


I don't get it - where am I trying to call it from the class?


The second line of main tries to call a class method, insert(), without
a class instance.

Greg

Oct 20 '05 #4
"Ook" <Ook Don't send me any freakin' spam at zootal dot com delete the
Don't send me any freakin' spam> wrote in message
news:As******** ************@gi ganews.com...

"John Ratliff" <us**@example.n et> wrote in message
news:4pB5f.2580 71$084.103411@a ttbi_s22...
Ook wrote:
What am I doing wrong? This code gives a compile error:
'SortedList<T>: :insert' : illegal call of non-static member function.
I've tried several variations of this, but keep getting the same error.
template <typename T>
class SortedList
{
public:
void insert( T item); // Write this
};
//-------------------------------------------------
template <typename T>
void SortedList<T>:: insert( T item)
{
}
int main()
{
int i = 123;
SortedList<int> ::insert(i);
On the above line, you are calling a member function of SortedList<int> .
Since there is no object involved on that line, you can use that syntax only
with static member functions.

Since it is natural to 'insert' into a SortedList object, I don't think you
want that function to be static.
return 0;
}


It looks like you are trying to call a member function from a class,
which cannot be done.

Try this insted:

int main() {
int i = 123;
SortedList<int> slist;
slist.insert(i) ;
On the line above, John Ratliff is showing you how to call a non-static
member function with an object. There, slist is an jobject of type
SortedList<int> , and the member function thas is being called is 'insert'.
}

--John Ratliff


I don't get it - where am I trying to call it from the class?


Where you use the Class::function syntax...

Ali

Oct 20 '05 #5
Ook

"Greg" <gr****@pacbell .net> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Ook wrote:
"John Ratliff" <us**@example.n et> wrote in message
news:4pB5f.2580 71$084.103411@a ttbi_s22...
> Ook wrote:
>> What am I doing wrong? This code gives a compile error:
>> 'SortedList<T>: :insert' : illegal call of non-static member function.
>> I've tried several variations of this, but keep getting the same
>> error.
>>
>>
>> template <typename T>
>> class SortedList
>> {
>> public:
>> void insert( T item); // Write this
>> };
>> //-------------------------------------------------
>> template <typename T>
>> void SortedList<T>:: insert( T item)
>> {
>> }
>> int main()
>> {
>> int i = 123;
>> SortedList<int> ::insert(i);
>> return 0;
>> }
>
> It looks like you are trying to call a member function from a class,
> which
> cannot be done.
>
> Try this insted:
>
> int main() {
> int i = 123;
> SortedList<int> slist;
> slist.insert(i) ;
> }
>
> --John Ratliff


I don't get it - where am I trying to call it from the class?


The second line of main tries to call a class method, insert(), without
a class instance.

Greg


Dooooohhhh!!!! I forgot to instantiate SortedList! Ack, I can't believe I
didn't see that - and John even showed how to do it.... :-P

/hangs head in extreme embarrassment
Oct 20 '05 #6
Ook

"Ali Çehreli" <ac******@yahoo .com> wrote in message
news:dj******** **@domitilla.ai oe.org...
<snip>
On the line above, John Ratliff is showing you how to call a non-static
member function with an object. There, slist is an jobject of type
SortedList<int> , and the member function thas is being called is 'insert'.


Yes, I stupidly missed that, even though it was quite obvious. My apologies
for being so dense lol, and thanks as usual to all of the quick help I get
here. Next time I'll read the FAQ and try to come up with a tougher question
:-)
Oct 20 '05 #7
Ook wrote:
Next time I'll read the FAQ and try to come up
with a tougher question :-)


If you do that you will simply be referred to the FAQ. :-)

DW
Oct 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
8143
by: Ney André de Mello Zunion | last post by:
Hello. Binding a temporary to a non-const reference is illegal. Everybody should be tired of hearing that. So should I. But then I found myself wondering about a small piece of code I was writing: void cipher(unsigned long& xa, unsigned long& xb) { // ... xa = // ...
10
1529
by: JKop | last post by:
Firstly, we all know that temporaries are non-const, which I shall demonstrate with the following code: struct Blah { int monkey; void SetMonkey(int const supplied) { monkey = supplied;
1
1564
by: Gernot Frisch | last post by:
GFXMLTree* Seek4Node(LPCTSTR name); const GFXMLTree* Seek4Node(LPCTSTR name) const { return Seek4Node(name); // Force to call the first version } -- -Gernot int main(int argc, char** argv) {printf
28
2910
by: dingbat | last post by:
I'm writing a "tabbed folder" nav bar. Site standards are graphical prettiness, CSS throughout, valid code, but accesibility is ignored where it conflicts with prettiness. The particular issue here is that the graphic designer wants a pretty (non-webbable) font on the shaded nav tabs, so I'm reduced to using bitmaps. To make the 4-way...
2
1563
by: Colin Walters | last post by:
Hi, I have a program which had a little function that always returned TRUE, it looked like this: int always_true_function (void *dummy, ...) { return 1; }
4
2794
by: Logu | last post by:
I have an interesting issue. rather I should call this as confusing issue. :-) I have a small proto in my project, which should act as a server, which essentially requests info and passes the info to another hardware interface. Since this is a non-critical piece, I simply had UNC Path to transfer the info as XML. But even at my initial...
12
2360
by: [Yosi] | last post by:
What I should do to return back the permissin I had in VS2003 , that allowd me to access public methode of one Class from other Thread. I have Class A(FORM) which create new thread (new class B), the new class thread get as parameter reference to his father( CLASS who mad it (classA)), The new thread need to call methodes from his father...
12
7178
by: Wilfried Mestdagh | last post by:
Hi, Using P/Invoke I use PostMessage to send a message from one thread to another. I'm pretty sure this has already worked in dotnet. but I've upgraded version 2 few day ago. Now I have an illegal cross thread operation if posting a message. Is this a bug introduced in latest version of dotnet ? It is very legal to use postmessage ...
4
2900
by: Pĺhl Melin | last post by:
I have some problems using conversion operators in C++/CLI. In my project I have two ref class:es Signal and SignalMask and I have an conversion function in Signal to convert Signal:s to SignalMask:s. The reason is I have a free function called WaitSignal that accepts av SignalMask where Signals parameters are supposed to implicitly be...
34
2953
by: Srinu | last post by:
Hi all, Can we assign return value of a function to a global variable? As we know, main() will be the first function to be executed. but if the above is true, then we have a function call before main. Please help me calarifying this. The code may be of the form. int f(); int x = f();
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.