Hello, I am working on a small library of *useful* (kinda) functions that add to c++, This is mainly for me, as i'm too lazy to write long functions to do a simple task like printing a new line.

I have these three files :

Header :

Code:
///////////////////////////////////////
// Name     : C-Flat header
// Author   : izder456
// License  : Simplified 2-Clause BSD
// Version  : a0.1
// Lauguage : C++ header
///////////////////////////////////////

namespace N
{
   class c-flat
   {
   public:
      //newline function
      void coutln();
      //length function of string
      int lens(char* s);
   };
};


implementation :

Code:
///////////////////////////////////////
// Name     : C-Flat library
// Author   : izder456
// License  : Simplified 2-Clause BSD
// Version  : a0.1
// Lauguage : C++
///////////////////////////////////////

#include <math.h>
#include <stdio.h>
#include <iostream>
#include <cstddef>
#include <type_traits>
#include "cf.h" // header in local directory
#include <iostream> // header in standard library
using namespace std;
using namespace N;

//newline function
void c-flat::coutln() {
   cout << endl;
}

//length function of string
int c-flat::lens(char * s) {
   char * t;
   int size = 0;
    for (t = s; *t != '\0'; t++) {
        size++;
    };
   return size;
}


& demo program :

Code:
///////////////////////////////////////
// Name     : C-Flat example program
// Author   : izder456
// License  : Simplified 2-Clause BSD
// Version  : a0.1
// Lauguage : C++ header
///////////////////////////////////////

#include <math.h>
#include <stdio.h>
#include <iostream>
#include <cstddef>
#include <type_traits>
#include "cf.h"
#include <iostream>
using namespace N;

int main() {
   c-flat cf;
   printf("line 1");
   cf.coutln();
   printf("line 3");
}


when I compile with clang++ main.cpp -std=c++19 -o main.exe

i get these errors :

Code:
In file included from main.cpp:14:
./cf.h:11:9: error: expected unqualified-id
        class c-flat
               ^
main.cpp:19:3: error: expected unqualified-id
        c-flat cf;
         ^
main.cpp:21:2: error: use of undeclared identifier 'cf'
        cf.coutln();
        ^
3 errors generated.


what am I doing wrong?
Class names cannot contain hyphens.
Now watch as Apple steals your code and makes money off it.
Nomkid wrote:
Now watch as Apple steals your code and makes money off it.

honestly i wouldn't care less

mateo wrote:
Class names cannot contain hyphens.

thanks! that fixed it!

One more question,
how do i set up this project for cmake, to make linking far easier...
https://github.com/Izder456/c-flat

never mind, i figured it out
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement