Function not being added to header file.

Posted on 2004-08-09
Last Modified: 2010-04-01
Im reading a book in visual c++, Im trying to use the Add Member Function wizard, but it wont add the function definition to the header, but it does add to the cpp file. It seems it WILL add to the header if both the type and param are the class name. Anyone know how i can fix this, or at least why its not adding?
Question by:Monstrosity_
  • 4
  • 2
  • 2
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11757287
> Im trying to use the Add Member Function wizard, but it wont add the function definition to the header.
Are you really sure? That's not normal. Maybe you are not noticing that some added function declarations are "grayed", but there exist.
Try to compile, if succeed, then function declaration is there.

Author Comment

ID: 11757376
hmm... i could try... but even in the book it shows what the final code SHOULD look like and only one of the three that it says to add accually gets added to the header. It doesnt even show up in the class view list. From what ive learnt it will compile either way, just a matter of wiether or not you want inline or not wouldnt it?

CBox operator+(const CBox& aBox) const   gets added but..
CBox operator*(int n) const  does not, but the cpp file shows it as,
CBox CBox::operator*(...) const ... so there should be a definition in the header right? otherwise whats the point of CBox:: ? Now im really confused ;)

Author Comment

ID: 11759623
I just tried to add the member funtcions and compile like you said and heres the debug info...

--------------------Configuration: classes - Win32 Debug--------------------
C:\WINDOWS\Desktop\C\VC6\classes\Box.cpp(27) : error C2039: '*' : is not a member of 'CBox'
        c:\windows\desktop\c\vc6\classes\box.h(13) : see declaration of 'CBox'
C:\WINDOWS\Desktop\C\VC6\classes\Box.cpp(28) : error C2270: '*' : modifiers not allowed on nonmember functions
Error executing cl.exe.

classes.exe - 2 error(s), 0 warning(s)

The line of code it refers to is the function added to the .cpp but not .h file..

CBox CBox::operator *(int n) const {}

LVL 39

Expert Comment

ID: 11761370
In your class header there should be lines like that:



Class Wizard adds new prototypes between these two comments. If these are missing or changed, it will fail.

Regards, Alex

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

LVL 39

Expert Comment

ID: 11761389
Also these two comments are needed for handler functions (non-virtual)



Regards, Alex


Author Comment

ID: 11767757
I added both those lines and still does same thing...
wtf.. maybe something got messed and needs reinstall
LVL 55

Accepted Solution

Jaime Olivares earned 125 total points
ID: 11767840
There are many situations in where Visual Studio IDE don't work as expected, some bug has been corrected in differents Software Packs (up to SP6 I guess) but some others no.
So, if after reinstalling still works the same, don't worry and do it manually.

Author Comment

ID: 11769511
reinstalled and same f-ing thing... this really p's me off. But i guess ill have to live with doing it manually... i'd send in a bug report or something, but i doubt it would even get looked at lol.

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now