My problem is that the storeElems member function is causing an error saying it is undefined, however there are no errors any where else in the program being reported. I have made several programs involving classes now, all with this three file format and this is the first time that a member function in the main file is being reported as undefined, so I'm not sure what to do.
I am modifying a set of static variables inside of the class's member function. The static variables are private. An example of what I'm doing is as below,
utilities.h ----------- class utilities { private: static int num_nodes;
public: void parse_details(char* );
[Code] ....
I get a compilation error in the function void utilities::parse_details(char* filename)
which says: undefined reference to `utilities::num_nodes'
I made this code (it does nothing I am just learning about classes, I was learning about friend functions) and I don't understand what is wrong, here is the code:
#include <iostream> #include <cstdlib> #include <cstring> using namespace std; class MyClass { public: friend int add(int a, int B)/>; [Code] ....
I know i didn't need to include cstdlib and cstring for this code but as I said, it's not supposed to be something it's just for practice and I was working on char arrays. My question is about the part where i try to define the function:
int MyClass::add(int a, int B)/> {}
My compiler(Microsoft Visual C++ 2010 Express) says that class MyClass has no member "add" even though it does...
I get the following error in XCode whenever I try to access the member I created 'randomGen' in a separate class in a different header file. I have made sure to include the header file and have tried to access it through an object.
This is the code I enter when trying to access the method from randomiser.h in main.cpp. It is also an overloaded function with doubles and integers:
RandomG randomiser; randomiser.randomGen(); // 'Call to member function 'randomGen' is ambiguous'
This is the code inside randomiser.h:
#include <string> #include <iostream> using std::string; using std::cout; using std::endl; class RandomG {
[Code] ....
This is the error inside xcode: [URL] ....
I have tried seperating the code for the functions in another class (main.cpp) and then running and it seems to works, so I'm not sure why I can't put everything in the .h file and then access it?
I would like it in a seperate file so it doesn't clutter my main. I am writing a game with SDL so that might be confusing and I would like the window to have a random title and other random properties, so it would be easier to use a function.
I am work on building a simple parse tree and the layout of my code look like this:
Headers pt_node.hiterator.hparsetree.h
Source files node.cppparsetree.cppmain.cpp
I am still relatively new to C++ , and have been advised to include function definition for the member function of both pt_node class and iterator class in the node.cpp file
I particular I have declare the following iterator.h:
i want to use a class to print data stored as vector or array with different data types. i also want the print function two take more than one vector or array or combination of both so that they can be written to file as two columns. so i wrote the following class:
right now it has only one member function for printing two vectors. later i'll add additional functions as required.
note: there has to be template functions inside the class i also want the object to be global so that i need not pass it as an argument to other calling functions
then i want to call this template function in another ordinary function written in a seperate cpp file
these function declarations are put in a header file. so i need know whether i should put the declaration of the template function in the header to use the function in different functions
i want to use a class to print data stored as vector or array with different data types.
i also want the print function two take more than one vector or array or combination of both so that they can be written to file as two columns.so i wrote the following class:
right now it has only one member function for printing two vectors. later i'll add additional functions as required.
note: there has to be template functions inside the class / i also want the object to be global so that i need not pass it as an argument to other calling functions
then i want to call this template function in another ordinary function written in a seperate cpp file these function declarations are put in a header file. so i need know whether i should put the declaration of the template function in the header to use the function in different functions.
I'm making a program that's essentially a Text-Based Fire Emblem game; it runs calculations and rolls dice and has all sorts of Goodies. However, I have hit a block to the tune of
#ifndef ITEM_H #define ITEM_H class Item {
[Code]....
Up Until I called up a Sword object, it worked fine. But when I compiled it, I got an Undefined Reference to Item::Item() error in Line 8 of Weapon.cpp.
Everything seems to be in order and I know my code still has mistakes. I'm just trying to get it to compile and it won't allow it. I've narrowed it down to when I call the functions in main but beyond that I have no clue.
#include <iostream> #include <cstring> using namespace std; void getSize(int num); void getSpace(int num, int ptr); void inputData(); void printData(); void destroy(); const int BIG_NUMBER = 100;
//pa4.cpp wirtten by Syd Frederick #include<iostream> #include<string> #include<fstream>
[Code].....
When compiling I'm getting a strange error that says :
/tmp/ccdt0Bf9.o: In function `main': pa4.cpp:(.text+0x1c): undefined reference to `synopsis()' pa4.cpp:(.text+0x1e7): undefined reference to `execute(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' collect2: ld returned 1 exit status
I'm getting an undefined reference error to a function, and I can't figure out why. I have tried letting code blocks compile the files, I have tried the command line to compile it with the same results.
I looked up the error and found this from [URL]
undefined reference Example /tmp/cc2Q0kRa.o: In function `main': /tmp/cc2Q0kRa.o(.text+0x18): undefined reference to `Print(int)' collect2: ld returned 1 exit status
Meaning / Your code called the function Print, but the linker could not find the code for it in any .o file
Usual Causes
You forgot to link the .o file that contains the function
You misspelled the name of the function
You spelled the name of the function correctly, but the parameter list is different in someway
which seems to be the error I get. I have double checked all 4 and I see nothing.
The code that specifically gives me the error is:
Item *name = new Item(desc, id, weight, loc); itemMap.addItem(name);
and the class looks like this:
class Item // Standard Items { private: std::string name; std::string desc; int id; int weight; int loc;
[code].....
I think everything matches up unless I'm just missing it.
I will post the entire code at the bottom. Its running fine right now but This part in the menu function I need to make as a separate function. My problem is when I make it into a function by itself I have to declare and initialize the grades A,B,C,D,F how can I do that when I can't make them equal 0 because it has to keep track of how many of each letter grade.
Code:
//Count letter grade if(ave >= 90) ++A; else if (ave >= 80) ++B; else if (ave >= 70) ++C; else if (ave >= 60) ++D; }
How to use a function twice to calculate two different variables. How to have a function compute the city tax, then it uses the function a second time to compute the county tax.
My program compiles, and runs fine, however it only outputs the city tax calculation. It seems it never attempts to calculate the county tax.
One thing: All of the directives I used is what we are limited to, no more, no less. He requires a set format and will dock points of you use anything but those directives and void main().
How do you create a save file for a game, that is not a separate file? Specifically I am using code::blocks and sfml 2.1 to make a game and it saves to a text file at the moment. My problem is that it is very easy to modify the text file, and it is annoying to have to copy and paste several files if you want to use a copy of the game. I have a feeling that it may be to do with resource files, but I'm not exactly sure how to get these to work or whether you can modify them dynamically.
When I try to compile a single file with GCC (I'm using Code::Blocks as my IDE if that is relevant) it gives me a bunch of undefined reference errors. Well, of course they are undefined since I haven't linked anything yet, but why is GCC complaining at compiling time?
The problem is that when I try to link and compile the project in one go I don't get any errors. The references in question are from the GLEW library if that is relevant.
srccharrenderer.o:charrenderer.cpp|| undefined reference to `_imp____glewDeleteBuffers'| srccharrenderer.o:charrenderer.cpp|| undefined reference to `_imp____glewDeleteBuffers'| srccharrenderer.o:charrenderer.cpp|| undefined reference to `glEnableClientState@4'| srccharrenderer.o:charrenderer.cpp|| undefined reference to `_imp____glewBindBuffer'| srccharrenderer.o:charrenderer.cpp|| undefined reference to `glVertexPointer@16'|
Write a function that takes two input arguments and provides two separate results to the caller, one that is the result of multiplying the two arguments, the other the result of adding them.Since you can directly return only one value from a function, you'll need the second value to be returned through a pointer or reference parameter.
I could do the assignment if all i had to do was create a function within one file, call it in the main class, and that would be done with it. no, my teacher wants us to have our main program, a header and a separate class file and create functions in it in which we can then use in the main file.
This is the main file:
#include <iostream> #include "call.h" using namespace std; int main() { int length; //holds the length of the call in minutes int hour; //holds the hour od the day(0-23 military time)
#include <iostream> class Hello { public: void Test() {
[Code].....
As i know a non-constant member function cant be called inside a constant member function but how the above code has been compiled successfully and giving the expected result .
So I have to read from a file, and store the information in separate variables. My problem is that for some of the information I need multiple words, and for others I don't, so I cant simply store 1 word into a variable and store the next in another in so on. To demonstrate what I mean let me give an example.
Dog Cat Blue Bird Snake White Horse
I am able to store "Dog","Cat","Blue","Bird"...etc in variables but I don't know how to make it so I can store "Dog" in one variable, "Cat" in a second variable. and "Blue Bird" in a third variable. "Snake" would be the 4th and "White Horse" would be the fifth. How can I read a file and manipulate the pointer to grab what I need?