I have a hpp file with a list of inline finctions like this:
Code:
inline int check() {
return 1;
}
inline int check_1() {
return 1;
}
... What I would like to do is to include them into several unrelated classes. How can I do this. Can I just add the hpp inline functions in headers of my class containing files or not. I mean if they are not defined as class functions how can they be called. I don't understan the logic.
I have defined to classes : Parent and Child. I have some global variables in a header file named as "var.h". These variables are used in both Parent and child Classes. The source code of these classes are written below:
Parent.h ============================================== #ifndef PARENT_H #define PARENT_H #pragma once #include <stdio.h> class Parent {
[Code] ....
After compiling, the compiler returns a fatal error as follows:
1>Parent.obj : error LNK2005: "int counter" (?counter@@3HA) already defined in Child.obj 1>C:Documents and SettingspishiDesktop estDebug est.exe : fatal error LNK1169: one or more multiply defined symbols found
It says the "counter" is defined multiple times....
I have a main.h file where I include all the needed things to make my program compile properly, string, vector etc.
And I also have another header file which comntains a class that is used later in the code (globally), I decided to keep it in another file to make it more clear and easier.
I need to include that file in main.h, but I also include main.h from that class header file because it contains some other includes that are required to compile.
Is this a good thing? Or should I keep main.h out of that class header file and include just things required for the class?
I may have complicated it too much, so I'll show an example, what I do now:
// ---- main.h ---- #include <string> #include <vector> #include <ctime> // other includes, these are just examples #include "MyClass.h" // the separated class header file
[Code] ......
So, from what you can see MyClass.h requires just including the vector, but to avoid repeating myself I include main.h which does that already, but also includes MyClass.h
So, I have two questions: 1. Is it ok to include in that way (including a file that includes the including file) 2. Is it good to include a main header file with all the includes even if I just need one of them, or should I skip including main.h and include just the things my class requires (vector is just an example)
I recall when I first started playing with C++ I was told that you should never use virtual functions unless you absolutely cannot think of a better way to do whatever you are attempting. This is something I have tried to stick to over the years - and indeed is probably why I have never used inheritance or polymorphism much in my own programmes.
However, I notice through a great deal of the code examples offered to questions here and even over on StackOverflow that commentators show no hesitation to recommend code that involves virtual functions. More so, I have even seen several instances here where - what I was taught as, but they may well have a different official name - 'pure virtual functions' (those with definitions inside a class of something like virtual int function_name(void)=0) are demonstrated and I was very clearly taught to avoid those like the plague.
I was wondering therefore has the official thinking changed since the middle nineties on when - and even whether - to use virtual functions in your programmes?
when I should use pure virtual functions.On the one hand, "TOY" for example should be an abstract class since theres no such thing as "TOY" , there are "toy cars", "toy fighters" etc , but on the other hand I need to force it somehow to be abstract since theres no really a function that any toy should have and implement on his own way (except PRINT maybe).
when I should REALLY use pure virtual functions? And if I want to avoid people from creating TOY objects (for example), the only way is PURE virtual functions. right?
So I have 2 seperate base classes, (note that I removed the variables and functions that do not relate to the topic) Object.h
class Object{ public: Object(); ~Object();
[Code].....
The error I get is saying I am calling a function declared with one calling convention with a function pointer declared with a different calling convention and this makes perfect sense because for some reason, the function pointer is pointed at the virtual function Object::update but I can't figure out why and how to make it point at the virtual function Drawable::getImage.
Also, the virtual update function is called in a different place just before this and works correctly.
class Character; class Village; class Character { public: //Functions void charGen(); //Character creation
[Code] .....
According to the Friendship and Inheritance tutorial [URL] ...., that code should work, but it doesn't. I am given an error: undefined reference to questsCompleted
I need to access the functions of the derived classes from a vector of objects of base classes (can't believe I wrote it). Here a Diagram for you to understand:
So as you see, I need the function Use() from the Usable class, to be able to be called from the vector like:
I'm developing a stack using a linked list. I have to develop two friend functions to do something with the list. But I've tried to understand the friendship, without any consistent result.
Extract of code:
Code: class Element { public: int Data; Element *nextElement; Element(int Element) {Data = Element; nextElement = NULL;} ~Element() { }
[Code] ....
I have no errors, but I cannot access the private properties of the class.
The thing I would like to do is: sum the elements of the stack with a friend function.
I'm trying to print a single linked list backward with functions/classes. I have created the main file and 3 header files. But I'm getting an error on one of the header files, linkedListIterator after adding #include "linkedListType.h". It says that "linkedLlistType.h" is calling itself. And when I try to run it, I get an error of "too many header files." I have tried changing the headers many times, but nothing seems to work.
.cpp file:
/*(Printing a single linked list backward) Include the functions reversePrint and recursiveReversePrint, as discussed in this chapter, in the class linkedListType. Also, write a program function to print a (single) linked list backward. (Use either the class unorderedLinkedList or the class orderedLinkedList to test your function.)*/
When I attempt to compile the above code, I get several thousand errors, mostly "stray ‘@’ in program", coming from the cocoa framework. It compiles and runs correctly if I omit the cocoa include or if I name the file main.mm instead of main.cpp.
I'm pretty sure it's failing because cocoa is written in objective c and I'm reading it as c++ code..how to include an objective c file in a c++ program?
I am trying to include all repetitions for just one turn but I keep getting
00.0 but I want (the one in red) 170.3 0 0.3 180.0 17 0.0 190.3 18 0.0 200.3 19 0.3 210.0 20 0.3 220.0 21 0.0 22 0.0
so basically I call a function that represents just one turn of getting a random number, and then when the player decides he wants to get a random number that is at least 17 and wants to repeat this 3x I have to print out this chart that shows the chances of the player rolling the numbers between 17-22 [how many times does he get 0,17,18,19,20,21,22] this is what I have
cout << "your score: " << (' ') << "chances for that score:" << endl; /* score is the player's total score for the one turn */ int score = 0; int score0 = 0; // 0
I have the header (and accompanying lib file) in my project folder, I have it in my solution explorer. And I've tried to add it via C++ Directories.. but that doesn't seem to exist anymore, instead it points to a user property sheet, but where to find or access it ...
I have an array of (Student)classes created in Manager.h, which contains a new instance of class Name (name),(in Student.h)How would I go about accessing the SetFirstName method in Name.cpp if I was in a class Manager.cpp? I have tried using Students[i].name.SetFirstName("name");
// In Manager.h #include"Student.h" class Manager {
I've worked a lot in Java and Perl and now I'm learning C++ and working on a simple e-reader (let's not get into why I'm not just using Kindle or other existing ones). This is for me and a number of friends.
At first my project will be on OS X, then Windows and Linux, and I hope to eventually use it on Android and iOS. I know that the last two will require separate GUIs, but I'm hoping the rest of the code will port easily.
Here's the problem:
I'm using Poppler to read and display PDF files. I started installing it on my iMac and it needs FontConfig, which is turning out to be a difficult install. I would not want to walk others through this or make them have to install Poppler and FontConfig (and any other libraries I find both need).
I thought I could just compile my final binaries using "-static" but I've been reading about how some libraries can't be statically linked or compiled.
Also, since I want to eventually port this to 4 other OSes (and apparently Poppler can work on those target OSes), I don't want to do something now or depend on something that will make it hard or impossible to port to other OSes later.
With that in mind, here are my questions:
1) Why is it some libraries cannot be compiled statically? How do I know if I'm dealing with one of those libraries?
2) Am I right that I could compile this program statically, and the resulting binary would include code from Poppler and FontConfig and other libraries would be included in the resulting executable binary?
3) What do I need to watch for so I can tell if using a particular library will be a problem when I need to port my program to a new OS? (Assuming, of course, that searching shows that library will compile or has been ported to that OS.)
I have four source files. The main source file includes two other source files. The two other source files both include the fourth source file. In the fourth source file I have an include guard. Will the code from the fourth source file exist in two locations in the compiled code? Is this something that is compiler dependent? An example of this is shown in the code below.
I have two report.h files located in two different directories. However the contents of them are different. How can I include the report.h file located in guarddog into the report.h file located in sky?
I am displaying data from an Excel Spreadsheet through an ASP.net web form using C#. I would like to run an SQL query on the data, but am having trouble figuring out how to use a string in my query.
Here is the code I am running in my .aspx.cs file. I am also using a .aspx to display the data in a GridView.
Ideally, I would like to add a WHERE clause to my string (string sSQL = "SELECT * FROM [Sheet1$A1:D14]"/> in order to query the current month and display the row of said month from the Excel Spreadsheet.
I have attempted to use a DataAdapter to insert the string into the query, but could not figure out how to conform my code to work with it.
I am currently developing a small quick'n dirty SIP (Session Initiation Protocol) parser. Its task is to read a file (or command-line argument) with a SIP requst and parse it using the sofia-sip library. It should exit either with "1" on parsing failure or "0" on parsing success.
I have taken the code snipplet from here: [URL] .... resulting in this source code:
I'm a little confused by my programming assignment this week. I've been working at it Wednesday and I've made progress but I'm still confused as to how I'm supposed to do this. The class I made is called Stack, and it's derived from a template class called StackADT. We also utilize a class called unorderedLinkedList, which is derived from a class called linkedList.
We're supposed to implement all of the virtual functions from stackADT in the Stack class. The Stack data is stored in a an unorderedLinkedList, so what I'm confused by is how to implement a few of the Stack functions because there are no functions in unorderedLinkedList which we could call to manipulate the data.
As you can see from my attached code, I'm really confused by how I'm supposed to implement the pop() and top() functions, and I also think my initializeList() function is wrong. We don't have any similar functions in unorderedLinkedList to call, so I'm at a loss of how i'd access my unorderedLinkedList. My initial thought was to call the similar functions in the class that unorderedLinkedList was derived from, linkedList, but I'm unsure of this is what we're supposed to do, or if theres actually a way to access my unorderedLinkedList without having to use the functions from the base class.
NOTE: We're not allowed to modify stackADT, unorderedLinkedList, and linkedList.
Stack.h
#include "stackADT.h" #include "unorderedLinkedList.h" template<class Type> class Stack: public stackADT<Type>{ template <class T> struct nodeType { T info; nodeType<T> *link;
But now I'm trying to use this to point to a function inside a class so instead of do11, i want to be able to point to Basic.Do11. Somehow this doesnt work and I keep on getting this message:
error: argument of type 'void (Basic::)()' does not match 'void (*)()'
I want to use FREAK(an opencv key-point descriptor library), a source file which exist in opencv or vc++, on the other hand i need to include the same header file to use the other functions, and when i use that source file i get "ambiguity error" how can i select to use that function from my current directory instead of interior function?